Skip to content

Commit bf84a53

Browse files
committed
add test_alert cmd
1 parent d73259b commit bf84a53

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

modules/alert_bot.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,8 @@ def __init__(self, ton, local, *args, **kwargs):
8989
def send_message(self, text: str):
9090
if self.token is None:
9191
raise Exception("send_message error: token is not initialized")
92+
if self.chat_id is None:
93+
raise Exception("send_message error: chat_id is not initialized")
9294
request_url = f"https://api.telegram.org/bot{self.token}/sendMessage"
9395
data = {'chat_id': self.chat_id, 'text': text, 'parse_mode': 'HTML'}
9496
response = requests.post(request_url, data=data, timeout=3)
@@ -183,6 +185,9 @@ def print_alerts(self, args):
183185
table.append([alert_name, alert['enabled'], alert['sent']])
184186
print_table(table)
185187

188+
def test_alert(self, args):
189+
self.send_message('Test alert')
190+
186191
def check_db_usage(self):
187192
usage = self.ton.GetDbUsage()
188193
if usage > 95:
@@ -266,3 +271,4 @@ def add_console_commands(self, console):
266271
console.AddItem("enable_alert", self.enable_alert, self.local.translate("enable_alert_cmd"))
267272
console.AddItem("disable_alert", self.disable_alert, self.local.translate("disable_alert_cmd"))
268273
console.AddItem("list_alerts", self.print_alerts, self.local.translate("list_alerts_cmd"))
274+
console.AddItem("test_alert", self.test_alert, self.local.translate("test_alert_cmd"))

mytonctrl/resources/translate.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -479,6 +479,11 @@
479479
"ru": "Список всех доступных оповещений через Telegram Bot",
480480
"zh_TW": "列出所有可用的 Telegram Bot 警報"
481481
},
482+
"test_alert_cmd": {
483+
"en": "Send test alert via Telegram Bot",
484+
"ru": "Отправить тестовое оповещение через Telegram Bot",
485+
"zh_TW": "通過 Telegram Bot 發送測試警報"
486+
},
482487
"cleanup_cmd": {
483488
"en": "Clean node old logs and temp files",
484489
"ru": "Очистить старые логи и временные файлы ноды",

0 commit comments

Comments
 (0)