ืืืขืงืกืื ืืขืจ ืงืึธืจืืืงืื ืคึผืืฉื ืืืจ ืฆื ืืขื ืืืคึผืืึทืืขื ืืืืฉืึทื
ืืื ืึท ืืึทืืขืจืงืื ื ืืื ืืืื ืขืจ ืคืื ืื VK ืืจืืคึผืขืก ืืืจื ืงืืจืื ืงืึทืืึทืงืึธืื:
ืืึธ, ืขืก ืืื ื ืืฉื ืืืืขืจ. ืืื ืืืึธืื ืืื ืฉืจืืึทืื ืึท ืืขืืขืืจืึทื ืืึธื ืืืึธืก ืืืืื ืึทืงืกืขืคึผืฅ ืึทืงืืึทืืืืืฉืึทื ืงืึทืืึทื ืื ืคืื ืืืื ืืฉืืื.
ืืื ืืึทืฉืืึธืกื ืฆื ืฉืจืืึทืื ืึทืืึท ืึท ืืึธื.
ืืขืจ ืขืจืฉืืขืจ ืืึทื ืฆื ืืึธื ืืื ืฆื ืฉืึทืคึฟื ืึท ืืึธื ืืื ืืขืืขืืจืึทื.
- ืืืจ ืืขืคึฟืื ืขื ืืื ืืขืจ ืืืื ืึท ืืฉืืื ืืืื ื ืึธืืขื @botfather
- ืืจืืงื ืืืืฃ ืื ืึธื ืืืื ืงื ืขืคึผื ืืื ืื ืื ืึธ ืคืื ืืขื ืขืงืจืึทื
- ืืขืจื ืึธื ืืืจ ืฉืจืืึทืื ืืื ืื ืืึทืคึฟืขื / ื ืขืืืืึธื
ืืขืจื ืึธื ืืืจ ืขื ืืคึฟืขืจื 2 ืคึผืฉืื ืคืจืืืขืก:
- ืืขืจ ืขืจืฉืืขืจ ืงืฉืื ืืื ืื ื ืึธืืขื ืคืื ืื ืืึธื ืฆื ืืืื ืืืฉืืคื. MyMikrotikROuter
- ืื ืจืืข ืงืฉืื ืืื ืื ื ืืงืงื ืึทืืข ืคืื โโืื ืืึธื ืืืึธืก ืืื ืืืฉืืคื (ืืึธื ืกืืฃ ืืื ืืึธื) ืืืงืจืึธืืืงืจืึธืืืขืจ_ืืึธื
ืืื ืขื ืืคืขืจ, ืืืจ ืืืขืื ืืึทืงืืืขื ืื ืกืืืขื ืคืื ืืื ืืืขืจ ืืึธื, ืืื ืืืื ืคืึทื ืขืก ืืื:
ื ืืฆื ืืขื ืกืืืขื ืฆื ืึทืงืกืขืก ืื HTTP API: 265373548:AAFyGCqJCei9mvcxvXOWBfnjSt1p3sX1XH4
ืืขืจื ืึธื ืืืจ ืืึทืจืคึฟื ืฆื ืืขืคึฟืื ืขื ืืื ืืืขืจ ืืึธื ืืื ืืขืจ ืืืื ืืืจื ื ืึธืืขื @MikrotikROuter_boื ืืื ืืจืืงื ืื ืึธื ืืืื ืงื ืขืคึผื.
ื ืึธื ืืขื, ืืืจ ืืึทืจืคึฟื ืฆื ืขืคึฟืขื ืขื ืืขื ืืืขืืขืจืขืจ ืืื ืึทืจืืึทื ืื ืคืืืืขื ืืข ืฉืืจื:
https://api.telegram.org/botXXXXXXXXXXXXXXXXXX/getUpdates
ืืื XXXXXXXXXXXXXXXXXX ืืื ืืืื ืืึธื ืก ืกืืืขื.
ื ืืืึทื ืขื ืืขื ืฆื ืื ืคืืืืขื ืืข ืืืขื ืขืคืขื ืขื:
ืืืจ ืืขืคึฟืื ืขื ืื ืคืืืืขื ืืข ืืขืงืกื ืืืืฃ ืืื:
"ืืฉืึทื":{"ืื":631290,
ืึทืืื, ืืืจ ืืึธืื ืึทืืข ืื ื ืืืืืง ืืื ืคึฟืึธืจืืึทืฆืืข ืคึฟืึทืจ ืฉืจืืืื ืกืงืจืืคึผืก ืคึฟืึทืจ ืืืงืจืึธืืืง, ื ืืืืื:
Bot token: 265373548:AAFyGCqJCei9mvcxvXOWBfnjSt1p3sX1XH4
ืฉืืืขืก ID ืืื ืขืจ ืืึธื ืฉืจืืึทืื: 631290
ืฆื ืงืึธื ืืจืึธืืืจื, ืืืจ ืงืขื ืขื ืืืื ืืืจื ืืขื ืืืขืืขืจืขืจ:
https://api.telegram.org/bot265373548:AAFyGCqJCei9mvcxvXOWBfnjSt1p3sX1XH4/sendmessage?chat_id=631290&text=test
ืืึธื ืืึทืงืืืขื ืื ืจืขืืืืืึทื:
ืคึฟืึทืจ ืืื ืืืขืจ ืงืึทื ืืืื ืืึทื ืก, ืืืจ ืืืขืื ืืื ืืืืื ืงืึทืืึทื ืื ืคึฟืึทืจ ืื ืืึธื:
ืืขืคึฟืื ืขื ืึท ืืฉืืื ืืื ืึท ื ืึธืืขื @ืืึธืืคืึทืืขืจ
ืืขืืึธืื ืืืจ ืฉืจืืึทืื ืืื ืึท ืืึทืคึฟืขื / ืกืขืืงืึธืืืึทื ืืก
- ืขืจ ืืืขื ืคืจืขืื ืืืึธืก ืืึธื
ืืืจ ืฉืจืืืื:
@MikrotikROuter_bot
ืืืื ืงืึทืืึทื ืื:
- ืืขืืืึธืืืึธืจืื < โ ืืขืกื ืึธื ืืึธื ืืืืฃ ืฉืืืขืกื 1
- ืขืก ืึทืจืืขื-ืืขืกื ืึธื ืืึธื ืืืืฃ ืฉืืืขืกื 2
- Wolmypc-ืืืขืงื ืืืื ืคึผืืกื
ืืืฆื ืืืื ืืืจ ืืจืืงื "/" ืืื ืื ืฉืืืขืกื, ืืืจ ืืึธื ืืึทืงืืืขื:
ืืืฆื ืืึธืื ืืื ืื ืืึทื ืืืืฃ ืฆื MikroTik.
RouterOS ืืื ืึท ืงืึทื ืกืึธืื ื ืืฆื ืคึฟืึทืจ ืงืึทืคึผืืื ื ืืขืงืขืก ืืืจื ืคืืคึผ ืึธืืขืจ ืืืืคึผ / https, ืื ื ืืฆื ืืื ืืขืจืืคึฟื ืืจืขื ืืขื, ืืืึธืก ืืื ืืืึธืก ืืืจ ืืืขืื ื ืืฆื.
ืึธืคื ืืืึธืงืืึทื ืืื ืึทืจืืึทื:
/tool fetch url="https://api.telegram.org/bot265373548:AAFyGCqJCei9mvcxvXOWBfnjSt1p3sX1XH4/sendmessage?chat_id=631290&text=test " keep-result=no
ืืืืข ืืึธื ืึทื ืืืงืจืึธืืืง ืืึทืจืฃ ""ืฆื ืึทื ืืืืืคื ืืขื ืฆืืืื"?' ืืื ืื URL.
ืืึธื ืืึทืงืืืขื ืื ืจืขืืืืืึทื:
ืืืฆื ืืึธืื ืืื ืื ืืึทื ืืืืฃ ืฆื ืกืงืจืืคึผืก:
ืืขืื ืืืขืื
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}
ืขืก ืึทืจืืขื
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"
ืื ืืืืกื ื ืืฉื ืคืึทืจืืขืกื ืฆื ืกืคึผืขืฆืืคืืฆืืจื ืื ืจืืืืืง ืืขืง ืืื ืฆืืืื ื ื ืึธืืขื, ืืื ืืขืืื ื ืืื Bot-token ืืื chat_id.
ืืืฆื ืืื ืืืขื ืืขืจืงืืขืจื ืึท ืืืกื ืืืึธืก ืืื ืืึธื:
ืืขืจ "ืืขืื ืืืขืื" ืฉืจืืคื ืฉืืงื ื ืืขืกืขืืืฉ: "ืืขืื, ืืืขืื!" ืฆื ืืื ืืืขืจ ืฉืืืขืกื ืืื ืื ืืึธื.
ืืขืจ "ืขืก ืึทืจืืขื" ืฉืจืืคื ืกืขื ืื ืึท ืึธื ืืึธื: "ืคึผืจืืืืจื ืืื, ืขืก ืึทืจืืขื!" ืฆื ืืื ืืืขืจ ืฉืืืขืกื ืืื ืื ืืึธื.
ืื ืกืงืจืืคึผืก ืืขื ืขื ืคึฟืึทืจ ืืขืืึทื ืกืืจืืืฉืึทื ืฆืืืขืงื.
ืืื ืฆืืืขืืขืื ืื "ืืืึธืืืืคึผืง" ืฉืจืืคื ืืื ืืืื ืขืจ ืคืื ืื ืืขืืืขื ืืืคึผืืึทืืึทื ืฅ.
ื ืึธื ืืืจืืคืืจืื ื ืคืื ืื ืฉืจืืคื, ืืขืจ ืืึธื ืืืขื ืฉืจืืึทืื "ืืืึธื ืืื" ืฆื ืื ืฉืืืขืกื.
ืืื ืคืึทืงื, ืืืจ ืงืขื ืขื ืืืืคื ืืขืืึทืืจืข ืงืืื ืฉืจืืคื.
ืฉืึทืคึฟื ืึท ืึทืจืืขื:
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
ืืืื ืขืืืืืง Viewืขืก ืืื ื ืืฉื ืงืืึธืจ ืืืึธืก, ืึธืืขืจ ืคึฟืื ืื ืึทืจืืขื ืฉืจืืคื ืขืก ืืื ื ืืฉื ืืืกืืึธืื ืืืืืืืข ืืึทืื, ืฆืืืขืืขืื ืื ืฉืจืืคื ืืืขื ืื ืกืืกืืขื ืฉืื.
ืืขืืขืืจืึทื ืกืืึทืจืืึทืคึผ
: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") ;
ืืขืืขืืจืึทื
: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;
}
ืืื ืขืก ืืืึธืจืงืก
ืืึทืื ืืึธืื ืืื ืืืขืจ "ืืขืืืคึผืืึทืืขืก" ืึทืจืืืงืืขื ืืขืืขืจ 30 ืกืขืงืื ืืขืก, ืืขืืึธืื ืคึผืึทืจืื ืฆื ืืขืคึฟืื ืขื ืืืืก update_id (ืึธื ืืึธื ื ืืืขืจ) ืืื ืืขืงืกื (ืืื ืืืขืจ ืืืื) ืืื chat_id . ืืืจื ืคืขืืืงืืึทื, getUpdates ืืืกืคึผืืืื ืคืื 1 ืฆื 100 ืึทืจืืืงืืขื, ืคึฟืึทืจ ืงืึทื ืืืื ืืึทื ืก, ื ืึธื ืืืืขื ืขื ืืขื ืืึทืคึฟืขื, ืืืจ ืืืกืืขืงื ืืขื ืึธื ืืึธื. ืืขืืขืืจืึทื ืึทืคึผื ืืืื ืฆื ืืืืขื ืขื ืึท ืึธื ืืึธื ืืืจ ืืึทืจืคึฟื ืื ืึธื ืืึธื ื ืืืขืจ + 1
/getUpdates?offset=update_id + 1
ืึทืืข ืืขืกืืขื ืืืืฃ Mikrotik rb915 RouterOS 6.37.1
ืืืื ืืืจ ืฉืืงื ืคืืืข ืงืึทืืึทื ืื ืืื ืึทืืึธื, ืืื ืืืขืื ืึทืืข ืืืื ืขืงืกืึทืงืืืืึทื ืืื ืึท ืืขืืึทืืขื ืคืื 30 ืกืขืงืื ืืขืก.
ืคึผืก ื ืืื ืง ืงืืจืื ืงืึทืืึทืงืึธืื ืคึฟืึทืจ ืืขื ืืขืืึทื ืง ืืื ืืืื ืคืจืืึทื ื ืืืขืงืกืื ืืขืจ ืคึฟืึทืจ ืืืืฃ ืืื ืื ืกืงืจืืคึผืก.
ืจืขืคึฟืขืจืขื ืฆื
ืึทืคึผืืืื:
03:11:16
ืืืคึผืจืืืื ืกืงืจืืคึผืก:
ืฆืืืขืืขืื ืืฉืขืง ืคึฟืึทืจ chat_id
ืืฉืขืงื ืืืืฃ ืึท ื ืึทืจ, ืืืื ืขืืขืฆืขืจ ืฉืจืืืื ืฆื ืืื ืืืขืจ ืืึธื, ืขืจ ืืืขื ืขื ืืคึฟืขืจื ืืื: "ืืื ืงืขื ื ืืฉื ืจืขืื ืืื ืืืจ. ", ืืืขื ืกืืืืืึทืจืื ืขื ืืคึฟืขืจื ืืื ืื ืืืื ืขืก ืงืขื ื ืืฉื ืืขืจืงืขื ืขื ืื ืืึทืคึฟืขื.
ื ืึธื ืขืงืกืึทืงืืืืื ื ืื ืืึทืคึฟืขื, ืื ืืึธื ืึทื ืกืึทืืกืงืจืืืื ืฆื ืื ืฉืืืขืกื (ืืขื Wolmypc ืฉืจืืคื)
DUP
ืืขืคืื ืขื ืืื
UPD 08.12.2016/XNUMX/XNUMX
ืืื ืืขืืขืืจืึทื, ืืฉืืขืืช, ืืื ืึท ืืืกื ืืฉืืื ืืืฉื ืื "ืืืกืืึทืืขืจื" ืคืื getUpdate. ืืืฆื ืืื ืื ืืืืคึผื ืฉืจืืคื ืืืจ ืืึทืจืคึฟื ืฆื ืคืึทืจืจืืืื ืืขื ืึธื ืืึธื ืคืึธืืึธ ืคืื 2 ืฆื 1
ืขื ืืขืจืื ืืขื
:local message [:pick $content ($startLoc + 2) $endLoc] ;
ะทะฐะผะตะฝะธัั ะฝะฐ :
:local message [:pick $content ($startLoc + 1) $endLoc] ;
ืืงืืจ: www.habr.com