|
| 1 | +# How to Create a New Group Photo Wall |
| 2 | + |
| 3 | +This guide explains how to add an independent photo wall for a new Telegram group. Each group requires its own Bot. |
| 4 | + |
| 5 | +--- |
| 6 | + |
| 7 | +## Prerequisites |
| 8 | + |
| 9 | +- The project has been deployed at least once (`./deploy.sh` or `npx cdk deploy`) |
| 10 | +- AWS CLI is installed and credentials are configured |
| 11 | +- You have a Telegram account |
| 12 | + |
| 13 | +--- |
| 14 | + |
| 15 | +## Step 1: Create a New Telegram Bot |
| 16 | + |
| 17 | +1. Open Telegram and search for **@BotFather** |
| 18 | +2. Send `/newbot` |
| 19 | +3. Provide a Bot name (e.g. `Marketing Wall Bot`) and a username (e.g. `marketing_wall_bot`, must end in `bot`) |
| 20 | +4. Save the returned **Bot Token** |
| 21 | +5. Turn off Privacy Mode: BotFather → `/mybots` → select the Bot → Bot Settings → Group Privacy → **Turn off** |
| 22 | + |
| 23 | +--- |
| 24 | + |
| 25 | +## Step 2: Store the Bot Token in Secrets Manager |
| 26 | + |
| 27 | +```bash |
| 28 | +aws secretsmanager create-secret \ |
| 29 | + --name "telegram/bot-token/marketing" \ |
| 30 | + --secret-string "YOUR_NEW_BOT_TOKEN" \ |
| 31 | + --region us-west-2 |
| 32 | +``` |
| 33 | + |
| 34 | +> The `marketing` suffix in `telegram/bot-token/marketing` is arbitrary; it just has to match the `secretName` you set in the next step. |
| 35 | +
|
| 36 | +--- |
| 37 | + |
| 38 | +## Step 3: Add the New Group to `cdk.json` |
| 39 | + |
| 40 | +Edit the project root `cdk.json` and append a new entry to the `telegramGroups` array: |
| 41 | + |
| 42 | +```json |
| 43 | +{ |
| 44 | + "context": { |
| 45 | + "telegramGroups": [ |
| 46 | + { |
| 47 | + "groupId": "demo-group", |
| 48 | + "chatId": "-1001234567890", |
| 49 | + "name": "Demo Photo Wall", |
| 50 | + "secretName": "telegram/bot-token/demo-group", |
| 51 | + "botUsername": "your_photo_wall_bot" |
| 52 | + }, |
| 53 | + { |
| 54 | + "groupId": "marketing", |
| 55 | + "chatId": "-1009876543210", |
| 56 | + "name": "Marketing Photo Wall", |
| 57 | + "secretName": "telegram/bot-token/marketing", |
| 58 | + "botUsername": "marketing_wall_bot" |
| 59 | + } |
| 60 | + ] |
| 61 | + } |
| 62 | +} |
| 63 | +``` |
| 64 | + |
| 65 | +### Field Reference |
| 66 | + |
| 67 | +| Field | Required | Description | Example | |
| 68 | +|-------|----------|-------------|---------| |
| 69 | +| `groupId` | Yes | URL identifier for the wall; letters, digits, underscore, hyphen only | `marketing` | |
| 70 | +| `chatId` | Yes | Telegram group Chat ID (negative integer); see the appendix for how to obtain it | `-1009876543210` | |
| 71 | +| `name` | Yes | Title shown on the photo wall page | `Marketing Photo Wall` | |
| 72 | +| `secretName` | Yes | Name in Secrets Manager that holds the Bot Token; must match Step 2 | `telegram/bot-token/marketing` | |
| 73 | +| `botUsername` | Yes | The Bot's `@username` (without `@`); only messages that `@mention` it are surfaced on the wall | `marketing_wall_bot` | |
| 74 | + |
| 75 | +--- |
| 76 | + |
| 77 | +## Step 4: Deploy |
| 78 | + |
| 79 | +```bash |
| 80 | +cd photo-wall && npm run build && cd .. |
| 81 | +npx cdk deploy --require-approval never |
| 82 | +``` |
| 83 | + |
| 84 | +After the deployment, the CDK output prints the new group's webhook URL: |
| 85 | + |
| 86 | +``` |
| 87 | +TelegramPhotoWallStack.WebhookUrlmarketing = https://<YOUR_DOMAIN>/api/webhook/marketing |
| 88 | +``` |
| 89 | + |
| 90 | +--- |
| 91 | + |
| 92 | +## Step 5: Register the Telegram Webhook |
| 93 | + |
| 94 | +```bash |
| 95 | +# Fetch the webhook verification secret |
| 96 | +WEBHOOK_SECRET=$(aws secretsmanager get-secret-value \ |
| 97 | + --secret-id "telegram/webhook-secret" \ |
| 98 | + --query SecretString --output text \ |
| 99 | + --region us-west-2) |
| 100 | + |
| 101 | +# Fetch the new Bot Token |
| 102 | +NEW_BOT_TOKEN=$(aws secretsmanager get-secret-value \ |
| 103 | + --secret-id "telegram/bot-token/marketing" \ |
| 104 | + --query SecretString --output text \ |
| 105 | + --region us-west-2) |
| 106 | + |
| 107 | +# Register the webhook |
| 108 | +curl -X POST "https://api.telegram.org/bot${NEW_BOT_TOKEN}/setWebhook" \ |
| 109 | + -H "Content-Type: application/json" \ |
| 110 | + -d "{ |
| 111 | + \"url\": \"https://<YOUR_DOMAIN>/api/webhook/marketing\", |
| 112 | + \"secret_token\": \"${WEBHOOK_SECRET}\", |
| 113 | + \"allowed_updates\": [\"message\"] |
| 114 | + }" |
| 115 | +``` |
| 116 | + |
| 117 | +> Replace `https://<YOUR_DOMAIN>` with the actual CloudFront URL emitted by CDK. |
| 118 | +
|
| 119 | +### Verify the Webhook |
| 120 | + |
| 121 | +```bash |
| 122 | +curl -s "https://api.telegram.org/bot${NEW_BOT_TOKEN}/getWebhookInfo" | python3 -m json.tool |
| 123 | +``` |
| 124 | + |
| 125 | +--- |
| 126 | + |
| 127 | +## Step 6: Add the Bot to the Group |
| 128 | + |
| 129 | +1. Open the target Telegram group |
| 130 | +2. Add member → search for `@marketing_wall_bot` → add |
| 131 | +3. Send a test message in the group: `@marketing_wall_bot hello` |
| 132 | + |
| 133 | +--- |
| 134 | + |
| 135 | +## Step 7: Open the Photo Wall |
| 136 | + |
| 137 | +``` |
| 138 | +https://<YOUR_DOMAIN>/wall/marketing |
| 139 | +``` |
| 140 | + |
| 141 | +If multiple groups are configured, a group switcher appears at the top of the page. |
| 142 | + |
| 143 | +--- |
| 144 | + |
| 145 | +## Appendix |
| 146 | + |
| 147 | +### Get the Telegram Group Chat ID |
| 148 | + |
| 149 | +**Method 1: Via the Bot API** |
| 150 | + |
| 151 | +1. Add the Bot to the group |
| 152 | +2. Send any message in the group |
| 153 | +3. Run: |
| 154 | +```bash |
| 155 | +curl -s "https://api.telegram.org/bot${NEW_BOT_TOKEN}/getUpdates" | python3 -m json.tool |
| 156 | +``` |
| 157 | +4. Locate `message.chat.id` in the returned JSON (group Chat IDs are negative, e.g. `-1009876543210`) |
| 158 | + |
| 159 | +**Method 2: Via @userinfobot** |
| 160 | + |
| 161 | +1. Add `@userinfobot` to the group |
| 162 | +2. It will reply with the group's Chat ID |
| 163 | +3. Remove it once you have the value |
| 164 | + |
| 165 | +### Remove a Group |
| 166 | + |
| 167 | +1. Remove the entry from `telegramGroups` in `cdk.json` |
| 168 | +2. Redeploy: `npx cdk deploy` |
| 169 | +3. (Optional) Delete the Bot Token: `aws secretsmanager delete-secret --secret-id "telegram/bot-token/marketing" --region us-west-2` |
| 170 | +4. (Optional) Remove the webhook: `curl -X POST "https://api.telegram.org/bot${NEW_BOT_TOKEN}/deleteWebhook"` |
| 171 | + |
| 172 | +### Quick Reference |
| 173 | + |
| 174 | +| Step | Command / Action | |
| 175 | +|------|------------------| |
| 176 | +| 1. Create the Bot | BotFather `/newbot` + turn off Privacy Mode | |
| 177 | +| 2. Store the Token | `aws secretsmanager create-secret ...` | |
| 178 | +| 3. Update config | Edit `cdk.json`, append the new group | |
| 179 | +| 4. Deploy | `npx cdk deploy` | |
| 180 | +| 5. Register webhook | `curl ... setWebhook` | |
| 181 | +| 6. Add Bot to group | Add as a Telegram group member | |
| 182 | +| 7. Test | Send `@bot hello` in the group, open `/wall/groupId` | |
0 commit comments