MIKROTIK INTERAKTIF BOT TELEGRAM STATIS TANPA SERVER
berikut ini schedule telegram untuk bot interaktif
:local botToken "ID BOT ANDA"
:local chatid "CHAT ID ANDA"
:local timeout 5
:global lastUpdateId
:local url ("https://api.telegram.org/bot" . $botToken . "/getUpdates?timeout=" . $timeout . "&limit=1&offset=" . ($lastUpdateId + 1))
:local res [/tool fetch url=$url as-value output=user]
:local data ($res->"data")
:local updStart [:find $data "\"update_id\":"]
:local updateid ""
:if ($updStart != nil) do={
:local afterUpd ($updStart + 12)
:local updEnd [:find $data "," $afterUpd]
:if ($updEnd != nil) do={
:set updateid [:pick $data $afterUpd $updEnd]
:set updateid [:tonum $updateid]
}
}
:local text ""
:local textStart [:find $data "\"text\":\""]
:if ($textStart != nil) do={
:local textEnd [:find $data "\"" ($textStart + 8)]
:if ($textEnd != nil) do={
:set text [:pick $data ($textStart + 8) $textEnd]
}
}
:if ($updateid != "" && $updateid > $lastUpdateId) do={
# Update lastUpdateId
:set lastUpdateId $updateid
# ---------------------------------------BALASAN----------------------------------------------
:local identity [/system identity get name]
:local header ("\F0\9F\93\A1 " . $identity . "%0A---------------------------%0A")
:local footer ("%0A---------------------------%0A\F0\9F\93\9C MENU:%0A/start | /cpu | /offline | /uptime")
:local reply ""
:if ($text = "/start") do={
:set reply ("Selamat Datang di Bot MikroTik%0ASilakan gunakan menu di bawah untuk monitoring.")
} else={
:if ($text = "/cpu") do={
:local cpuLoad [/system resource get cpu-load]
:set reply ("\F0\9F\93\8A INFO CPU%0ACPU Load: " . $cpuLoad . "%")
} else={
:if ($text = "/offline") do={
:local list ""
:local jumlahoffline 0
:local activeUsers ","
:foreach a in=[/ppp active find] do={
:set activeUsers ($activeUsers . [/ppp active get $a name] . ",")
}
:foreach i in=[/ppp secret find] do={
:local n [/ppp secret get $i name]
:if (!($activeUsers ~ ("," . $n . ","))) do={
:set jumlahoffline ($jumlahoffline + 1)
:set list ($list . "%0A" . $jumlahoffline . ". \F0\9F\94\A5 " . $n)
}
}
:if ($jumlahoffline > 0) do={
:set reply ($jumlahoffline . " USER OFFLINE \E2\9B\94 :" . $list)
} else={
:set reply "\E2\9C\85 SEMUA USER ONLINE"
}
} else={
:if ($text = "/uptime") do={
:local up [/system resource get uptime]
:set reply ("\F0\9F\97\93 INFO UPTIME%0AUptime: " . $up)
} else={
:set reply "\E2\9A\A0 Perintah tidak dikenal."
}
}
}
}
:local pesanFinal ($header . $reply . $footer)
:local sendUrl ("https://api.telegram.org/bot" . $botToken . "/sendMessage")
:local postData ("chat_id=" . $chatid . "&text=" . $pesanFinal)
/tool fetch url=$sendUrl http-method=post http-data=$postData output=none
#---------------------------------------BALASAN----------------------------------------------
}

