AI features for bots

Telegram bots offer a number of features for AI chatbots.

Live response streaming

sendMessageTextDraftAction#376d975c random_id:long text:TextWithEntities = SendMessageAction;

updateUserTyping#2a17bf5c flags:# user_id:long top_msg_id:flags.0?int action:SendMessageAction = Update;

---functions---

messages.setTyping#58943ee2 flags:# peer:InputPeer top_msg_id:flags.0?int action:SendMessageAction = Bool;

Live response streaming allows chatbots to stream text responses to the user as they are generated.

Live response streaming is implemented using live drafts, represented by the sendMessageTextDraftAction typing action, sent using messages.setTyping and received inside of updateUserTyping updates.

Unlike other typing notifications, incoming live drafts are rendered as a normal messages, always pinned to the bottom of the chat, as if they were the last sent message in the chat.

Currently, live drafts can only be sent to users.
Both bots and normal users can send live drafts to other users.

Every live draft is identified by a combination of the following values:

This means that i.e. {random_id: 1, chat_id: 1234, topic_id: 2} and {random_id: 1, chat_id: 1234, topic_id: 3} point to different live drafts that can be updated independently.

To update a live draft, simply send a new sendMessageTextDraftAction with the same random_id to the same chat and topic: graphical clients should render this by updating the live draft message, fading in (or otherwise animating) the added characters (the number of chars to fade in is equal to max(0, strlen(new) - strlen(prev))).

To create a new live draft, send a new sendMessageTextDraftAction with a different random_id to the same chat and topic: this will replace any previous live draft, and graphical clients should render this by updating the entire live draft message, fading in (or otherwise animating) all characters (the number of chars to fade in is equal to strlen(new)).

To recap, each chat (or each bot forum topic, for bot forums ») can have at most one live draft, with each new draft replacing the previous one, with slightly different update rendering depending on whether the previous draft had the same or a different ID.

Live draft messages should be deleted automatically by graphical clients message_typing_draft_ttl » seconds after they're received, or when receiving a normal message within the same chat/bot forum topic, whichever comes first.

The exact batching of live draft updates is up to the bot: live drafts can be sent, for example, every N generated UTF-8 chars or every M seconds, whichever comes first.

Bot forums

Bots can behave like forums » if Threaded mode is enabled via @botfather.

This is especially useful for AI chatbots, see here » for a detailed description of bot forums.

Note: this feature is subject to an additional fee for Telegram Star purchases as described in Section 6.2.6 of our Terms of Service for Bot Developers.