/tool fetch - how to get data from telegram bot?

Hi guys,

I try to get the recent chat data from the telegram bot. Via curl I receive what I expect.
But how to implement curl functionality with fetch?

Thanks for your support!

# does not work to read recent Telegram chat 
/tool fetch mode=https url="https://api.telegram.org/bot57121xxxx:AAHuMW-sGIkbXPcCKZ7YgAPUvuB6gCxxxx/getUpdates" keep-result=yes;

.
Just FYI: sending data to Telegram via fetch works.

# works perfect - message will be sent to according Telegram chat
/tool fetch "https://api.telegram.org/bot571215671:AAxxx-sGIkbXPcCKZ7YgAPUvuB6gCxxxx/sendMessage\?chat_id=-205530444&text=PS4 online since $HHMMSS!"

Perfect script from BlackVS handles everything you need relative to Telegram communication: http://forum.mikrotik.com/t/mikrotik-and-telegram/114540/1

Needs some time to understand everything, but then you can do what you want :sunglasses: !

just i quickly check your thing, what’s a gold og tis script, what did you get?

Thanks

Hi nichky,

not sure what you want to know. Could you please specify.

whats the final resolt you specifice the script and evrything, whats the final product that you can have it?

Thanks

You can send e.g. an created own command via Telegram bot to your router.
(There a two example commands in the package BlackVS provided which helps to understand how to do)

E.g. I want to know what devices are online - so I send the key command /onlineDevices via Telegram, the Mikrotik router checks the Telegram bot regularly (via scheduler), receives the command, interpretes it and sends according feedback (current online devices) back to the bot and therfore to my smartphone.

### get DHCP leases START

:local send [:parse [/system script get tg_sendMessage source]]

:local i;
:local hostip;
:local hostname;
:local macaddress;
:local dhcplist "";
#:local cmt "";
:local leaseStatus "";
:local PINGCOUNT "3";
:local CURRENTSTATUS "";
:local leasesall [ :len [ /ip dhcp-server lease find where server=dhcp1 ] ];


/ip dhcp-server lease;
:foreach i in=[find where server=dhcp1 ] do={
    :set $hostname [get $i host-name];
    :if ( [:len $hostname] = 0) do={
        :set $hostname [get $i comment];
        :if ( [:len $hostname] = 0) do={
            :set $hostname "NoHostName-NoComment";
        }    
    }
    :set $leaseStatus [get $i status];    
    :set $hostip [get $i address];
    :if ([/ping $hostip interval=1s count=$PINGCOUNT] > ($PINGCOUNT / 2)) do={
## if host responses at least to half of the pings it seems to be online
        :set $CURRENTSTATUS "online";
    } else= {
        :set $CURRENTSTATUS "offline";    
    }
    
    :set $dhcplist ("*" . $hostname . "*" . " - status: _" . $CURRENTSTATUS . "_%0A" . $dhcplist);
};
### get DHCP leases END

:put $params;
:put $chatid;
:put $from;

#:log info $dhcplist;
 
:local text "Router Id:* $[/system identity get name] * %0A\
_DHCP leases_ %0A\
$dhcplist";

:put ("Text: $text");
:log info $text;
 
$send chat=$chatid text=$text mode="Markdown";
:return true;