change telegram default index to telegram-index

This commit is contained in:
2022-04-08 04:06:38 +03:00
parent f01af5f54a
commit fb7275f9dd
8 changed files with 13 additions and 14 deletions

View File

@ -38,6 +38,7 @@ class Telegram(Report, JinjaTemplate):
:ivar api_key: bot api key
:ivar chat_id: chat id to post message, either string with @ or integer
:ivar template_path: path to template for built packages
:ivar template_type: template message type to be used in parse mode, one of MarkdownV2, HTML, Markdown
"""
TELEGRAM_API_URL = "https://api.telegram.org"
@ -56,6 +57,7 @@ class Telegram(Report, JinjaTemplate):
self.api_key = configuration.get(section, "api_key")
self.chat_id = configuration.get(section, "chat_id")
self.template_path = configuration.getpath(section, "template_path")
self.template_type = configuration.get(section, "template_type", fallback="HTML")
def _send(self, text: str) -> None:
"""
@ -65,7 +67,7 @@ class Telegram(Report, JinjaTemplate):
try:
response = requests.post(
f"{self.TELEGRAM_API_URL}/bot{self.api_key}/sendMessage",
data={"chat_id": self.chat_id, "text": text})
data={"chat_id": self.chat_id, "text": text, "parse_mode": self.template_type})
response.raise_for_status()
except requests.HTTPError as e:
self.logger.exception("could not perform request: %s", exception_response_text(e))