feat(telegram): add ability to specify multiple chat_ids (#335)
Co-authored-by: Florian Lottes <florian.lottes@etailer.de>
This commit is contained in:
parent
2a8f448a65
commit
856a900528
2 changed files with 18 additions and 15 deletions
plugins/telegram
|
@ -32,7 +32,7 @@ server configuration file or as environment variables.
|
|||
```python
|
||||
PLUGINS = ['telegram']
|
||||
TELEGRAM_TOKEN = '' # default="not set"
|
||||
TELEGRAM_CHAT_ID = '' # default="not set"
|
||||
TELEGRAM_CHAT_ID = '' # default="not set", specify multiple ID's separated by comma
|
||||
TELEGRAM_TEMPLATE = '' # default will use hardcoded one (can be a filename to template file)
|
||||
TELEGRAM_PROXY = '' # default="not set", URL must start from http://, socks5 not supported
|
||||
TELEGRAM_PROXY_USERNAME = '' # default="not set"
|
||||
|
|
|
@ -112,21 +112,24 @@ class TelegramBot(PluginBase):
|
|||
|
||||
LOG.debug('Telegram: post_receive sendMessage disable_notification=%s', str(disable_notification))
|
||||
|
||||
try:
|
||||
response = self.bot.sendMessage(TELEGRAM_CHAT_ID,
|
||||
text,
|
||||
parse_mode='Markdown',
|
||||
disable_notification=disable_notification,
|
||||
reply_markup=keyboard)
|
||||
except telepot.exception.TelegramError as e:
|
||||
raise RuntimeError("Telegram: ERROR - %s, description= %s, json=%s",
|
||||
e.error_code,
|
||||
e.description,
|
||||
e.json)
|
||||
except Exception as e:
|
||||
raise RuntimeError("Telegram: ERROR - %s", e)
|
||||
chat_ids = TELEGRAM_CHAT_ID.split(",")
|
||||
for chat_id in chat_ids:
|
||||
try:
|
||||
response = self.bot.sendMessage(chat_id,
|
||||
text,
|
||||
parse_mode='Markdown',
|
||||
disable_notification=disable_notification,
|
||||
reply_markup=keyboard)
|
||||
except telepot.exception.TelegramError as e:
|
||||
raise RuntimeError("Telegram (ChatId: %s): ERROR - %s, description= %s, json=%s",
|
||||
chat_id,
|
||||
e.error_code,
|
||||
e.description,
|
||||
e.json)
|
||||
except Exception as e:
|
||||
raise RuntimeError("Telegram: ERROR - %s", e)
|
||||
|
||||
LOG.debug('Telegram: %s', response)
|
||||
LOG.debug('Telegram (ChatId: %s): %s', chat_id, response)
|
||||
|
||||
def status_change(self, alert, status, summary):
|
||||
return
|
||||
|
|
Loading…
Add table
Reference in a new issue