Skip to main content

Example

Telegram Trigger Example​

What you'll build​

This integration reacts to incoming Telegram messages. When a user sends a message to your bot, the telegram:Listener receives the webhook update and routes it to the onMessage handler in your telegram:TelegramService. The handler logs the chat ID and message text.

Architecture​

Prerequisites​

Setting up the Telegram integration​

New to WSO2 Integrator? Follow the Create a New Integration guide to set up your integration first, then return here to add the trigger.

Adding the Telegram trigger​

Add a Telegram event integration and implement the listener and service as described in the Telegram event integration guide. WSO2 Integrator renders the listener and service on the design canvas, with all available handlers listed under Event Handlers.

WSO2 Integrator design canvas showing the telegramListener connected to TelegramService with onMessage and onEditedMessage handlersWSO2 Integrator design canvas showing the telegramListener connected to TelegramService with onMessage and onEditedMessage handlers

Select telegram:TelegramService in the design canvas to open the Service Designer, which lists every pre-registered event handler bound to the telegramListener.

Telegram Service Designer listing onMessage, onEditedMessage, onCallbackQuery, and onInlineQuery handlersTelegram Service Designer listing onMessage, onEditedMessage, onCallbackQuery, and onInlineQuery handlers

Handling Telegram events​

Select the onMessage row to open its flow canvas, then add a Log Info step with the message text:

remote function onMessage(telegram:Message message) returns error? {
log:printInfo("Telegram message received", chatId = message.chat.id, text = message.text);
}

Running the integration​

Run the integration from WSO2 Integrator, then send a message to your bot from Telegram. Telegram delivers the webhook to your listener, which invokes onMessage and logs the message. Verify the log entry in the WSO2 Integrator console output.

What's next​