TelegramBot

TelegramBot

This feeder consumes updates from a bot registered with @BotFather using the Telegram Bot API.
Unlike the telegram feeder (MTProto user client), telegrambot is suited for interactive bots that expose commands or inline keyboards.

Based on go-telegram/bot.

Parameters

ParameterTypeDefaultDescription
tokenSTRINGemptyBot token issued by @BotFather. Required.
modeSTRINGpollingpolling or webhook.
addrSTRING:3000Listen address (webhook mode only).
webhook_urlSTRINGemptyPublic URL registered with Telegram (required if mode=webhook).
webhook_secretSTRINGemptyTelegram secret_token for incoming webhook verification.
delete_webhook_on_stopBOOLfalseUnregister the webhook from Telegram on shutdown.
commandsSTRINGemptyComma-separated command list (e.g. /start,/help). Empty = auto-detect any /xxx.
allowed_usersSTRINGemptyComma-separated user IDs or @usernames. Empty = all. Usernames matched case-insensitively. When set, the sender MUST be in the list — non-listed users are rejected regardless of chat origin.
allowed_chatsSTRINGemptyComma-separated chat IDs. Empty = all. When allowed_users is also set, private DMs from listed users bypass this list (so listed users can always DM the bot).
eventsSTRINGallComma-separated subset of message,command,callback_query,edited_message,channel_post,edited_channel_post,chat_member,my_chat_member.
debugBOOLfalseEnable library debug logging.
tgRule => <telegrambot: token="123:abc", commands="/start,/help", allowed_users="@alice,@bob"> | ...
tgRule => <telegrambot: token="123:abc", mode="webhook", webhook_url="https://example.com/webhook", webhook_secret="sekret"> | ...

Output

Every propagated message carries a type extra field identifying the update kind.

Common fields (when applicable):

NameDescription
typeEvent kind.
update_idTelegram update ID.
user_id, user_username, user_firstname, user_lastname, user_language, user_isbot, user_ispremiumSender info.
chat_id, chat_type, chat_title, chat_usernameChat info.

Event message / command

NameDescription
textMessage text (also the main field).
msg_id, msg_timestamp, msg_date, msg_timeTiming.
msg_editedAlways false for this event.
msg_captionCaption, if present.
msg_reply_to_idReplied-to message ID, if any.
msg_forward_fromForwarded-from user ID (only when forward origin is a user).
msg_forward_from_chatForwarded-from chat/channel ID.
msg_hasmediatrue when media attached.
msg_mediatypephoto, document, video, audio, voice, sticker, animation.
msg_medianame, msg_mediaext, msg_mediasizeMedia metadata.
msg_file_id, msg_file_unique_idBot API file identifiers.
commandCommand (e.g. /start). Only on type=command.
command_argsText after the command. Only on type=command.

Event edited_message / edited_channel_post

Same fields as above with msg_edited=true and an additional msg_edit_date field.

Event channel_post / edited_channel_post

Message fields as above. user_* may be absent (channel posts can lack a sender).

Event callback_query

NameDescription
callback_idCallback query ID.
callback_dataButton payload (also the main field).
callback_chatinstanceTelegram chat instance identifier.
chat_id, chat_type, chat_title, chat_usernameChat the keyboard message lives in (also populated when the original message is no longer accessible). Absent only for inline_message_id-only callbacks.
msg_idID of the message that carried the inline keyboard (useful with edit_message).

Event chat_member / my_chat_member

NameDescription
member_old_statusPrevious member status.
member_new_statusNew member status.
member_user_id, member_user_usernameAffected user.

Examples

tgRule => <telegrambot: token="123:abc", commands="/start", allowed_users="@alice,12345"> | text(target="command", pattern="/start") | log(msg="start received from {{ .user_username }}")