функция чтения SMS из PDU LTE модемов с пересылкой в чатбот Телеграмм
Добавлено: 26 мар 2023, 12:17
Представляю функцию поиска СМС в PDU всех LTE-модемов или выбранного LTE-модема и пересылкой в
чатбот пользователя Телеграм. Для ppp-модемов делать не стал, благо не пользую уже, но тоже возможно.
Возможна как транслитерация русскоязычных SMS так и пересылка SMS-сообщений на русском языке
Возможен выбор PDU - только из памяти SIM-карты или из SIM и памяти модема
Для корректной работы интерфейсы LTE должны иметь имена, присваеваемые РоутерОС по умолчанию (lteX) и не переименованные !
Примеры использования:
перед использование задать:
:global botID - API токен пользователя Телеграмм
:global myChatID - ID чата пользователя
:global Emoji - Эмоджи роутера в UTF8 для быстрого визуального "опознавания" роутера в чате (по желанию)
вызов функции (возможен без параметров и с переменным числом позиционных параметров):
[$FuncSmsResend] - чтение SMS из PDU всех LTE-модемов роутера и пересылка в чатбот пользователя Телеграм
русскоязычные SMS передаются на русском языке
[$FuncSmsResend translite MT] - чтение SMS всех LTE-модемов как с СИМ-карт, так и из памяти и передача
в чат в транслите
[$FuncSmsResend LTE2] - чтение SMS только LTE2-модема и передача в Телеграмм без транслита (русское на русском)
[$FuncSmsResend LTE1 russian SM] - чтение SMS модема LTE1, СМС только с СИМ-карты, передача на русском.
Функция работает именно с PDU модема/ов, SMS в /tool sms inbox не обрабатываются и не удаляются !
Остальное - в комментариях скрипта.
Для пересылки СМС на русском языке необходима функция FuncTelegramSender (также приведена ниже).
Проверял на модемах Микротик, всё работает как надо. Проверяйте, кому нужно, может какой косячок вылезет, поправлю.
чатбот пользователя Телеграм. Для ppp-модемов делать не стал, благо не пользую уже, но тоже возможно.
Возможна как транслитерация русскоязычных SMS так и пересылка SMS-сообщений на русском языке
Возможен выбор PDU - только из памяти SIM-карты или из SIM и памяти модема
Для корректной работы интерфейсы LTE должны иметь имена, присваеваемые РоутерОС по умолчанию (lteX) и не переименованные !
Примеры использования:
перед использование задать:
:global botID - API токен пользователя Телеграмм
:global myChatID - ID чата пользователя
:global Emoji - Эмоджи роутера в UTF8 для быстрого визуального "опознавания" роутера в чате (по желанию)
вызов функции (возможен без параметров и с переменным числом позиционных параметров):
[$FuncSmsResend] - чтение SMS из PDU всех LTE-модемов роутера и пересылка в чатбот пользователя Телеграм
русскоязычные SMS передаются на русском языке
[$FuncSmsResend translite MT] - чтение SMS всех LTE-модемов как с СИМ-карт, так и из памяти и передача
в чат в транслите
[$FuncSmsResend LTE2] - чтение SMS только LTE2-модема и передача в Телеграмм без транслита (русское на русском)
[$FuncSmsResend LTE1 russian SM] - чтение SMS модема LTE1, СМС только с СИМ-карты, передача на русском.
Функция работает именно с PDU модема/ов, SMS в /tool sms inbox не обрабатываются и не удаляются !
Остальное - в комментариях скрипта.
Для пересылки СМС на русском языке необходима функция FuncTelegramSender (также приведена ниже).
Код: Выделить всё
#----------------------------------------------------------
# FuncSmsResend 24.03.2023
#----------------------------------------------------------
# Андрей Радоманов - основной скрипт чтения SMS из PDU модема
# Sertik - функция из скрипта
# SergeyN - идея и реализация возможности передачи SMS на русском языке
#
# поиск СМС в PDU всех LTE-модемов или выбранного LTE и пересылка в
# чатбот пользователя Телеграм
# скрипт не умееет объединять SMS, если одно SMS разбито в PDU на два и более
# передаёт части SMS как отдельные SMS
# для передачи SMS на русском языке используется функция Sertik FuncTelegramSender
# если она не установлена в global скрипт может работать только в режиме транслитерации SMS
# usage: set global botID - Telegram bot API token
# set global myChatID - user`s chat ID
# set global Emoji - Router`s Emoji for Telegram (optional)
# [$FuncSmsResend] - full read PDU LTE modems and resend to Telegram chat
# [$FuncSmsResend translite/russian MT/SM] - choice latin translite or russian text and choice SMS-storage SM (SIM-card) or MT (all pzu SIM & phone)
# [$FuncSmsResend LTEx translite/russian MT/SM] - + choice modem (LTE1 or LTE2)
:global FuncSmsResend do={
:global Emoji
:global botID; :if (!any $botID) do={:log error "ERROR $0: Not set botID"; :return "Error $0: Not set botID"}
:global myChatID; :if (!any $myChatID) do={:log error "ERROR: $0 Not set chatID"; :return "Error $0: Not set chatID"}
:global FuncTelegramSender; if (!any $FuncTelegramSender) do={:log error "$0 Not set global function FuncTelegramSender. Working in limited functionality mode (translit only)"}
:local CLTE 0
:local CLTEs 1
:local CLTEx
:foreach i in=[/interface lte find] do={:set CLTE ($CLTE+1)}
:if ($CLTE=0) do={:log error "function $0 informs: Not LTE modem"; :return "Error $0: Not LTE modem"}
:if ($1="LTE1") do={:set CLTEs 1; :set CLTE 1}
:if (($1="LTE2") && ($CLTE=2)) do={:set CLTEs 2}
for x from=$CLTEs to=$CLTE do={
:set CLTEx ("lte"."$[:tostr $x]")
# :log warning $CLTEx
# main body script SMS decoder
:local autodelete 1;
:local smsArray ({});
:local inboxCursor 0;
:local inboxCount 0;
/interface lte at-chat $CLTEx input="AT+CMGF=0";
:local res
:if (([:len $3]>0) and ($3="MT")) do={
:set res [/interface lte at-chat $CLTEx input="AT+CPMS=\"MT\"" as-value wait=yes];}
:if (([:len $3]=0) and ($2="MT")) do={
:set res [/interface lte at-chat $CLTEx input="AT+CPMS=\"MT\"" as-value wait=yes];}
:if (([:len $3]>0) and ($3="SM")) do={
:set res [/interface lte at-chat $CLTEx input="AT+CPMS=\"SM\"" as-value wait=yes];}
:if (([:len $3]=0) and ($2="SM")) do={
:set res [/interface lte at-chat $CLTEx input="AT+CPMS=\"SM\"" as-value wait=yes];}
:if ([:len $2]=0) do={:set res [/interface lte at-chat $CLTEx input="AT+CPMS=\"MT\"" as-value wait=yes];}
:set res ($res->"output");
:if ([:typeof [:find $res "+CPMS: "]] = "num") do={
:set inboxCount [:tonum [:pick $res ([:find $res "+CPMS: "]+7) ([:find $res ","])]];
:put "SMS Inbox count: $inboxCount";
};
:if ($inboxCount>0) do={
:local symbols {"-";" ";" ";"!";"\"";"#";"\$";"%";"&";"'";"(";")";"*";"+";",";"-";".";"/";"0";"1";"2";"3";"4";"5";"6";"7";"8";"9";":";";";"<";"=";">";"?";"@";"A";"B";"C";"D";"E";"F";"G";"H";"I";"J";"K";"L";"M";"N";"O";"P";"Q";"R";"S";"T";"U";"V";"W";"X";"Y";"Z";"[";"\\";"]";"^";"_";"`";"a";"b";"c";"d";"e";"f";"g";"h";"i";"j";"k";"l";"m";"n";"o";"p";"q";"r";"s";"t";"u";"v";"w";"x";"y";"z";"{";"|";"}";"~","\"","\""};
:local symbolsUTF [:toarray "2013,000A,0020,0021,0022,0023,0024,0025,0026,0027,0028,0029,002A,002B,002C,002D,002E,002F,0030,0031,0032,0033,0034,0035,0036,0037,0038,0039,003A,003B,003C,003D,003E,003F,0040,0041,0042,0043,0044,0045,0046,0047,0048,0049,004A,004B,004C,004D,004E,004F,0050,0051,0052,0053,0054,0055,0056,0057,0058,0059,005A,005B,005C,005D,005E,005F,0060,0061,0062,0063,0064,0065,0066,0067,0068,0069,006A,006B,006C,006D,006E,006F,0070,0071,0072,0073,0074,0075,0076,0077,0078,0079,007A,007B,007C,007D,007E,00AB,00BB"];
:local symbolsRus
:if (($1="translite") or ($2="translite")) do={
:set symbolsRus [:toarray "A,B,V,G,D,E,Yo,Zh,Z,I,Y,K,L,M,N,O,P,R,S,T,U,F,Kh,C,Ch,Sh,Sch,',I,',E,Yu,Ya,a,b,v,g,d,e,yo,zh,z,i,y,k,l,m,n,o,p,r,s,t,u,f,kh,c,ch,sh,sch,',i,',e,yu,ya,_,!,_,_,_,%,&,',(,),*,+,_,-,.,/,0,1,2,3,4,5,6,7,8,9"];}
:if (([:len $1]=0) or ($1="russian") or ([:len $2]=0) or ($2="russian")) do={
:set symbolsRus [:toarray "А,Б,В,Г,Д,Е,Ё,Ж,З,И,Й,К,Л,М,Н,О,П,Р,С,Т,У,Ф,Х,Ц,Ч,Ш,Щ,Ъ,Ы,Ь,Э,Ю,Я,а,б,в,г,д,е,ё,ж,з,и,й,к,л,м,н,о,п,р,с,т,у,ф,х,ц,ч,ш,щ,ъ,ы,ь,э,ю,я,_,!,_,_,_,%,&,',(,),*,+,_,-,.,/,0,1,2,3,4,5,6,7,8,9"];}
:local symbolsRusUTF [:toarray "0410,0411,0412,0413,0414,0415,0401,0416,0417,0418,0419,041A,041B,041C,041D,041E,041F,0420,0421,0422,0423,0424,0425,0426,0427,0428,0429,042A,042B,042C,042D,042E,042F,0430,0431,0432,0433,0434,0435,0451,0436,0437,0438,0439,043A,043B,043C,043D,043E,043F,0440,0441,0442,0443,0444,0445,0446,0447,0448,0449,044A,044B,044C,044D,044E,044F"];
:local hexstr "0123456789ABCDEF";
:local ascii " !\"#\$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~";
:while ($inboxCursor < $inboxCount) do={
:set inboxCursor ($inboxCursor+1);
:local sms [/interface lte at-chat $CLTEx input="AT+CMGR=$inboxCursor" as-value wait=yes];
:set sms ($sms->"output");
#:put ("inbox $inboxCursor:'".$sms."'\n");
:if (( [:typeof [:find $sms "+CMGR"]] != "nil" ) and ([:typeof [:find $sms "\n"]] != "nil")) do={
:set sms [:pick $sms ([:find $sms "+CMGR"]+1) ([:len $sms]+1)];
:local lineStart ([:find $sms "\n"]+1);
:local lineEnd [:find $sms "\nOK" $lineStart] ;
:if ([:typeof $lineEnd] = "nil") do={
:set lineEnd ([:len $sms]+1);
}
:set sms [:pick $sms $lineStart $lineEnd];
#Removes unesessary \r\n at the end of lines
:if ([:pick $sms ([:len $sms]-1)] = "\n") do={
:set sms [:pick $sms 0 ([:len $sms]-1)];
}
:if ([:pick $sms ([:len $sms]-1)] = "\r") do={
:set sms [:pick $sms 0 ([:len $sms]-1)];
}
:if ([:pick $sms ([:len $sms]-1)] = "\n") do={
:set sms [:pick $sms 0 ([:len $sms]-1)];
}
:if ([:pick $sms ([:len $sms]-1)] = "\r") do={
:set sms [:pick $sms 0 ([:len $sms]-1)];
}
#:put ("sms-raw $inboxCursor:'".$sms."'\n");
:local i;
:if ([:len $sms]>8) do={
:local pduEnd 0;
:local smsLen [:len $sms];
:local pduPartNum 1;
:local curPos 0;
:local smsTS;
:local smsFrom;
:local smsNum "0000";
:local dcs "00";
:while (($pduPartNum < 8) and ($curPos < $smsLen)) do={
:local pduPartLen;
:if ($pduPartNum = 1) do={ #SCA - Service Center Address
:set pduPartLen 14;
:if (([:pick $sms $curPos ($curPos+2)])!="91") do={
:put "first two bytes is not 91, skipping...";
:set pduPartLen ($pduPartLen+2);
}
}
:if ($pduPartNum = 2) do={
:set pduPartLen 2;
}
:if ($pduPartNum = 3) do={
:local tmpHex1 [:pick $sms $curPos ($curPos+1)]
:local tmpHex2 [:pick $sms ($curPos+1) ($curPos+2)]
:local fromLen;
:set pduPartLen 0;
:if ([:typeof [:find $hexstr $tmpHex1]] = "num") do={
:set fromLen ([:find $hexstr $tmpHex1] * 16);
}
:if ([:typeof [:find $hexstr $tmpHex2]] = "num") do={
:set fromLen ([:find $hexstr $tmpHex2]+$fromLen);
}
if ( [:pick [:tostr (($fromLen*10)/2)] ([:len [:tostr (($fromLen*10)/2)]]-1) [:len [:tostr (($fromLen*10)/2)]]] = "5") do={
:set pduPartLen ($fromLen+1);
} else={
:set pduPartLen $fromLen;
}
:set pduPartLen ($pduPartLen+4);
if (([:pick $sms ($curPos+2) ($curPos+4)]="91") or ([:pick $sms ($curPos+2) ($curPos+4)]="81")) do={
:set smsFrom "+";
:for i from=0 to=($fromLen-1) do={
if ( [:pick [:tostr (($i*10)/2)] ([:len [:tostr (($i*10)/2)]]-1) [:len [:tostr (($i*10)/2)]]] = "5") do={
:set smsFrom ($smsFrom.[:pick $sms ($curPos+4+$i-1)]);
} else {
:set smsFrom ($smsFrom.[:pick $sms ($curPos+4+$i+1)]);
}
}
} else={
:set smsFrom [:pick $sms ($curPos+2) ($curPos+$pduPartLen)];
:if ([:pick $smsFrom 0 2] = "D0") do={
:set smsFrom [:pick $smsFrom 2 [:len $smsFrom]];
:local curbit 0;
:local nextpart 0;
:local smsDecoded "";
:for i from=0 to=([:len $smsFrom]-1) step=2 do={
:local tmp [:pick $smsFrom $i];
:local charcode ([:find "0123456789ABCDEF" $tmp]*16);
:set tmp [:pick $smsFrom ($i+1)];
:set charcode ($charcode+[:find "0123456789ABCDEF" $tmp]);
:if ($curbit<7) do={
:set tmp ($charcode & (127>>$curbit));
:set tmp ($tmp<<$curbit);
:set tmp ($tmp + $nextpart);
:set nextpart ($charcode>>(7-$curbit));
:set curbit ($curbit+1);
}
:set smsDecoded ($smsDecoded.[:pick $ascii ($tmp-32)]);
:if ($curbit=7) do={
:set tmp $nextpart;
:set curbit 0;
:set nextpart 0;
:set smsDecoded ($smsDecoded.[:pick $ascii ($tmp-32)]);
}
}
:set smsFrom $smsDecoded;
}
}
#:put ("FROM: ".$smsFrom);
}
:if ($pduPartNum = 4) do={ #PID - Protocol Identifier
:set pduPartLen 2;
}
:if ($pduPartNum = 5) do={ #DCS - Data Coding Scheme
:set pduPartLen 2;
:set dcs [:pick $sms $curPos ($curPos+2)];
}
:if ($pduPartNum = 6) do={ #SCTS - Service Centre Time Stamp
:set pduPartLen 14;
:set smsTS "20";
:for i from=0 to=11 do={
if ( [:pick [:tostr (($i*10)/2)] ([:len [:tostr (($i*10)/2)]]-1) [:len [:tostr (($i*10)/2)]]] = "5") do={
:set smsTS ($smsTS.[:pick $sms ($curPos+$i-1)]);
} else {
:set smsTS ($smsTS.[:pick $sms ($curPos+$i+1)]);
}
}
}
:if ($pduPartNum = 7) do={ #UDL - User Data Length
:set pduPartLen 2;
}
:if ($pduPartLen = 0) do={
#:put ("could not detect Pdu len for part:".$pduPartNum);
:set pduPartLen 2;
}
#:put ("PDU PART ".$pduPartNum.": ".[:pick $sms $curPos ($curPos+$pduPartLen)]);
:set curPos ($curPos+$pduPartLen);
:set pduPartNum ($pduPartNum+1);
:set pduEnd $curPos;
}
#:log info ("PDU END: ".$pduEnd);
:if ($pduEnd = 0) do={
:log error ("Unable to find end of PDU in the next message: ".[:pick $sms 0 72]);
:set pduEnd 58;
}
#:put ("PDU:".[:pick $sms 0 $pduEnd]);
:set sms [:pick $sms $pduEnd [:len $sms]];
:local udh [:pick $sms 0 2];
:if ($udh = "05") do={
#:put ("UDH: ".[:pick $sms 0 12]);
:set smsNum ([:pick $sms 6 8].[:pick $sms 10 12]);
:set sms [:pick $sms 12 [:len $sms]];
}
:if ($dcs = "08") do={
:local decodedSMS "";
:for i from=0 to=([:len $sms]-1) step=4 do={
:local char [:pick $sms $i ($i+4)];
:local ind [:find $symbolsRusUTF $char];
:if ([:typeof $ind]="num") do={
:set decodedSMS ($decodedSMS.[:pick $symbolsRus $ind]);
} else={
:set ind [:find $symbolsUTF $char];
:if ([:typeof $ind]="num") do={
:set decodedSMS ($decodedSMS.[:pick $symbols $ind]);
} else={
:if ($char!="\r") do={
:set decodedSMS ($decodedSMS."[".$char."]");
}
}
}
}
:set sms $decodedSMS;
}
:if ($dcs = "00") do={
#:put ("UCS2: ".$sms);
:local curbit 0;
:local nextpart 0;
:local smsDecoded "";
:for i from=0 to=([:len $sms]-1) step=2 do={
:local tmp [:pick $sms $i];
:local charcode ([:find "0123456789ABCDEF" $tmp]*16);
:set tmp [:pick $sms ($i+1)];
:set charcode ($charcode+[:find "0123456789ABCDEF" $tmp]);
:if ($curbit<7) do={
:set tmp ($charcode & (127>>$curbit));
:set tmp ($tmp<<$curbit);
:set tmp ($tmp + $nextpart);
:set nextpart ($charcode>>(7-$curbit));
:set curbit ($curbit+1);
}
:set smsDecoded ($smsDecoded.[:pick $ascii ($tmp-32)]);
:if ($curbit=7) do={
:set tmp $nextpart;
:set curbit 0;
:set nextpart 0;
:set smsDecoded ($smsDecoded.[:pick $ascii ($tmp-32)]);
}
}
:set sms $smsDecoded;
}
#:log info ("SET ".($smsTS.$smsNum)." ".$sms);
:set ($smsArray->($smsTS.$smsFrom.$smsNum)) $sms;
}
}
}
:if ($autodelete=1) do={
:set inboxCursor 0;
:do {
:set inboxCursor ($inboxCursor+1);
/interface lte at-chat $CLTEx input="AT+CMGD=$inboxCursor";
} while ($inboxCursor < $inboxCount);
};
}; #if inboxCount>0
:local buffer ({});
:local CsmsArray [:len $smsArray]
:foreach k,v in=$smsArray do={
:local smsId [:pick $k 0 ([:len $k]-4)];
:local smsFrom [:pick $k 0 ([:len $k]-4)];
:set ($buffer->$smsId) ($buffer->$smsId . $v);
:set ($smsArray->$k);
}
:foreach k,v in=$buffer do={
:local smsFrom [:pick $k 14 [:len $k]];
:local sysName [/system identity get name];
:local datePrefix ("[".[:pick $k 6 8].".".[:pick $k 4 6].".".[:pick $k 0 4]." ".[:pick $k 8 10].":".[:pick $k 10 12].":".[:pick $k 12 14]."]");
:log warning ($datePrefix." SMS from $CLTEx ".$smsFrom.": ".$v);
:put ($sysName." ". $datePrefix . " SMS from " . $smsFrom . ": ". $v . "\n");
:local smsContent ("$Emoji"."SMS $sysName $CLTEx $datePrefix $smsFrom >> $v");
:if (any $FuncTelegramSender) do={
do {
:if (($1!="translite") or ($2!="translite")) do={
[$FuncTelegramSender $smsContent]}
} on-error={:log error "ERROR $0 couldn't forward SMS to Telegram"}
} else={
do {
/tool fetch url="https://api.telegram.org/$botID/sendmessage\?chat_id=$myChatID&text=$smsContent" keep-result=no;
} on-error={:log error "ERROR $0 couldn't forward SMS to Telegram"}
}
:set ($buffer->$k);
}
:if ($CsmsArray>0) do={:log warning "Done: $CsmsArray SMS resend"} else={:log error "no unsent SMS on $CLTEx"}
:return "Done"}
}
Код: Выделить всё
#------------------------------------------------------------------------------------------------------------
# Функция перекодировки и пересылки сообщений на
# русском и английском языках в мессенджер Телеграмм
# by Sertik версия 16.10.2021
#-----------------------------------------------------------------------------------------------------------
#
# usage [$FuncTelegramSender "text message" "style"]
# style ="html" or "markdown" or "markdownV2" or nothing
#
# Examles:
#
# [$FuncTelegramSender ("$[/system resource get version]"."%0A"."Ros version")]
# [$FuncTelegramSender ("<b>"."$[/system resource get version]"."</b>"."%0A"."Ros version") "html"]
# <b> жирный </b>
# <i> курсив </i>
# <u> подчеркивание </u>
# <s> зачеркнутый </s>
# [$FuncTelegramSender ("*"."$[/system resource get version]"."*"."%0A"."Ros version") "markdown"]
# [$FuncTelegramSender "`text message`" "markdown"] - monospased text
# [$FuncTelegramSender ("[Ссылка на Ваш сайт под катом ](http://example.com/") "markdown"]
#[$FuncTelegramSender "~Сообщение с ошибкой перечеркнуто~" "markdownV2"]
# [$FuncTelegramSender "__Важное сообщение подчеркнуто __" "markdownV2"]
# [$FuncTelegramSender ("text"."\\"."\$"." @!#%'()*+,-./:;<=>?[]^_`{|}~")]
# [$FuncTelegramSender "Для вывода \ $ " необходимо экранирование \$, \\, кавычки не поддерживаются]
:global FuncTelegramSender do={
:if ([:len $0]!=0) do={
:global botID;
:global myChatID;
:local Tstyle
:if ([:len $2]=0) do={} else={:set $Tstyle $2}
:if (($2="html") or ($2="markdown") or ($2="markdownV2") or ([:len $2]=0)) do={
:local string; :set $string $1;
# table of the codes of Russian letters UTF8 + some characters are not supported by Telegram
:local rsimv [:toarray {"А"="D090"; "Б"="D091"; "В"="D092"; "Г"="D093"; "Д"="D094"; "Е"="D095"; "Ж"="D096"; "З"="D097"; "И"="D098"; "Й"="D099"; "К"="D09A"; "Л"="D09B"; "М"="D09C"; "Н"="D09D"; "О"="D09E"; "П"="D09F"; "Р"="D0A0"; "С"="D0A1"; "Т"="D0A2"; "У"="D0A3"; "Ф"="D0A4"; "Х"="D0A5"; "Ц"="D0A6"; "Ч"="D0A7"; "Ш"="D0A8"; "Щ"="D0A9"; "Ъ"="D0AA"; "Ы"="D0AB"; "Ь"="D0AC"; "Э"="D0AD"; "Ю"="D0AE"; "Я"="D0AF"; "а"="D0B0"; "б"="D0B1"; "в"="D0B2"; "г"="D0B3"; "д"="D0B4"; "е"="D0B5"; "ж"="D0B6"; "з"="D0B7"; "и"="D0B8"; "й"="D0B9"; "к"="D0BA"; "л"="D0BB"; "м"="D0BC"; "н"="D0BD"; "о"="D0BE"; "п"="D0BF"; "р"="D180"; "с"="D181"; "т"="D182"; "у"="D183"; "ф"="D184"; "х"="D185"; "ц"="D186"; "ч"="D187"; "ш"="D188"; "щ"="D189"; "ъ"="D18A"; "ы"="D18B"; "ь"="D18C"; "э"="D18D"; "ю"="D18E"; "я"="D18F"; "Ё"="D001"; "ё"="D191"; "№"="0023"; " "="0020"; "&"="0026"; "`"="0027"; "+"="002B";"["="005B"; "\"="005C"; "]"="005D"; "_"="005F"; "'"="0060"}]
# encoding of the symbols and аssembly line
:local StrTele ""; :local code "";
:for i from=0 to=([:len $string]-1) do={:local keys [:pick $string $i (1+$i)]; :local key ($rsimv->$keys); if ([:len $key]!=0) do={:set $code ("%"."$[:pick ($rsimv->$keys) 0 2]"."%"."$[:pick ($rsimv->$keys) 2 4]");:if ([pick $code 0 3] ="%00") do={:set $code [:pick $code 3 6]}} else={:set $code $keys}; :set $StrTele ("$StrTele"."$code")}
do {
/tool fetch url="https://api.telegram.org/$botID/sendmessage\?chat_id=$myChatID&parse_mode=$Tstyle&text=$StrTele" keep-result=no; :return "Done"
} on-error={:log info; :log error "Error function $0 fetch"; :log info ""; :return "Error fetch"}
} else={:log info; log error "Parametrs function $0 mismatch"; :log info ""; :return "Error parametrs mismatch"}
}
}