mirror of
https://github.com/eworm-de/routeros-scripts.git
synced 2025-08-04 02:04:45 +02:00
mod/notification-telegram: introduce $GetTelegramChatId
This commit is contained in:
parent
4eafcaa3ac
commit
53b13b295a
5 changed files with 52 additions and 9 deletions
BIN
doc/mod/notification-telegram.d/getchatid.avif
Normal file
BIN
doc/mod/notification-telegram.d/getchatid.avif
Normal file
Binary file not shown.
After Width: | Height: | Size: 3.8 KiB |
|
@ -38,14 +38,21 @@ create your own bot:
|
|||
|
||||

|
||||
|
||||
Now open a chat with your bot and start it by clicking the `START` button.
|
||||
Set that token from *BotFather* (use your own!) to `TelegramTokenId`, for
|
||||
now just temporarily:
|
||||
|
||||
Open just another chat with [GetIDs Bot](https://t.me/getidsbot), again start
|
||||
with the `START` button. It will send you some information, including the
|
||||
`id`, just below `You`.
|
||||
:set TelegramTokenId "5214364459:AAHLwf1o7ybbKDo6pY24Kd2bZ5rjCakDXTc";
|
||||
|
||||
Now open a chat with your bot and start it by clicking the `START` button,
|
||||
then send your first message. Any text will do. On your device run
|
||||
`$GetTelegramChatId` to retrieve the chat id:
|
||||
|
||||
$GetTelegramChatId;
|
||||
|
||||

|
||||
|
||||
Finally edit `global-config-overlay`, add `TelegramTokenId` with the token
|
||||
from *BotFather* and `TelegramChatId` with your id from *GetIDs Bot*. Then
|
||||
from *BotFather* and `TelegramChatId` with your retrieved chat id. Then
|
||||
reload the configuration.
|
||||
|
||||
> ℹ️ **Info**: Copy relevant configuration from
|
||||
|
@ -54,9 +61,10 @@ reload the configuration.
|
|||
|
||||
### Notifications to a group
|
||||
|
||||
Sending notifications to a group is possible as well. Add your bot and the
|
||||
*GetIDs Bot* to a group, then use the group's id (which starts with a dash)
|
||||
for `TelegramChatId`. Then remove *GetIDs Bot* from group.
|
||||
Sending notifications to a group is possible as well. Add your bot to a group
|
||||
and make it an admin (required for read access!) and send a message and run
|
||||
`$GetTelegramChatId` again. Then use that chat id (which starts with a dash)
|
||||
for `TelegramChatId`.
|
||||
|
||||
Groups can enable the `Topics` feature. Use `TelegramThreadId` to send to a
|
||||
specific topic in a group.
|
||||
|
|
|
@ -15,7 +15,7 @@
|
|||
# Git commit id & info, expected configuration version
|
||||
:global CommitId "unknown";
|
||||
:global CommitInfo "unknown";
|
||||
:global ExpectedConfigVersion 134;
|
||||
:global ExpectedConfigVersion 135;
|
||||
|
||||
# global variables not to be changed by user
|
||||
:global GlobalFunctionsReady false;
|
||||
|
|
|
@ -10,6 +10,7 @@
|
|||
# https://rsc.eworm.de/doc/mod/notification-telegram.md
|
||||
|
||||
:global FlushTelegramQueue;
|
||||
:global GetTelegramChatId;
|
||||
:global NotificationFunctions;
|
||||
:global PurgeTelegramQueue;
|
||||
:global SendTelegram;
|
||||
|
@ -58,6 +59,39 @@
|
|||
:global ExitError; $ExitError false $0;
|
||||
} }
|
||||
|
||||
# get the chat id
|
||||
:set GetTelegramChatId do={ :do {
|
||||
:global TelegramTokenId;
|
||||
|
||||
:global CertificateAvailable;
|
||||
:global LogPrint;
|
||||
|
||||
:if ([ $CertificateAvailable "Go Daddy Root Certificate Authority - G2" ] = false) do={
|
||||
$LogPrint warning $0 ("Downloading required certificate failed.");
|
||||
:return false;
|
||||
}
|
||||
|
||||
:local Data;
|
||||
:do {
|
||||
:set Data ([ /tool/fetch check-certificate=yes-without-crl output=user \
|
||||
("https://api.telegram.org/bot" . $TelegramTokenId . "/getUpdates?offset=0" . \
|
||||
"&allowed_updates=%5B%22message%22%5D") as-value ]->"data");
|
||||
} on-error={
|
||||
$LogPrint warning $0 ("Fetching data failed!");
|
||||
:return false;
|
||||
}
|
||||
|
||||
:local JSON [ :deserialize from=json value=$Data ];
|
||||
:foreach Update in=($JSON->"result") do={
|
||||
$LogPrint info $0 ("The chat id is: " . ($Update->"message"->"chat"->"id"));
|
||||
:return true;
|
||||
}
|
||||
|
||||
$LogPrint info $0 ("No message received.");
|
||||
} on-error={
|
||||
:global ExitError; $ExitError false $0;
|
||||
} }
|
||||
|
||||
# send notification via telegram - expects one array argument
|
||||
:set ($NotificationFunctions->"telegram") do={
|
||||
:local Notification $1;
|
||||
|
|
|
@ -59,6 +59,7 @@
|
|||
132="Split off plugins from 'check-health', so the script works on all devices to monitor CPU and RAM. The supported plugins for sensors in hardware are installed automatically.";
|
||||
133="Updated the default configuration for 'fw-addr-lists', deprecated lists were removed, a collective list was added.";
|
||||
134="Enhanced 'mod/notification-telegram' and 'telegram-chat' to support topics in groups.";
|
||||
135="Introduced helper function '\$GetTelegramChatId' for 'mod/notification-telegram' which helps retrieve information.";
|
||||
};
|
||||
|
||||
# Migration steps to be applied on script updates
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue