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?
15
Answers
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.
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:
😁 xF0x9Fx98x81 GRINNING FACE WITH SMILING EYES
😉 xF0x9Fx98x89 WINKING FACE
An addition to this answer https://stackoverflow.com/a/31431810/1114926.
The link that Mustafa provided doesn’t represent all emoji. This source is better http://emojipedia.org/ ☝️. It has variations of emoji in addition to the major sign.
Real solution is to use https://github.com/spatie/emoji (
composer require spatie/emoji
) for Emoji codes. Now your code will look likeor
This is something you could really use. Unlike writing all the codes manually and having hard time understanding what is it on the first glance.
See emojis and their UTF-8 codes here:
http://apps.timwhitlock.info/emoji/tables/unicode
Then you must convert UTF-8 codes to Telegram-ready response text with the following code:
I have been looking for an answer for this for a long time, but could not get it working. my scripting skills are poor and converting php answers to bash proved a challenge.
But, nonetheless I got it working with a most simple solution:
I went to telegram desktop messenger, there i send the required emoji (🚌).
Than I made a variable: bus=”🚌”
Now I can use the variable in the curl as: “text=some text $bus”
This works great using bash on linux, I suppose it could also work in php.
I am using this code at linux bash and curl command for grinning face
Just another choice
$curl …. -F text=”😁″ -F parse_mode=html …. “https://api.telegram.org/botTOKEN/sendMessage“
will enable parse_mode to html and use HTML hexadecimal (hex) reference(😁) for unicode U+1F601
You can just copy emojy from telegram and paste in text to send like 🏠
another way you can use the name of shap ,for example for home you can use
:house:
example:
Easiest way is to just copy and past the emoji you need in your code.
But then you will have to make sure your source code files are stored UTF8
I just opened Telegram on my system and copied the ones I needed and never looked back 🙂 Funny thing is that I do not have to work with constants, specific names
or the unicode character value. I can directly see what emoji is used IN MY EDITOR.
If you process that into a message (example above is PHP, but I guess it will work in any programming language)
> PHP 7
You just to use the
u
and the unicode literal like following:😀
Resource: https://stackoverflow.com/a/33548423/8760592
Note that, at least with JavaScript/Node.js, you can just paste the emoticon’s directly into the code and they translate find into the Telegram API. EG. 😎
You need to json_decode unicode value first, try like this.
IMPORTANT THING:
No one said it.
You have to use double quote, not single ones.
Code below will give you just text:
xF0x9Fx98x822021-11-21 09:54:25
But with double quotes you’ll get emoji:
to get smileys and emojis.. you can always reference this emoji documentation for DEVs
https://carpedm20.github.io/emoji/