Alexander Koryukin me impulit ad hanc exsecutionem
Et commentarium in una e sodalitatum VK a Kirill Kazakov:
Yeah, omnino securum non est. Malim scribere telegraphum automati quod solum activation mandata ex ratione mea accipit.
tali automati scribere decrevi.
Primum igitur facere est telegraphum creare automatum.
- In inquisitione invenimus rationem nomine @botfather
- Click in Satus puga in fundo scrinii
- Deinde scribimus ei mandatum / newbot
Tunc respondemus 2 quaestiones simplices;
- Prima quaestio est nomen bot creatum. MyMikrotikROuter
- Secunda quaestio est cognomen creati (sit terminus bot) MikrotikROuter_bot
Respondentes accipiemus tesseram automatis nostri, in casu meo est:
Hoc signo accedere HTTP API: 265373548:AAFyGCqJCei9mvcxvXOWBfnjSt1p3sX1XH4
Deinde, necesse est ut nostri autocineti in inquisitione nominatim inveniant @MikrotikROuter_boT ac premere Satus puga pyga.
Postea, navigatrum aperire debes et hanc lineam inire:
https://api.telegram.org/botXXXXXXXXXXXXXXXXXX/getUpdates
Ubi XXXXXXXXXXXXXXXXXX Bot tua est signum.
Pagina sequenti aperietur similis:
Textum sequentem invenimus in ea:
"Curabitur":{"id":631290,
Omnes itaque necessariae informationes habemus pro scripto scripto pro Mikrotik, scilicet:
Bot indicium: 265373548:AAFyGCqJCei9mvcxvXOWBfnjSt1p3sX1XH4
Curabitur ID ubi scribat: 631290
Sisto, per navigatrum possumus ire:
https://api.telegram.org/bot265373548:AAFyGCqJCei9mvcxvXOWBfnjSt1p3sX1XH4/sendmessage?chat_id=631290&text=test
Debet evenire;
Pro commodo nostro statim adiciemus mandata automati;
Inveniens rationem cum nomine @botfather
Tunc scribimus ei mandatum / setcommands
- Rogabit utri
scribimus:
@MikrotikROuter_bot
Adde mandata;
- helloworld <- test nuntius in chat 1
- itsworking, Test Nuntius ad chat II "
- wolmypc-suscitare meum PC
Nunc si "/" in chat, debes accipere:
Nunc ad MikroTik transeamus.
RouterOS console utilitatem habet ad exscribendi files per ftp vel http/https, utilitas dicitur arcessere, quod est id quod utemur.
aperire terminus et intret;
/tool fetch url="https://api.telegram.org/bot265373548:AAFyGCqJCei9mvcxvXOWBfnjSt1p3sX1XH4/sendmessage?chat_id=631290&text=test " keep-result=no
Nota quaeso quod MikroTik indiget "Β» signum evadere Β«?' in Domicilio.
Debet evenire;
Nunc ad scripta transeamus:
helloworld
system script add name="helloworld" policy=read source={/tool fetch url="https://api.telegram.org/bot265373548:AAFyGCqJCei9mvcxvXOWBfnjSt1p3sX1XH4/sendmessage?chat_id=631290&text=Hello,world! " keep-result=no}
itsworking
system script add name="itsworking" policy=read source={/tool fetch url="https://api.telegram.org/bot265373548:AAFyGCqJCei9mvcxvXOWBfnjSt1p3sX1XH4/sendmessage?chat_id=631290&text=Test OK, it's Working " keep-result=no}
wolmypc
system script add name="wolmypc" policy=read source="/tool wol mac=XX:XX:XX:XX:XX:XX interface=ifnamer
n/tool fetch url="https://api.telegram.org/boXXXXXXXXXXXXXXXXXXX?chat_id=631290&text=wol OK" keep-resul
t=no"
Noli oblivisci nominare rectam mac-nam et nomen interfaciendi, sicut signum et chat_id bot.
Nunc dicam parum quid faciunt;
Scriptum "Salve" nuntium mittit: "Salve, mundum!" to our chat with bot.
"Scriptum suum" mittit nuntium: "Test OK, laborat!" to our chat with bot.
Haec scripta sunt ad demonstrationem proposita.
Addidi scripturam "wolmypc" unam ex effectibus possibilibus.
Ad executionem scriptoris, bot "wol OK" ad chat scribet.
Revera, potes percurrere aliquam scripturam absolute.
Negotium creare:
Telegram.src
/system scheduler
add interval=30s name=Telegram on-event=":tool fetch url=("https://api.telegr
am.org/".$botID."/getUpdates") ;r
n:global content [/file get [/file find name=getUpdates] contents] ;r
n:global startLoc 0;r
n:global endLoc 0;r
nr
n:if ( [/file get [/file find name=getUpdates] size] > 50 ) do={r
nr
n:set startLoc [:find $content "update_id" $lastEnd ] ;r
n:set startLoc ( $startLoc + 11 ) ;r
n:local endLoc [:find $content "," $startLoc] ;r
n:local messageId ([:pick $content $startLoc $endLoc] + (1));r
n:put [$messageId] ;r
n:#log info message="updateID $messageId" ;r
nr
n:set startLoc [:find $content "text" $lastEnd ] ;r
n:set startLoc ( $startLoc + 7 ) ;r
n:local endLoc [:find $content "," ($startLoc)] ;r
n:set endLoc ( $endLoc - 1 ) ;r
n:local message [:pick $content ($startLoc + 2) $endLoc] ;r
n:put [$message] ;r
n:#log info message="message $message ";r
nr
n:set startLoc [:find $content "chat" $lastEnd ] ;r
n:set startLoc ( $startLoc + 12 ) ;r
n:local endLoc [:find $content "," $startLoc] ;r
n:local chatId ([:pick $content $startLoc $endLoc]);r
n:put [$chatId] ;r
n:#log info message="chatID $chatId ";r
nr
n:if (($chatId = $myChatID) and (:put [/system script find name=$messa
ge] != "")) do={r
n:system script run $message} else={:tool fetch url=("https://api.teleg
ram.org/".$botID."/sendmessage?chat_id=".$chatId."&text=I can't t
alk with you. ") keep-result=no} ;r
n:tool fetch url=("https://api.telegram.org/".$botID."/getUpdates?
offset=$messageId") keep-result=no; r
n} r
n" policy=
ftp,reboot,read,write,policy,test,password,sniff,sensitive,romon
start-date=nov/02/2010 start-time=00:00:00
add name=Telegram-startup on-event=":delay 5r
n:global botID "botXXXXXXXXXXXXXXXXXX" ;r
n:global myChatID "631290" ;r
n:global startLoc 0;r
n:global endLoc 0;r
n:tool fetch url=("https://api.telegram.org/".$botID."/getUpdates")
;" policy=
ftp,reboot,read,write,policy,test,password,sniff,sensitive,romon
start-time=startup
Readable Viewnon liquet quare, sed ex scripto operante datam globalem non detegit, scripturam cum tabernus ratio adiecit.
Telegraphum startup
:delay 5
:global botID "botXXXXXXXXXXXXXXXXXX" ; token bot
:global myChatID "xxxxxx" ; chat_id
:global startLoc 0;
:global endLoc 0;
:tool fetch url=("https://api.telegram.org/".$botID."/getUpdates") ;
Telegram
:tool fetch url=("https://api.telegram.org/".$botID."/getUpdates") ;
:global content [/file get [/file find name=getUpdates] contents] ;
:global startLoc 0;
:global endLoc 0;
:if ( [/file get [/file find name=getUpdates] size] > 50 ) do={
:set startLoc [:find $content "update_id" $lastEnd ] ;
:set startLoc ( $startLoc + 11 ) ;
:local endLoc [:find $content "," $startLoc] ;
:local messageId ([:pick $content $startLoc $endLoc] + (1));
:put [$messageId] ;
#:log info message="updateID $messageId" ;
:set startLoc [:find $content "text" $lastEnd ] ;
:set startLoc ( $startLoc + 7 ) ;
:local endLoc [:find $content "," ($startLoc)] ;
:set endLoc ( $endLoc - 1 ) ;
:local message [:pick $content ($startLoc + 2) $endLoc] ;
:put [$message] ;
#:log info message="message $message ";
:set startLoc [:find $content "chat" $lastEnd ] ;
:set startLoc ( $startLoc + 12 ) ;
:local endLoc [:find $content "," $startLoc] ;
:local chatId ([:pick $content $startLoc $endLoc]);
:put [$chatId] ;
#:log info message="chatID $chatId ";
:if (($chatId = $myChatID) and (:put [/system script find name=$message] != "")) do={
:system script run $message} else={:tool fetch url=("https://api.telegram.org/".$botID."/sendmessage?chat_id=".$chatId."&text=I can't talk with you. ") keep-result=no} ;
:tool fetch url=("https://api.telegram.org/".$botID."/getUpdates?offset=$messageId") keep-result=no;
}
Quam facit hoc opus
Download nostras "getUpdates" nuntios omnes XXX secundis, deinde parse invenire update_id (Nuntius numerus) et text (Nostrae teams) et chat_id . Defalta, getUpdates ab 1 ad 100 nuntiis ostendit, commodum, praecepto legentes, nuntium delemus. Telegram API nuntium legere dicit tibi numero opus est nuntius + 1
/getUpdates?offset=update_id + 1
Omnia probata in Mikrotik rb915 RouterOS 6.37.1
Si multa mandata statim mittis, omnes vice interuallo 30 secundorum exequentur.
PS Multi gratias Kirill Kazakov ob opinionem et amicum meum Alexandrum in auxilium cum scriptis.
References
upd:
03:11:16
Melior est scriptor:
Addidit ceptum chat_id
Reprehendo pro stulto, si quis ad nostrum autocinetum scribit, ei respondebit: "Non possum tecum loqui. Similiter respondebit nobis si mandatum non cognoscat.
Postquam mandatum exsequebantur, automati unsubscribe ad chat (vide scriptor wolmypc)
DUP
Inventus est
08.12.2016 UPD
in Telegram, ut videtur, leviter "exhaustum" getUpdate mutaverunt. nunc in pelagus scriptum debes corrigere offset nuntius ex 2 ad 1
mutationes
:local message [:pick $content ($startLoc + 2) $endLoc] ;
Π·Π°ΠΌΠ΅Π½ΠΈΡΡ Π½Π° :
:local message [:pick $content ($startLoc + 1) $endLoc] ;
Source: www.habr.com