current_alerts
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revision | Next revisionBoth sides next revision | ||
current_alerts [2021/11/03 14:19] – [GetCurrentAlerts()] emozolyak | current_alerts [2022/01/04 10:25] – [GetCurrentAlerts()] emozolyak | ||
---|---|---|---|
Line 56: | Line 56: | ||
end -- for | end -- for | ||
end -- tprint | end -- tprint | ||
+ | </ | ||
+ | |||
+ | === Example of sending Telegram messages upon new alerts === | ||
+ | |||
+ | Below is the example of how to send Telegram messages when the alert count has increased: | ||
+ | <code lua> | ||
+ | --[[ | ||
+ | Checks if number of alerts has increased and then sends message via | ||
+ | Telegram | ||
+ | --]] | ||
+ | TELEGRAM_BOT_ID = " | ||
+ | active_alerts = 0 | ||
+ | |||
+ | function main (userId) | ||
+ | | ||
+ | local alerts = GetCurrentAlerts() | ||
+ | | ||
+ | if (#alerts > active_alerts) then -- number has increased | ||
+ | local a_names = {} | ||
+ | |||
+ | for a_num, a in ipairs(alerts) do | ||
+ | INFO(" | ||
+ | table.insert(a_names, | ||
+ | end | ||
+ | a_names = table.concat(a_names, | ||
+ | SendTelegramMessage(TELEGRAM_BOT_ID, | ||
+ | end | ||
+ | | ||
+ | active_alerts = #alerts | ||
+ | | ||
+ | end | ||
</ | </ | ||
current_alerts.txt · Last modified: 2022/07/04 12:35 by emozolyak