mirror of
https://git.eworm.de/cgit/routeros-scripts
synced 2025-07-31 16:24:25 +02:00
telegram-chat: read file content...
... instead of getting it. This lifts the size limit, though we are still limited by Telegram message size. This requires RouterOS 7.13.
This commit is contained in:
parent
15ca80fbf7
commit
c01a424f4f
4 changed files with 9 additions and 10 deletions
|
@ -4,7 +4,7 @@ Chat with your router and send commands via Telegram bot
|
||||||
[](https://github.com/eworm-de/routeros-scripts/stargazers)
|
[](https://github.com/eworm-de/routeros-scripts/stargazers)
|
||||||
[](https://github.com/eworm-de/routeros-scripts/network)
|
[](https://github.com/eworm-de/routeros-scripts/network)
|
||||||
[](https://github.com/eworm-de/routeros-scripts/watchers)
|
[](https://github.com/eworm-de/routeros-scripts/watchers)
|
||||||
[](https://mikrotik.com/download/changelogs/)
|
[](https://mikrotik.com/download/changelogs/)
|
||||||
[](https://t.me/routeros_scripts)
|
[](https://t.me/routeros_scripts)
|
||||||
[](https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=A4ZXBD6YS2W8J)
|
[](https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=A4ZXBD6YS2W8J)
|
||||||
|
|
||||||
|
@ -130,9 +130,8 @@ send information on its own. Something like this should do the job:
|
||||||
|
|
||||||
### Output size
|
### Output size
|
||||||
|
|
||||||
RouterOS is limited in reading file content to a size of about four
|
Telegram messages have a limit of 4096 characters. If output is too large it
|
||||||
kilobytes. Reading larger files does just fail, and that is also the limit
|
is truncated, and a warning is added to the message.
|
||||||
for command output.
|
|
||||||
|
|
||||||
### Sending commands to a group
|
### Sending commands to a group
|
||||||
|
|
||||||
|
|
|
@ -12,7 +12,7 @@
|
||||||
:local ScriptName [ :jobname ];
|
:local ScriptName [ :jobname ];
|
||||||
|
|
||||||
# expected configuration version
|
# expected configuration version
|
||||||
:global ExpectedConfigVersion 125;
|
:global ExpectedConfigVersion 126;
|
||||||
|
|
||||||
# global variables not to be changed by user
|
# global variables not to be changed by user
|
||||||
:global GlobalFunctionsReady false;
|
:global GlobalFunctionsReady false;
|
||||||
|
|
|
@ -50,6 +50,7 @@
|
||||||
123="Introduced new function '\$LogPrint', and deprecated '\$LogPrintExit2'. Please update custom scripts if you use it.";
|
123="Introduced new function '\$LogPrint', and deprecated '\$LogPrintExit2'. Please update custom scripts if you use it.";
|
||||||
124="Added support for links in 'netwatch-notify', these are added below the formatted notification text.";
|
124="Added support for links in 'netwatch-notify', these are added below the formatted notification text.";
|
||||||
125=("April's Fool! " . [ $SymbolForNotification "smiley-partying-face" ] . "Well, you missed it... - no charge nor fees. (Anyway... Donations are much appreciated, " . [ $SymbolForNotification "smiley-smiling-face" ] . "thanks!)");
|
125=("April's Fool! " . [ $SymbolForNotification "smiley-partying-face" ] . "Well, you missed it... - no charge nor fees. (Anyway... Donations are much appreciated, " . [ $SymbolForNotification "smiley-smiling-face" ] . "thanks!)");
|
||||||
|
126="Made 'telegram-chat' capable of handling large command output. Telegram messages still limit the size, so it is truncated now.";
|
||||||
};
|
};
|
||||||
|
|
||||||
# Migration steps to be applied on script updates
|
# Migration steps to be applied on script updates
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
# Copyright (c) 2023-2024 Christian Hesse <mail@eworm.de>
|
# Copyright (c) 2023-2024 Christian Hesse <mail@eworm.de>
|
||||||
# https://git.eworm.de/cgit/routeros-scripts/about/COPYING.md
|
# https://git.eworm.de/cgit/routeros-scripts/about/COPYING.md
|
||||||
#
|
#
|
||||||
# requires RouterOS, version=7.12
|
# requires RouterOS, version=7.13
|
||||||
#
|
#
|
||||||
# use Telegram to chat with your Router and send commands
|
# use Telegram to chat with your Router and send commands
|
||||||
# https://git.eworm.de/cgit/routeros-scripts/about/doc/telegram-chat.md
|
# https://git.eworm.de/cgit/routeros-scripts/about/doc/telegram-chat.md
|
||||||
|
@ -141,14 +141,13 @@
|
||||||
:if ([ :len [ /file/find where name=($File . ".failed") ] ] > 0) do={
|
:if ([ :len [ /file/find where name=($File . ".failed") ] ] > 0) do={
|
||||||
:set State ([ $SymbolForNotification "cross-mark" ] . "The command failed with an error!\n\n");
|
:set State ([ $SymbolForNotification "cross-mark" ] . "The command failed with an error!\n\n");
|
||||||
}
|
}
|
||||||
:local Content [ /file/get $File contents ];
|
:local Content ([ /file/read chunk-size=32768 file=$File as-value ]->"data");
|
||||||
$SendTelegram2 ({ origin=$ScriptName; chatid=($Chat->"id"); silent=true; replyto=($Message->"message_id"); \
|
$SendTelegram2 ({ origin=$ScriptName; chatid=($Chat->"id"); silent=true; replyto=($Message->"message_id"); \
|
||||||
subject=([ $SymbolForNotification "speech-balloon" ] . "Telegram Chat"); \
|
subject=([ $SymbolForNotification "speech-balloon" ] . "Telegram Chat"); \
|
||||||
message=([ $SymbolForNotification "gear" ] . "Command:\n" . $Message->"text" . "\n\n" . \
|
message=([ $SymbolForNotification "gear" ] . "Command:\n" . $Message->"text" . "\n\n" . \
|
||||||
$State . [ $IfThenElse ([ :len $Content ] > 0) \
|
$State . [ $IfThenElse ([ :len $Content ] > 0) \
|
||||||
([ $SymbolForNotification "memo" ] . "Output:\n" . $Content) [ $IfThenElse ([ /file/get $File size ] > 0) \
|
([ $SymbolForNotification "memo" ] . "Output:\n" . $Content) \
|
||||||
([ $SymbolForNotification "warning-sign" ] . "Output exceeds file read size.") \
|
([ $SymbolForNotification "memo" ] . "No output.") ]) });
|
||||||
([ $SymbolForNotification "memo" ] . "No output.") ] ]) });
|
|
||||||
/file/remove "tmpfs/telegram-chat";
|
/file/remove "tmpfs/telegram-chat";
|
||||||
} else={
|
} else={
|
||||||
$LogPrint info $ScriptName ("The command from update " . $UpdateID . " failed syntax validation!");
|
$LogPrint info $ScriptName ("The command from update " . $UpdateID . " failed syntax validation!");
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue