Telegram bots offer a number of features for AI chatbots.
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:
random_idThis 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.
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.
In other words, each live draft (identified by random_id, chat_id and topic_id as specified above) has its own expiration date, equal to reception_date + message_typing_draft_ttl.
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 add a new live draft along with existing ones, and graphical clients should render this by appending a new live draft message to the chat, 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 a variable number of live drafts, with each new draft replacing the previous one only if it has the same random_id and is sent to the same topic and peer.
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.
Please note that not all Telegram clients currently support rendering multiple live drafts with different
random_ids in the same topic concurrently, some clients may treat all drafts sent to the same topic as having the samerandom_id.
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.