How to send emoji emoticons through Telegram API?
In the official documentation not a word about emoticons. Somewhere they write that you need to send a UTF-8
emoticon code. ... but to no avail
U+1F601 U1F601 #1F601; F601; \xF0\x9F\x98\x81
How to send emoji emoticons through Telegram API?
In the official documentation not a word about emoticons. Somewhere they write that you need to send a UTF-8
emoticon code. ... but to no avail
U+1F601 U1F601 #1F601; F601; \xF0\x9F\x98\x81
Look at Emoji Unicode Tables .
The emoticon code you need is in the Bytes (UTF-8)
column Bytes (UTF-8)
.
Before sending to the server, you must execute the URL Encode.
For example, \xF0\x9F\x98\x81
should look like this: %F0%9F%98%81
.
I just copied the emoji from the table above with the usual mouse selection (as text is selected) from the "Native" column like this: ๐
I am writing a bot on C #, it works in this form "\U0001F69A"
for the U+1F69A
from the table.
On bash, I use this resource to get the code
The string "C / C ++ / Java source code" displays the required encoding. The request takes the form
/usr/local/bin/curl -s --header 'Content-Type: application/json' --request 'POST' --data "{\"chat_id\":\"-432111111\",\"text\":\"\uD83D\uDC4C - Here is OK emoji\"}" "https://api.telegram.org/bot<TOKEN>/sendMessage"
where \uD83D\uDE31
is the coded symbol ๐
For PHP where there is a smile:
hex2bin('f09f9880')<br> f09f9880
- Smiley code without \ั
from here (column Bytes (UTF-8)
)
Use tools to present Unicode text in your environment. She will perform the conversion from text to octets according to the utf-8 encoding, and then perform percent-encoding . For example, to send the flag, which consists of the Unicode characters U + 1f1f7 , U + 1f1fa to restclient in Emacs :
POST https://api.telegram.org/bot:token/sendMessage Content-type: application/x-www-form-urlencoded chat_id=:chat-id&text=ััะฐ ๐ท๐บ!
This performs an http POST request at the specified url (bot identified by :token
sends a ััะฐ ๐ท๐บ!
message ััะฐ ๐ท๐บ!
:chat-id
chat).
On Python it might look like:
import requests requests.post(f'https://api.telegram.org/bot{token}/sendMessage', dict(chat_id=chat_id, text='ััะฐ ๐ท๐บ!'))
It is seen that there is no need to manually encode the string in the ascii representation:
'\u0443\u0440\u0430 \U0001f1f7\U0001f1fa!'
Python automatically encodes the message. On the server goes (encrypted using TLS), something like:
POST /bot<token>/sendMessage HTTP/1.1 Host: api.telegram.org User-Agent: python-requests/2.18.4 Accept-Encoding: gzip, deflate Accept: */* Connection: keep-alive Content-Length: 69 Content-Type: application/x-www-form-urlencoded chat_id=<chat-id>&text=%D1%83%D1%80%D0%B0+%F0%9F%87%B7%F0%9F%87%BA%21
Source: https://ru.stackoverflow.com/questions/497325/
All Articles
\xF0\x9F\x98\x81
- VenZell%F0%9F%98%81
- VenZell