-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwebhook.tf
More file actions
43 lines (37 loc) · 1.29 KB
/
webhook.tf
File metadata and controls
43 lines (37 loc) · 1.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
###################
# Telegram Webhook
###################
# Automatically set webhook on apply and delete on destroy
resource "null_resource" "telegram_webhook" {
# Trigger re-run when webhook URL changes
triggers = {
webhook_url = "${aws_apigatewayv2_stage.webhook.invoke_url}webhook"
bot_token = var.telegram_bot_token
}
# Set webhook after infrastructure is created
provisioner "local-exec" {
command = <<-EOT
echo "📡 Setting Telegram webhook..."
curl -s -X POST "https://api.telegram.org/bot${var.telegram_bot_token}/setWebhook" \
-d "url=${aws_apigatewayv2_stage.webhook.invoke_url}webhook" \
-d "allowed_updates=[\"message\",\"callback_query\"]" \
-d "drop_pending_updates=false" | jq .
echo "✅ Webhook configured successfully!"
EOT
}
# Delete webhook on destroy
provisioner "local-exec" {
when = destroy
command = <<-EOT
echo "🗑️ Removing Telegram webhook..."
curl -s -X POST "https://api.telegram.org/bot${self.triggers.bot_token}/deleteWebhook" \
-d "drop_pending_updates=false" | jq .
echo "✅ Webhook removed successfully!"
EOT
}
depends_on = [
aws_apigatewayv2_stage.webhook,
aws_lambda_function.webhook,
aws_apigatewayv2_integration.webhook
]
}