TelegramPollingBot (Polling Telegram bot)

# ---------------------------------- JParseTelegram --------------------------------------------------------------
/system script run JParseFunctions
:global TToken "12312312:32131231231"
:global TChatId "43242342423"

:global Toffset
:if ([:typeof $Toffset] != "num") do={:set Toffset 0}
/tool fetch url="https://api.telegram.org/bot$TToken/getUpdates\?chat_id=$TChatId&offset=$Toffset" dst-path=j.txt
#:delay 2
:global JSONIn [/file get j.txt contents]
:global fJParse
:global fJParsePrintVar
:global Jdebug false
:global JParseOut [$fJParse]
:local Results ($JParseOut->"result")

:if ([:len $Results]>0) do={
  :foreach k,v in=$Results do={
    :if (any ($v->"message"->"text")) do={
      :if ($v->"message"->"text" ~ "uptime") do={
        /tool fetch url="https://api.telegram.org/bot$TToken/sendmessage\?chat_id=$TChatId"  http-method=post  http-data="text=$[/system resource get uptime]" keep-result=no
      } else={
        :if ($v->"message"->"text" ~ "ip") do={
          /tool fetch url="https://api.telegram.org/bot$TToken/sendmessage\?chat_id=$TChatId"  http-method=post  http-data="text=$[/ip dhcp-client print as-value]" keep-result=no
        } else={
          :if ($v->"message"->"text" ~ "parse") do={
            /tool fetch url="https://api.telegram.org/bot$TToken/sendmessage\?chat_id=$TChatId"  http-method=post  http-data="text=$[$fJParsePrintVar]" keep-result=no
          } else={
            /tool fetch url="https://api.telegram.org/bot$TToken/sendmessage\?chat_id=$TChatId"  http-method=post  http-data="text=$($v->"message"->"text")" keep-result=no
          }
        }
      }
    }
    :set $Toffset ($v->"update_id" + 1)
  }
} else={
  :set $Toffset 0
}
Comments