Telegram Bot Integration
Create a Telegram bot, save its credentials as a target, and test delivery.
Use this guide to send PayloadRelay webhook payloads to a Telegram chat, group, or channel.
Purpose#
Use this guide to:
- Create a Telegram bot with @BotFather.
- Get the chat ID or the channel ID.
- Save the bot token and the chat ID as a relay target.
- Attach the target to an endpoint destination.
- Send a test delivery.
Before you start#
- A Telegram account.
- Admin access to the Telegram chat or channel. A channel needs this access.
- 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>"
}PayloadRelay escapes the JSON for HTML and puts it in a <pre> block. The message can contain a maximum of 4096 characters. PayloadRelay keeps space for the endpoint name, and it cuts the payload text when this is necessary. A template message also keeps space for an optional Activity link.
Procedure#
1. Create a bot with @BotFather#
- Open Telegram and search for
@BotFather. - Send
/newbot. Enter a name and a username when @BotFather asks for them. - BotFather replies with your
bot tokenin the format123456789:ABCdefGhIJKlmnopQRSTuvWXYZ. - Copy this token and keep it in a safe location.
2. Get the chat ID#
For a private chat or a group:
- Add your new bot to the chat or the group.
- Send a message in the chat.
- Open
https://api.telegram.org/bot<YOUR_TOKEN>/getUpdatesin a browser. - Find
"chat": {"id": -1001234567890, ...}in the response. - Copy the
idvalue. A group ID and a channel ID contain a minus sign.
Alternative: @userinfobot
- Forward a message from the chat or the channel to
@userinfobot. - The bot replies 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 targetsin PayloadRelay. - Select
Add target. - Select
Telegramas the type. - Enter the bot token in the
Bot Tokenfield.- PayloadRelay stores the token encrypted, and it does not show the token after you save.
- Enter the
Chat ID, for example,-1001234567890. - Add a name and a description. These values are optional. Then save.
The target needs no email confirmation. It is available immediately.
4. Attach the target to an endpoint#
- Open the endpoint create page or the endpoint edit page.
- In
Outputs, select the Telegram target. - Save the endpoint.
5. Test delivery#
- On the
Relay targetspage, find the Telegram target and selectSend test. - PayloadRelay starts a test delivery and records the result in Activity. If Telegram accepts the request, a test message appears in the chat. If Telegram rejects the request, read the delivery details for the Bot API error.
Security#
- PayloadRelay stores the bot token in a safe location, and it does not show the token after you save.
- The chat ID is routing information. It is not a secret.
- To change the bot token, edit the target and enter the new token.
Retry behavior#
A failed endpoint delivery uses the standard automatic retry schedule of PayloadRelay, in the limit of the plan. A Telegram retry has no separate configuration. Telegram can rate-limit a continuous burst. Send the deliveries less frequently, or let the retries correct the temporary errors.
Troubleshooting#
| Symptom | Likely cause | Fix |
|---|---|---|
| 400 Bad Request: chat not found | A wrong chat ID | Read the chat ID again. You can use getUpdates. |
| 403 Forbidden: bot was kicked | The bot is not a member of the chat | Add the bot to the chat again. |
| 403 Forbidden: bot is not admin | The bot has no send permission in the channel | Make the bot an admin with the Post Messages permission. |
| No delivery and no error | The bot token is revoked | Create a new token with @BotFather, and update the target. |
| The test button fails with 400 | The bot token is missing | Edit the target and enter the bot token. |