telegram-botemojitelegraf

How to send custom emoji from Bot in Telegram


I'm trying to send the custom_emoji through Telegram API using MessageEntity object.

Here is how I've tried to do it:

const message = '🚀'
ctx.sendMessage({
  text: message,
  entities: [{
    type: 'custom_emoji',
    length: message.length,
    offset: 0,
    custom_emoji_id: '5389102131527556772'
  }]
})

p.s. I'm using Telegraf TS, but it doesn't matter since it's just a basic function


Solution

  • Telegram finally published more detailed doc covering this moment: https://core.telegram.org/bots/api#markdownv2-style

    Custom emoji entities can only be used by bots that purchased additional usernames on Fragment.

    MarkdownV2 style

    ![👍](tg://emoji?id=5368324170671202286)
    

    HTML style

    <tg-emoji emoji-id="5368324170671202286">👍</tg-emoji>
    

    The documentation is a bit vague. So will explain how I get it:

    1. You need to make one time purchase with 5k TON, to allow your bot to attach custom usernames.
    2. Attach one of the usernames you own through fragment.com
    3. Sending custom emoji should be available from now on More details you can find on Fragment FAQ

    p.s. Custom emoji id could be found in web.telegram.org through inspector: customEmojiId in Telegram Web version