Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to send Emoji with Telegram Bot API?

I need to send messages containing emoji with my Telegram Bot.

So I copy/paste emoji code :nine: for example, in my message text and send it to a user, BUT emoji didn`t work.

This is my sample code and function:

function tel_send($key, $t, $c)
{
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, "https://api.telegram.org/bot" . $key . "/sendMessage");
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_POST, true);
    curl_setopt($ch, CURLOPT_POSTFIELDS, "cache=" . (time() / rand(1, time() - 100)) . "&text=" . $t . "&chat_id=" . $c);
    $ss = curl_exec($ch);
    curl_close($ch);
    return $ss;
}
tel_send($key, "My number - :nine:", $val['message']['chat']['id']);

So, my question is: How can I send emoji by Telegram bot?

like image 908
Vlmake Avatar asked Jul 15 '15 12:07

Vlmake


People also ask

How do you send Emojis in API?

inside your onNotificationProcessing method(For emoji in notification body, use setContentText). Send notification with emoji replaced with Unicode. Also, add <emoji> before and after your Unicode(this is to identify emoji inside the application).

How do you send Emojis on Telegram?

Go to Chat Settings and scroll down to Quick Reaction. In there, you'll find a list of emoji available for use. Select the one you want.

Can Telegram BOT send pictures?

Photo to send. Pass a file_id as String to send a photo that exists on the Telegram servers (recommended), pass an HTTP URL as a String for Telegram to get a photo from the Internet, or upload a local photo by passing a file path.

Can a telegram BOT send message to user?

It is only possible to send messages to users whom have already used /start on your bot. When they start your bot, you can find update. message.


2 Answers

I faced the same issue a few days ago.. The solution is to use Bytes (UTF-8) notation from this table: http://apps.timwhitlock.info/emoji/tables/unicode

examples:

😁 \xF0\x9F\x98\x81 GRINNING FACE WITH SMILING EYES

😉 \xF0\x9F\x98\x89 WINKING FACE

like image 58
codeWhisperer Avatar answered Sep 24 '22 10:09

codeWhisperer


you need to specify emoji's unicode value.

check here

these are returned by a function as emoji value like u'\U000026C4' which is snowman. although it is in python, you can apply it for php.

like image 42
Mustafa Avatar answered Sep 21 '22 10:09

Mustafa