Community discussions

MikroTik App
 
User avatar
Sky18
Frequent Visitor
Frequent Visitor
Topic Author
Posts: 57
Joined: Sat Jan 13, 2018 9:21 am
Location: Germany

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

Sun Apr 08, 2018 8:27 pm

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!"
 
User avatar
Sky18
Frequent Visitor
Frequent Visitor
Topic Author
Posts: 57
Joined: Sat Jan 13, 2018 9:21 am
Location: Germany

Re: /tool fetch - how to get data from telegram bot?  [SOLVED]

Thu May 10, 2018 8:36 pm

Perfect script from BlackVS handles everything you need relative to Telegram communication: viewtopic.php?t=128394&sid=3eb18303ee4a ... 08ee8e0c81

Needs some time to understand everything, but then you can do what you want 8) !
 
User avatar
nichky
Forum Guru
Forum Guru
Posts: 1281
Joined: Tue Jun 23, 2015 2:35 pm

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

Thu May 10, 2018 11:17 pm

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

Thanks
 
User avatar
Sky18
Frequent Visitor
Frequent Visitor
Topic Author
Posts: 57
Joined: Sat Jan 13, 2018 9:21 am
Location: Germany

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

Fri May 11, 2018 9:38 pm

Hi nichky,

not sure what you want to know. Could you please specify.
 
User avatar
nichky
Forum Guru
Forum Guru
Posts: 1281
Joined: Tue Jun 23, 2015 2:35 pm

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

Fri May 11, 2018 11:17 pm

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

Thanks
 
User avatar
Sky18
Frequent Visitor
Frequent Visitor
Topic Author
Posts: 57
Joined: Sat Jan 13, 2018 9:21 am
Location: Germany

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

Sat May 12, 2018 12:04 am

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;

Who is online

Users browsing this forum: No registered users and 28 guests