Receive Telegram events
Updates from polling or webhooks normalize into shared ChannelEvent values before reaching your handler. See @anvia/telegram for setup and receive modes.
Start the handler
await channel.start(async (event) => {
if (event.type === 'message') {
console.log(event.text, event.attachments, event.replyTo, event.mentionedBot)
}
if (event.type === 'action') {
console.log(event.sender.id, event.actionId, event.messageId)
}
if (event.type === 'command') {
console.log(event.name, event.text)
}
if (event.type === 'reaction') {
console.log(event.reaction, event.removed)
}
})- Events whose sender is any bot account are filtered out before delivery.
mentionedBotis true when a message mentions the bot via@<botusername>(or an inline text mention), addresses a command to it with its username suffix, or replies to one of its messages. A bare/startin a group still arrives as acommandevent, but withmentionedBot === false.- The chat type maps to
conversation.kind:privatebecomesdirect, groups and supergroups becomegroup, and channels becomechannel. - Ordinary emoji reactions are preserved. Custom emoji become
telegram:custom_emoji:<id>and paid reactions becometelegram:paid; anonymous reactions use the acting chat as the normalized sender. - Message edits arrive as
message-editedevents carrying the new text and attachments.
Command targeting
A message whose first entity is a bot_command at offset 0 becomes a command event: the name is lowercased with any @target stripped, and the remaining text is trimmed into text. A command addressed to a different bot (/ask@otherbot) is ignored; a command with no target passes through.
Receive scope
The adapter subscribes only to message, edited_message, message_reaction, and callback_query updates. Everything else Telegram can emit — channel posts, inline queries, polls, membership changes — is never delivered. Messages with no sender, no text/caption, and no media (stickers, locations, polls on their own) also produce no event, as do button presses on messages the adapter cannot see or with non-portable callback data.
Continue with
- Telegram messaging — reply, edit, and react through the Bot API.
- Telegram client and transport — validate and normalize updates yourself.