I'm trying to send an emoji/emoticon to my Telegram bot using a bash script. This bash script calls the Telegram API as follows:
curl -s -X POST 'https://api.telegram.org/'$API'/sendMessage' -F chat_id=$chat -F text=$text
Since the bash script isn't unicode, I cannot simply copy/paste the emojis from the web. Therefore I tried using the UTF-8 emoji variants, but the backslash character keeps getting escaped.
The expected json output should be as follows: "text":"\ud83d\udd14"
Instead, this is what I get:
Input: $text = \xF0\x9F\x98\x81
JSON Output = "text":"\\xF0\\x9F\\x98\\x81\\"
Input: $text = u'\U0001F604'
JSON Output = "text": "u'\\U0001F604'\"
Input: $text = \U0001F514
JSON Output = "text":"\\U0001F514"
Input: $text = "(1f600)"
JSON Output = "text":"\"(1f600)\""
Input: $text = \ud83d\ude08
JSON Output = "text":"\\ud83d\\ude08"
Input: $text = \\\ud83d\\\udd14
JSON Output = "text":"\\\\\\ud83d\\\\\\udd14"
What is the correct syntax to send an emoji using a bash script and curl to my Telegram bot?
Thank you very much!
jq
, figure out how to encode your string. – Crowell