feat(telegram): add ability to specify multiple chat_ids ()

Co-authored-by: Florian Lottes <florian.lottes@etailer.de>
This commit is contained in:
flottes 2021-01-06 23:20:56 +01:00 committed by GitHub
parent 2a8f448a65
commit 856a900528
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 18 additions and 15 deletions

View file

@ -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"

View file

@ -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