Skip to content

Connect a Telegram bot

Availability: Live /status

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.

  • 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 with login, 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>.

  1. In Telegram, open a chat with @BotFather, Telegram’s own tool for creating bots.
  2. Send /newbot, then answer the two questions: a display name, and a username that ends in bot.
  3. BotFather replies with a token that looks like 123456789:AA.... Copy it.

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.

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.

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.

  1. Open your bot in Telegram and press Start. The bot replies with the agent’s openingGreeting (a generic line if the agent has none).
  2. Send a real message. The reply arrives after a few seconds, produced by the agent’s published workflow.
  3. 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.

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.

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. allowedGroupIds holds the Telegram chat ids (groups are negative numbers); an empty list serves no group.
  • It starts in shadow mode. With shadow left at its default of true, 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.

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.

What you seeLikely causeWhat to do
FORBIDDEN on any connector callThe login is not the workspace ownerSign in as the owner
Step 3 fails with a Telegram errorThe token is wrong, was revoked, or has extra spacesCopy the token again from BotFather
Step 3 fails with “already registered to another channel connector”That bot belongs to another connectorPause the other connector, or create a new bot
Activation fails and lastErrorMessage is setTelegram refused the check or the webhookFix the cause named in the message, then call activateChannelConnector again
status is ACTIVE but the bot never answersThe agent has no published workflowPublish the workflow and attach it to the agent; see the Quickstart
The bot answers with a generic apologyThe workflow failed on that turnOpen the run in Observability
In a group the bot never answersPrivacy mode still on, group not in allowedGroupIds, or shadow still trueCheck all three, in that order
The bot answers every group messagetalkativeness is CHATTYUse MENTION_ONLY or QUIET

For every field and error of the connector calls, see the Channels API reference.