Hi,
I would like to know if it is possible based on this code, to insert two (or three) Unicode symbols in a text to send to Telegram, a single symbol if it works fine.
Function $tgFunc by @diamuxin
:global tgFunc do={
:local BotToken "XXXXXXXXX:XXXXXXXXXXXX-XXXXXXXXXXXXXXXXXX"
:local ChatID "XXXXXXXXX"
:local parseMode "HTML"
:local SendText $1
:local DisableWebPagePreview True
/tool fetch url="[https://api.telegram.org/bot$BotToken/sendMessage\?chat_id=](https://api.telegram.org/bot$BotToken/sendMessage%5C?chat_id=)\
$ChatID&parse_mode=$parseMode&text=$SendText&disable_web_page_preview=\
$DisableWebPagePreview" keep-result=no
:log info "=> Send Telegram message"
}
Function $SymbolByUnicodeName by @eworm
:global SymbolByUnicodeName do={
:local Symbols {
"abacus"="\F0\9F\A7\AE";
"alarm-clock"="\E2\8F\B0";
"calendar"="\F0\9F\93\85";
"card-file-box"="\F0\9F\97\83";
"chart-decreasing"="\F0\9F\93\89";
"chart-increasing"="\F0\9F\93\88";
"cloud"="\E2\98\81";
"cross-mark"="\E2\9D\8C";
"earth"="\F0\9F\8C\8D";
"fire"="\F0\9F\94\A5";
"floppy-disk"="\F0\9F\92\BE";
"high-voltage-sign"="\E2\9A\A1";
"incoming-envelope"="\F0\9F\93\A8";
"information"="\E2\84\B9";
"large-orange-circle"="\F0\9F\9F\A0";
"large-red-circle"="\F0\9F\94\B4";
"link"="\F0\9F\94\97";
"lock-with-ink-pen"="\F0\9F\94\8F";
"memo"="\F0\9F\93\9D";
"mobile-phone"="\F0\9F\93\B1";
"pushpin"="\F0\9F\93\8C";
"scissors"="\E2\9C\82";
"sparkles"="\E2\9C\A8";
"speech-balloon"="\F0\9F\92\AC";
"up-arrow"="\E2\AC\86";
"warning-sign"="\E2\9A\A0";
"white-heavy-check-mark"="\E2\9C\85"
}
:return (($Symbols->$1) . "\EF\B8\8F");
}
Telegram Test
{
:global tgFunc
:global SymbolByUnicodeName
$tgFunc ("$[$SymbolByUnicodeName "calendar"] Telegram Test") ; # send OK
$tgFunc ("$[$SymbolByUnicodeName "calendar,memo"] Telegram Test") ; # Not OK
}
Sertik
December 5, 2023, 5:47am
2
:return (($Symbols->$1) . "\EF\B8\8F");
If desired, you can return as many characters as you want from your array:
:return (($Symbols->$1) . ($Symbols->$2). ($Symbols->$3). "\EF\B8\8F");
If $2 and $3 are not specified, they simply will not be refunded
$tgFunc (“$[$SymbolByUnicodeName “calendar” “memo”] Telegram Test”) ; # OK too!
Amm0
December 5, 2023, 6:07am
3
You can also modify @eworm ’s code to convert $1 to an array & then loop on the array to lookup the emoji:
# Function $SymbolByUnicodeName by @eworm
:global SymbolByUnicodeName do={
:local Symbols {
"abacus"="\F0\9F\A7\AE";
"alarm-clock"="\E2\8F\B0";
"calendar"="\F0\9F\93\85";
"card-file-box"="\F0\9F\97\83";
"chart-decreasing"="\F0\9F\93\89";
"chart-increasing"="\F0\9F\93\88";
"cloud"="\E2\98\81";
"cross-mark"="\E2\9D\8C";
"earth"="\F0\9F\8C\8D";
"fire"="\F0\9F\94\A5";
"floppy-disk"="\F0\9F\92\BE";
"high-voltage-sign"="\E2\9A\A1";
"incoming-envelope"="\F0\9F\93\A8";
"information"="\E2\84\B9";
"large-orange-circle"="\F0\9F\9F\A0";
"large-red-circle"="\F0\9F\94\B4";
"link"="\F0\9F\94\97";
"lock-with-ink-pen"="\F0\9F\94\8F";
"memo"="\F0\9F\93\9D";
"mobile-phone"="\F0\9F\93\B1";
"pushpin"="\F0\9F\93\8C";
"scissors"="\E2\9C\82";
"sparkles"="\E2\9C\A8";
"speech-balloon"="\F0\9F\92\AC";
"up-arrow"="\E2\AC\86";
"warning-sign"="\E2\9A\A0";
"white-heavy-check-mark"="\E2\9C\85"
}
:local symnames [:toarray $1]
:local retval ""
:foreach symname in=$symnames do={
:set retval ($retval . ($Symbols->$symname))
}
:return ($retval . "\EF\B8\8F");
}
Note: the “foreach” will work same if only one is provided, since the “toarray” will contain one element.
Thank you very much Sertik and Amm0 for your help.
By the way Amm0, your site is very useful:
https://observablehq.com/@a2m0/utf2rsc#decodeStart
BR.
eworm
December 6, 2023, 4:58pm
5
Instead of stealing just one function you could use all of them as expected…
So if you install my scripts and configure Telegram as expected this gives exactly what you want:
$SendTelegram ([ $SymbolForNotification "calendar,memo" ] . "Telegram Test") "Message...";