Telegram Bot Integration
Create a Telegram bot, get a chat ID, register credentials as a relay target, and validate delivery.
Use this guide to forward PayloadRelay webhook payloads to a Telegram chat, group, or channel.
Purpose
This workflow helps you:
- Create a Telegram bot via @BotFather.
- Obtain your chat or channel ID.
- Register the bot token and chat ID as a relay target.
- Attach the target to an endpoint output.
- Validate with a test delivery.
Prerequisites and permissions
- A Telegram account.
- Admin access to the target Telegram chat or channel (for channels).
- Access to
Relay targetsandEndpointsin PayloadRelay.
Payload format
PayloadRelay sends a sendMessage request to the Telegram Bot API:
{
"chat_id": "<your-chat-id>",
"parse_mode": "HTML",
"text": "<b>EndpointName</b>\n<pre>{ ...original payload... }</pre>"
}The payload JSON is HTML-escaped and embedded in a <pre> block for monospace rendering. Total message length is capped at ~3500 characters (Telegram max is 4096) to leave headroom for the header.
Step-by-step workflow
1. Create a bot via @BotFather
- Open Telegram and search for @BotFather.
- Send
/newbotand follow the prompts to choose a name and username. - BotFather will reply with your bot token in the format
123456789:ABCdefGhIJKlmnopQRSTuvWXYZ. - Copy and save this token securely.
2. Get the chat ID
For a private chat or group:
- Add your new bot to the chat or group.
- Send any message in the chat.
- Open
https://api.telegram.org/bot<YOUR_TOKEN>/getUpdatesin a browser. - Look for
"chat": {"id": -1001234567890, ...}in the response. - Copy the
idvalue (including the minus sign for groups/channels).
Alternative — @userinfobot:
- Forward a message from the target chat/channel to @userinfobot.
- The bot will reply with the chat ID.
For a public channel:
- Add your bot as an admin of the channel.
- Use the
getUpdatesmethod above, or use@userinfobot.
3. Add a Telegram relay target
- Open Relay targets in PayloadRelay.
- Select Add target.
- Choose Telegram as the type.
- Enter your Bot Token in the Bot Token field.
- Stored encrypted and never shown again after saving.
- Enter the Chat ID (e.g.,
-1001234567890). - Optionally add a name and description, then save.
No email confirmation is required — the target is ready immediately.
4. Attach the target to an endpoint
- Open the endpoint create/edit page.
- In Target destinations, select your Telegram target.
- Save the endpoint.
5. Validate delivery
- On the Relay targets page, find your Telegram target and select Send test.
- PayloadRelay queues a test delivery and records the result in activity. If Telegram accepts the request, a test message appears in the configured chat; if Telegram rejects it, check the delivery details for the Bot API error.
Security
- The bot token is stored securely and is not shown again after saving.
- Treat the chat ID as non-secret routing information.
- To rotate the bot token, edit the target and enter the new token.
Retry behavior
Failed endpoint deliveries use PayloadRelay's standard automatic retry schedule capped by your plan. Telegram retries are not separately configurable like webhook-output retry policies. Telegram may rate-limit sustained bursts; if that happens, reduce delivery frequency or let retries recover temporary failures.
Troubleshooting
| Symptom | Likely cause | Fix |
|---|---|---|
| 400 Bad Request: chat not found | Wrong chat ID | Double-check the chat ID (use getUpdates method). |
| 403 Forbidden: bot was kicked | Bot is not a member of the chat | Add the bot to the chat again. |
| 403 Forbidden: bot is not admin | Bot lacks send permission in the channel | Make the bot an admin with Post Messages permission. |
| Message not delivered, no error | Bot token revoked | Regenerate token via @BotFather and update the target. |
| Test button fails with 400 | Missing bot token | Edit the target and enter the bot token. |