Skip to main content

Telegram

Telegram event integrations receive webhook updates from the Telegram Bot API and trigger handler functions as messages, callback queries, and other update types arrive. Use them to build chatbots, handle inline keyboard interactions, and automate replies without polling getUpdates.

note

The Telegram webhook listener must be reachable over HTTPS from the internet. For local development, use a tunneling tool such as ngrok to create a public HTTPS URL for your local port.

Create a bot and get a token by messaging @BotFather on Telegram and sending /newbot. See the setup guide for details.

Creating a Telegram listener​

  1. Click + Add Artifact in the canvas or click + next to Entry Points in the sidebar.

  2. In the Artifacts panel, select Telegram under Event Integration.

  3. In the creation form, fill in the following fields:

    Create Telegram form showing the Listener Name, Port, Access Token, and Callback URL fieldsCreate Telegram form showing the Listener Name, Port, Access Token, and Callback URL fields
    FieldDescriptionDefault
    Listener NameIdentifier for the listener created with this service.telegramListener
    PortThe port on which the webhook listener accepts incoming HTTP requests.8090
    Access TokenThe bot access token issued by @BotFather. Used both to derive the webhook secret token and, together with Callback URL, to auto-register the webhook.Required
    Callback URLThis listener's public HTTPS URL, used to auto-register the webhook when set.()

    Expand Advanced Configurations to override the Telegram Bot API base URL.

    FieldDescriptionDefault
    Service URLThe Telegram Bot API base URL.https://api.telegram.org
  4. Click Create.

  5. WSO2 Integrator opens the service in the Service Designer. The canvas shows the attached listener pill and an empty Event Handlers section.

  6. Click + Add Handler to define how incoming updates are processed.

Service configuration​

Service configuration controls the service name and the Telegram listener it is attached to.

In the Service Designer, click Configure to open the Telegram Configuration panel.

The panel shows a Service Configuration field for the service's acknowledgement behavior, and an Attached Listeners list. Pick a listener under Attached Listeners to configure its connection settings.

Telegram Configuration panel showing the empty Service Configuration record editor, and the Attached Listeners list with the Name, Listen To, Access Token, Service URL, and Callback URL fieldsTelegram Configuration panel showing the empty Service Configuration record editor, and the Attached Listeners list with the Name, Listen To, Access Token, Service URL, and Callback URL fields

Service configuration​

FieldDescription
Service ConfigurationAdvanced acknowledgement settings as a @telegram:ServiceConfig record expression (e.g., { autoAck: false }). Defaults to autoAck: true, acknowledging automatically. See Manual acknowledgement.

Main configurations​

FieldDescription
NameThe name of the listener. Required.
Listen ToA port number to bind a new http:Listener to, or an existing http:Listener. Required.
Access TokenThe bot access token issued by @BotFather. Used both to derive the webhook secret token and, together with Callback URL, to auto-register the webhook.
Service URLThe Telegram Bot API base URL; override only for a self-hosted Bot API server, tests, or a proxy. Defaults to https://api.telegram.org.
Callback URLThis listener's public HTTPS URL, used to auto-register the webhook when set.

Click Attach Listener to attach an additional listener to the same service.

Click Save Changes to apply updates.

Event handlers​

An event handler is a remote function that WSO2 Integrator calls for each Telegram Bot API update received.

Adding an event handler​

In the Service Designer, click + Add Handler. A Select Handler to Add panel opens on the right listing the available update types.

Select Handler to Add drawer listing the Telegram event handlersSelect Handler to Add drawer listing the Telegram event handlers

Pick On Message, then click Save. This opens the Flow Designer for onMessage.

Flow canvas for the Telegram onMessage handlerFlow canvas for the Telegram onMessage handler

Use the flow canvas to add integration steps such as database writes, HTTP calls, and transformations. Repeat these steps to add the other handlers you need.

Manual acknowledgement​

By default, the listener acknowledges (200 OK) each update automatically, before any handler runs. Telegram requires a fast 2xx and retries otherwise, so this is the safe default for slow handlers. Annotate the service @telegram:ServiceConfig {autoAck: false} to decide exactly when an update is acknowledged instead, and declare a handler's optional second parameter as a telegram:Caller:

@telegram:ServiceConfig {
autoAck: false
}
service telegram:TelegramService on telegramListener {

remote function onMessage(telegram:Message message, telegram:Caller caller) returns error? {
check persistMessage(message);
check caller->complete();
}
}

If a handler declared with a Caller never calls caller->complete(), the listener never sends its own 200 OK for that request, and Telegram's own retry behavior treats the resulting failure the same as any other failed delivery. Telegram may redeliver an update if the acknowledgement is slow, dropped, or never sent, under either autoAck setting, not just false, so make handler processing idempotent, or deduplicate using update_id.

Handler types​

This listener supports nine Telegram update types, one per TelegramService handler. All are optional. Implement only the ones your bot needs. Telegram's allowed_updates already keeps unsupported update types from reaching your webhook; among the nine supported types, an update whose handler you didn't declare is acknowledged and ignored.

HandlerTriggered when
onMessageA new incoming message arrives.
onEditedMessageAn existing message is edited.
onChannelPostA new channel post is published.
onEditedChannelPostAn existing channel post is edited.
onCallbackQueryA user presses an inline keyboard button.
onInlineQueryA user sends a new inline query.
onPollA poll's state changes.
onPreCheckoutQueryA user confirms a payment, just before it's charged.
onShippingQueryA user provides a shipping address for an invoice with flexible pricing.

What's next​