Connect a Telegram bot
Availability: Live
This page connects one Telegram bot to one Wetel agent so that anyone who messages the bot talks to that agent. It takes about ten minutes and four API calls. Wetel registers the Telegram webhook for you: there is no server to run and no webhook URL to paste anywhere.
What you need
Section titled “What you need”- An agent with a published workflow. If you have not built one, run the Quickstart first and keep the agent
id. - A workspace owner login. Creating, activating and pausing a connector are owner-only: any other member gets
FORBIDDEN. Get a token withlogin, as in the Quickstart. - A Telegram account on your phone or desktop.
Every request goes to https://api.wetel.dev/graphql (the test environment) with the headers x-huat-platform: customer and Authorization: Bearer <accessToken>.
Step 1: Create the bot in Telegram
Section titled “Step 1: Create the bot in Telegram”- In Telegram, open a chat with @BotFather, Telegram’s own tool for creating bots.
- Send
/newbot, then answer the two questions: a display name, and a username that ends inbot. - BotFather replies with a token that looks like
123456789:AA.... Copy it.
Step 2: Create the connector
Section titled “Step 2: Create the connector”This reserves a connector in DRAFT status for your agent. It does not talk to Telegram yet.
mutation CreateChannelConnector($input: CreateChannelConnectorInput!) { createChannelConnector(input: $input) { id status channelType }}{ "input": { "agentId": 42, "channelType": "TELEGRAM" } }Expected response: status is DRAFT. Keep the connector id.
Step 3: Set the bot token
Section titled “Step 3: Set the bot token”mutation SetCredentials($input: UpdateChannelConnectorCredentialsInput!) { updateChannelConnectorCredentials(input: $input) { id status externalIdentifier }}{ "input": { "connectorId": 1, "credential": { "token": "<YOUR_BOT_TOKEN>" } }}Send credential as a variable, never as an inline literal. Wetel checks the token with Telegram before it saves anything, so a wrong token fails here, with nothing stored. On success externalIdentifier is the bot’s numeric id and status is still DRAFT.
A bot can belong to only one connector. If the bot is already connected somewhere, the call fails with BAD_REQUEST; pause the other connector first or create a new bot.
Step 4: Activate
Section titled “Step 4: Activate”mutation Activate($input: ActivateChannelConnectorInput!) { activateChannelConnector(input: $input) { id status lastErrorMessage }}{ "input": { "connectorId": 1 } }Wetel runs a second check with Telegram and registers the webhook. Expected response: status is ACTIVE and lastErrorMessage is null. If anything fails the call returns an error, the status does not change, and lastErrorMessage holds the reason.
Step 5: Test it
Section titled “Step 5: Test it”- Open your bot in Telegram and press Start. The bot replies with the agent’s
openingGreeting(a generic line if the agent has none). - Send a real message. The reply arrives after a few seconds, produced by the agent’s published workflow.
- To see the connector from the API side, read it back:
query Connectors { listChannelConnectors { id agentId channelType status lastErrorMessage }}If the bot stays silent, check status and lastErrorMessage first, then the table at the end of this page.
Sending /start at any time ends the current conversation and begins a fresh one, which is the way out of a chat that has gone off track.
Optional: voice replies
Section titled “Optional: voice replies”By default the agent answers in text. To have it answer a voice note with a voice note, switch it on per connector:
mutation VoiceReplies($input: UpdateChannelConnectorSettingsInput!) { updateChannelConnectorSettings(input: $input) { id voiceReplyEnabled alwaysVoiceReply }}{ "input": { "connectorId": 1, "voiceReplyEnabled": true, "alwaysVoiceReply": false }}With alwaysVoiceReply left false, the bot sends a voice reply only when the person sent a voice note. Setting it to true forces every reply to be voice and only takes effect while voiceReplyEnabled is true.
Group mode
Section titled “Group mode”In a group, a bot that answered every message would be unbearable. Group mode makes the bot behave like a quiet member: it answers when it is mentioned, replied to, or called by name, and, depending on how talkative you set it, may speak up unprompted when a short judgement says it should. Otherwise it stays silent. A cooldown and a daily cap limit unprompted messages.
Three things to know before you turn it on:
- Switch off the bot’s privacy mode in BotFather (
/mybots, your bot, Bot Settings, Group Privacy, Turn off), then remove and re-add the bot to the group. Otherwise Telegram never shows the bot messages that do not mention it. - Only groups you list are served.
allowedGroupIdsholds the Telegram chat ids (groups are negative numbers); an empty list serves no group. - It starts in shadow mode. With
shadowleft at its default oftrue, the bot decides and logs what it would do but never replies, so you can check its judgement before it speaks.
mutation GroupMode($input: UpdateChannelConnectorGroupModeInput!) { updateChannelConnectorGroupMode(input: $input) { id groupMode groupConfig }}{ "input": { "connectorId": 1, "groupMode": true, "config": { "allowedGroupIds": ["-1001234567890"], "talkativeness": "MENTION_ONLY", "shadow": true } }}talkativeness is MENTION_ONLY, QUIET, NORMAL or CHATTY. When you are happy with what shadow mode logged, send the same call with "shadow": false. Private chats are not affected by group mode. A fuller walk-through is in the group chat recipe.
Pause the bot
Section titled “Pause the bot”mutation Pause($input: DeactivateChannelConnectorInput!) { deactivateChannelConnector(input: $input) { id status }}{ "input": { "connectorId": 1 } }Expected response: status is PAUSED. No messages are processed while paused. To resume, call activateChannelConnector again; you do not need to enter the token again. Pausing also releases the bot, so a different connector can use it.
There is no call that deletes a connector today.
If something goes wrong
Section titled “If something goes wrong”| What you see | Likely cause | What to do |
|---|---|---|
FORBIDDEN on any connector call | The login is not the workspace owner | Sign in as the owner |
| Step 3 fails with a Telegram error | The token is wrong, was revoked, or has extra spaces | Copy the token again from BotFather |
| Step 3 fails with “already registered to another channel connector” | That bot belongs to another connector | Pause the other connector, or create a new bot |
Activation fails and lastErrorMessage is set | Telegram refused the check or the webhook | Fix the cause named in the message, then call activateChannelConnector again |
status is ACTIVE but the bot never answers | The agent has no published workflow | Publish the workflow and attach it to the agent; see the Quickstart |
| The bot answers with a generic apology | The workflow failed on that turn | Open the run in Observability |
| In a group the bot never answers | Privacy mode still on, group not in allowedGroupIds, or shadow still true | Check all three, in that order |
| The bot answers every group message | talkativeness is CHATTY | Use MENTION_ONLY or QUIET |
For every field and error of the connector calls, see the Channels API reference.