AI features

Telegram offers many AI features powered by Cocoon — a decentralized network designed to maximize privacy.

Compose messages

messageEntityDiffInsert#71777116 offset:int length:int = MessageEntity;
messageEntityDiffReplace#c6c1e5a7 offset:int length:int old_text:string = MessageEntity;
messageEntityDiffDelete#0652c1c5 offset:int length:int = MessageEntity;

textWithEntities#751f3146 text:string entities:Vector<MessageEntity> = TextWithEntities;

messages.composedMessageWithAI#90d7adfa flags:# result_text:TextWithEntities diff_text:flags.0?TextWithEntities = messages.ComposedMessageWithAI;

---functions---

messages.composeMessageWithAI#fd426afe flags:# proofread:flags.0?true emojify:flags.3?true text:TextWithEntities translate_to_lang:flags.1?string change_tone:flags.2?string = messages.ComposedMessageWithAI;

Use messages.composeMessageWithAI when writing a message to invoke telegram's AI Editor that can translate, transform, fixup and/or emojify your text in a number of different ways, privately powered by Cocoon!

This method is invoked when pressing the AI button in the text input bar in chats: the AI button should be shown only for messages with more than 3 lines of text (even if the method itself doesn't have any limitation).

There are multiple available editor modes, enabled by the appropriate flag:

  • proofread - Proofread and fix mistakes in the message
  • translate_to_lang - Translate the message to the specified language (pass the desired language code)
  • change_tone - Rephrase the message using the specified tone » (pass the style ID)
  • emojify - Add emojis to the message

All of the modes specified above can be combined.

Pass the text to transform in text: the method will return a messages.composedMessageWithAI constructor, containing the transformed message in the result_text field, with all styled text entities offsets appropriately moved/resized/deleted as needed.

If only the proofreading mode (proofread) is enabled, the method will additionally populate messages.composedMessageWithAI.diff_text with a "pre-rendered" diff between the old and the new message text.

diff_text should be rendered by simply rendering the textWithEntities, which only in this case will contain only diff entities, rendered as specified here » (normal styled text entities will always be stripped only in diff_text, never in result_text).

AI compose tones

The full and up to date list of available AI composer tones is available in the ai_compose_styles client configuration key », example value:

[
        [
            "formal",
            "5357080225463149588",
            "Formal"
        ],
        [
            "short",
            "5350460637182993292",
            "Short"
        ],
        ...
]

The ai_compose_styles key contains an array of tone descriptors.

The tone descriptor is itself an array with three elements, in the specified order:

  • Style ID (string)
  • Custom emoji ID of the style's icon (string, containing a 64-bit signed long decimal integer)
  • Localized, human-readable name of the style (string)

Summarize messages

textWithEntities#751f3146 text:string entities:Vector<MessageEntity> = TextWithEntities;

---functions---

messages.summarizeText#abbbd346 flags:# peer:InputPeer id:int to_lang:flags.0?string tone:flags.2?string = TextWithEntities;

Invoke messages.summarizeText to summarize the contents of the message with AI, privately powered by Cocoon.

Pass the message's ID in id, and the chat where the message is located in peer.

You may choose a custom tone » for the summary, passing the tone identifier to tone.

The summary can additionally be translated by specifying a language code in the to_lang flag.

Chatbot AI features

Telegram bots offer a number of features for AI chatbots: