Search code examples
utf-8telegramemoji

Example for App Script Send Emoji in Telegram


I'm trying to send an emoji to a ChatBot, taking inspiration from the emoji code table that I found on the page http://apps.timwhitlock.info/emoji/tables/unicode...

But I have the problem that when I send the message the code is read as a string...

Can you please have an example of how to write the string in such a way that it is recognized when it is passed to the following method:

function sendMessage(idChat, text)
{
   var date =
   {
     method: "post",
     payload: {
       method: "sendMessage",
       chat_id: String(Chatid),
       text: text,
       parse_mode: "HTML",

     }
   };

   UrlFetchApp.fetch("https://api.telegram.org/bot" +
                       tokens +
                       "/",
                     date);
}

with

sendMessage(idChat, "\xF0\x9F\x98\x81")

or

sendMessage(idChat, "uU0001F4A8")

with

sendMessage(idChat, "U+1f601")

the result was that the codes were only recognized as strings


Solution

  • I think it is better to use emoji itself instead of using the code. Like this:

    sendMessage(idChat, "😁")
    

    Using the actual emoji in the code makes it more readable and straightforward. And also, using Unicode codes (like U+1f601) might not be interpreted as emojis by telegram.