Community discussions

MikroTik App
 
User avatar
diamuxin
Member
Member
Topic Author
Posts: 311
Joined: Thu Sep 09, 2021 5:46 pm

Send a unicode symbol to Telegram from an array list

Tue Dec 05, 2023 1:03 am

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.

example code

# 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/s ... \?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
}
 
User avatar
Sertik
Member
Member
Posts: 420
Joined: Fri Sep 25, 2020 3:30 pm
Location: Russia, Moscow

Re: Send a unicode symbol to Telegram from an array list

Tue Dec 05, 2023 7:47 am

: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!
Last edited by Sertik on Tue Dec 05, 2023 8:31 am, edited 2 times in total.
 
User avatar
Amm0
Forum Guru
Forum Guru
Posts: 3018
Joined: Sun May 01, 2016 7:12 pm
Location: California

Re: Send a unicode symbol to Telegram from an array list

Tue Dec 05, 2023 8:07 am

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.
 
User avatar
diamuxin
Member
Member
Topic Author
Posts: 311
Joined: Thu Sep 09, 2021 5:46 pm

Re: Send a unicode symbol to Telegram from an array list

Tue Dec 05, 2023 2:02 pm

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.
 
User avatar
eworm
Forum Guru
Forum Guru
Posts: 1067
Joined: Wed Oct 22, 2014 9:23 am
Location: Oberhausen, Germany
Contact:

Re: Send a unicode symbol to Telegram from an array list

Wed Dec 06, 2023 6:58 pm

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...";

Who is online

Users browsing this forum: No registered users and 6 guests