This guide walks through integrating a Telegram group with the photo wall system.
- The photo wall system is deployed (
./deploy.sh) - You have a Telegram account
- AWS CLI is installed with configured credentials
| Item | Value |
|---|---|
| CloudFront URL | https://<YOUR_DOMAIN> |
| Webhook URL template | https://<YOUR_DOMAIN>/api/webhook/{groupId} |
If you have redeployed the stack, fetch the latest URL with
aws cloudformation describe-stacks --stack-name TelegramPhotoWallStack --query "Stacks[0].Outputs".
-
Open Telegram and start a chat with @BotFather
-
Send
/newbot -
Provide:
- Bot name (display name): for example
My Photo Wall Bot - Bot username (unique handle, must end in
bot): for examplemy_photo_wall_bot
- Bot name (display name): for example
-
BotFather returns a Bot Token in this form:
7123456789:AAH1234567890abcdefghijklmnopqrstuv -
Save this token for the next steps.
By default, a Bot cannot read every message in a group. Turn off Privacy Mode:
- In the BotFather chat, send
/mybots - Select the Bot you just created
- Choose Bot Settings → Group Privacy
- Click Turn off
With Privacy Mode off the Bot can receive every group message. Otherwise it only sees
/-prefixed commands.
Store the Bot Token in AWS Secrets Manager (do not hard-code it anywhere):
aws secretsmanager create-secret \
--name "telegram/bot-token/demo-group" \
--secret-string "7123456789:AAH1234567890abcdefghijklmnopqrstuv" \
--region us-west-2Replace the token with your own.
demo-groupshould match thesecretNameconfigured incdk.json.
If the secret already exists, use update:
aws secretsmanager update-secret \
--secret-id "telegram/bot-token/demo-group" \
--secret-string "7123456789:AAH1234567890abcdefghijklmnopqrstuv" \
--region us-west-2aws secretsmanager get-secret-value \
--secret-id "telegram/bot-token/demo-group" \
--query SecretString --output text \
--region us-west-2The deployment generated a 64-character random string used to verify webhook origin so that only Telegram requests are accepted:
WEBHOOK_SECRET=$(aws secretsmanager get-secret-value \
--secret-id "telegram/webhook-secret" \
--query SecretString --output text \
--region us-west-2)
echo $WEBHOOK_SECRETTell Telegram where to push messages:
BOT_TOKEN="7123456789:AAH1234567890abcdefghijklmnopqrstuv"
WEBHOOK_URL="https://<YOUR_DOMAIN>/api/webhook/demo-group"
curl -X POST "https://api.telegram.org/bot${BOT_TOKEN}/setWebhook" \
-H "Content-Type: application/json" \
-d "{
\"url\": \"${WEBHOOK_URL}\",
\"secret_token\": \"${WEBHOOK_SECRET}\",
\"allowed_updates\": [\"message\"]
}"Expected response:
{"ok":true,"result":true,"description":"Webhook was set"}curl -s "https://api.telegram.org/bot${BOT_TOKEN}/getWebhookInfo" | python3 -m json.toolKey fields in the expected output:
{
"ok": true,
"result": {
"url": "https://<YOUR_DOMAIN>/api/webhook/demo-group",
"has_custom_certificate": false,
"pending_update_count": 0,
"last_error_date": null,
"last_error_message": null
}
}If
last_error_messageis non-null, Telegram is hitting an error during delivery; investigate based on the message.
- Open the Telegram group you want to sync
- Open the group settings → Add Members
- Search for the Bot username (e.g.
@my_photo_wall_bot) - Add the Bot to the group
Send a test message in the group (text or photo) and open the photo wall page to confirm it appears:
https://<YOUR_DOMAIN>/wall/demo-group
To configure additional independent walls, follow these steps:
A Bot can only have one webhook URL. Different groups therefore require separate Bots.
aws secretsmanager create-secret \
--name "telegram/bot-token/marketing" \
--secret-string "NEW_BOT_TOKEN_HERE" \
--region us-west-2{
"context": {
"telegramGroups": [
{
"groupId": "demo-group",
"chatId": "-1001234567890",
"name": "Demo Photo Wall",
"secretName": "telegram/bot-token/demo-group"
},
{
"groupId": "marketing",
"chatId": "-1009876543210",
"name": "Marketing Photo Wall",
"secretName": "telegram/bot-token/marketing"
}
]
}
}Field reference:
| Field | Description | Example |
|---|---|---|
groupId |
URL identifier for the wall (letters, digits, underscore, hyphen) | marketing |
chatId |
Telegram group Chat ID (see appendix) | -1001234567890 |
name |
Title displayed on the wall | Marketing Photo Wall |
secretName |
Name of the Bot Token secret in Secrets Manager | telegram/bot-token/marketing |
npx cdk deploy --require-approval neverNEW_BOT_TOKEN="<new bot token>"
curl -X POST "https://api.telegram.org/bot${NEW_BOT_TOKEN}/setWebhook" \
-H "Content-Type: application/json" \
-d "{
\"url\": \"https://<YOUR_DOMAIN>/api/webhook/marketing\",
\"secret_token\": \"${WEBHOOK_SECRET}\",
\"allowed_updates\": [\"message\"]
}"Method 1: Via the Bot API
- Add the Bot to the group
- Send any message in the group
- Run:
curl -s "https://api.telegram.org/bot${BOT_TOKEN}/getUpdates" | python3 -m json.tool- Locate
message.chat.idin the JSON response. Group Chat IDs are typically negative (e.g.-1001234567890).
Method 2: Via @userinfobot
- Add
@userinfobotto the group - It will reply with the group's Chat ID
- Remove it once you have the value
curl -X POST "https://api.telegram.org/bot${BOT_TOKEN}/deleteWebhook"aws logs tail /ecs/telegram-photo-wall --follow --region us-west-2Q: Messages were sent in the group but nothing appears on the wall.
- Confirm the Bot has been added to the group
- Confirm Privacy Mode is off (BotFather → Bot Settings → Group Privacy → Turn off)
- Check webhook status:
curl -s "https://api.telegram.org/bot${BOT_TOKEN}/getWebhookInfo" - Inspect ECS logs for errors
Q: Photos do not load.
- Photos use S3 pre-signed URLs with a 1-hour TTL; refresh the page to mint new URLs
- Confirm the ECS Task Role has S3 read/write permissions (CDK provisions this automatically)
Q: Webhook returns 403.
- Confirm the
secret_tokenmatches the value in Secrets Manager (telegram/webhook-secret) - Confirm the
groupIdin the webhook URL matches thegroupIdincdk.json