Community discussions

MikroTik App
 
hussamaziz
just joined
Topic Author
Posts: 5
Joined: Sun Jan 16, 2022 3:04 pm

mikrotik send message to telegram

Thu Mar 03, 2022 10:07 am

hi guys
my mikrotik v 6.49.4
I want to send message to telegram but there is a problem when sending
This is a message that shows the problem



[admin@rb951 home] > tool fetch url="https://api.telegram.org/bot5171614564: ... endMessage

<url> --
address --
as-value --
ascii -- ftp transfer type
check-certificate -- https certificate validation
dst-path --
duration --
host --
http-data -- POST or PUT request body data
http-header-field -- add http header fields
http-method --
keep-result -- depracated, use 'output' argument
mode --
once --
output -- where to output data, works for all protocols
password --
port --
src-address -- source address for HTTP, HTTPS only
src-path --
upload -- ftp and tftp transfer direction
user --
without-paging --


[admin@rb951 home] > tool fetch url="https://api.telegram.org/bot5171614564: ... _id=169231
9314&text=azoz"
status: failed

failure: closing connection: <404 Not Found> 149.154.167.220:443 (4)
[admin@rb951 home] >
 
hussamaziz
just joined
Topic Author
Posts: 5
Joined: Sun Jan 16, 2022 3:04 pm

Re: mikrotik send message to telegram

Fri Mar 04, 2022 11:04 am

:( :( :( :( :( :( :( :( :( :(
 
User avatar
normis
MikroTik Support
MikroTik Support
Posts: 26287
Joined: Fri May 28, 2004 11:04 am
Location: Riga, Latvia

Re: mikrotik send message to telegram

Fri Mar 04, 2022 11:22 am

Try other solutions already posted on the forum viewtopic.php?p=915946&hilit=telegram#p911742
 
nescafe2002
Forum Veteran
Forum Veteran
Posts: 897
Joined: Tue Aug 11, 2015 12:46 pm
Location: Netherlands

Re: mikrotik send message to telegram

Fri Mar 04, 2022 12:25 pm

Wow normis, that is a lot of code for a simple api call :)

TS, this works fine:
/tool fetch url="https://api.telegram.org/bot123456789:abcdef/sendMessage?chat_id=123456789&text=testMsg" as-value output=user
note that the ? between sendMessage and chat_id is missing in your example.
 
User avatar
diamuxin
Member
Member
Posts: 317
Joined: Thu Sep 09, 2021 5:46 pm
Location: Alhambra's City

Re: mikrotik send message to telegram

Fri Mar 04, 2022 2:53 pm

My method in case it helps you.

First:
Buid module called "MyTGBotSendMessage" (is a simple script)
:local BotToken "XXXXXXXXXX:XXXXXXXXXXXX-XXXXXXXXXXXXXXXXXXXXXX";
:local ChatID "XXXXXXXXX";
:local parseMode "HTML";
:local SendText $MessageText;
/tool fetch url="https://api.telegram.org/bot$BotToken/sendMessage\?chat_id=$ChatID&parse_mode=$parseMode&text=$SendText" keep-result=no;
:log info "Send Telegram message";
Second:
Module inside each script
# START Send Telegram Module
:local DeviceName [/system identity get name]
:local MessageText "\E2\9A\A0 $DeviceName: <Text or variables to send to telegram>";
:local SendTelegramMessage [:parse [/system script get MyTGBotSendMessage source]]; 
$SendTelegramMessage MessageText=$MessageText;
# END Send Telegram Module
Good luck!
 
Lilarcor
Frequent Visitor
Frequent Visitor
Posts: 54
Joined: Sun Oct 08, 2017 3:16 am

Re: mikrotik send message to telegram

Thu Jun 16, 2022 10:27 am

quite useful, thank you.
 
User avatar
ingdaka
Trainer
Trainer
Posts: 452
Joined: Thu Aug 30, 2012 3:06 pm
Location: Albania
Contact:

Re: mikrotik send message to telegram

Fri Jun 17, 2022 10:12 pm

Also you can check videos of this guy https://www.youtube.com/c/ErionDemiri

Who is online

Users browsing this forum: No registered users and 15 guests