summaryrefslogtreecommitdiff
path: root/src/home/telegram/telegram.py
diff options
context:
space:
mode:
authorEvgeny Zinoviev <me@ch1p.io>2023-06-10 22:44:31 +0300
committerEvgeny Zinoviev <me@ch1p.io>2023-06-10 22:44:31 +0300
commitf3b9d50496257d87757802dfb472b5ffae11962c (patch)
tree7e77ddaf3a00c467024c41333fcaa99db9da3876 /src/home/telegram/telegram.py
parent3790c2205396cf860738f297e6ddc49cd2b2a03f (diff)
new config: port openwrt_log_analyzer
Diffstat (limited to 'src/home/telegram/telegram.py')
-rw-r--r--src/home/telegram/telegram.py28
1 files changed, 15 insertions, 13 deletions
diff --git a/src/home/telegram/telegram.py b/src/home/telegram/telegram.py
index 2f94f93..f42363e 100644
--- a/src/home/telegram/telegram.py
+++ b/src/home/telegram/telegram.py
@@ -2,25 +2,27 @@ import requests
import logging
from typing import Tuple
-from ..config import config
-
+from .config import TelegramChatsConfig
+_chats = TelegramChatsConfig()
_logger = logging.getLogger(__name__)
def send_message(text: str,
- parse_mode: str = None,
- disable_web_page_preview: bool = False):
- data, token = _send_telegram_data(text, parse_mode, disable_web_page_preview)
+ chat: str,
+ parse_mode: str = 'HTML',
+ disable_web_page_preview: bool = False,):
+ data, token = _send_telegram_data(text, chat, parse_mode, disable_web_page_preview)
req = requests.post('https://api.telegram.org/bot%s/sendMessage' % token, data=data)
return req.json()
-def send_photo(filename: str):
+def send_photo(filename: str, chat: str):
+ chat_data = _chats[chat]
data = {
- 'chat_id': config['telegram']['chat_id'],
+ 'chat_id': chat_data['id'],
}
- token = config['telegram']['token']
+ token = chat_data['token']
url = f'https://api.telegram.org/bot{token}/sendPhoto'
with open(filename, "rb") as fd:
@@ -29,19 +31,19 @@ def send_photo(filename: str):
def _send_telegram_data(text: str,
+ chat: str,
parse_mode: str = None,
disable_web_page_preview: bool = False) -> Tuple[dict, str]:
+ chat_data = _chats[chat]
data = {
- 'chat_id': config['telegram']['chat_id'],
+ 'chat_id': chat_data['id'],
'text': text
}
if parse_mode is not None:
data['parse_mode'] = parse_mode
- elif 'parse_mode' in config['telegram']:
- data['parse_mode'] = config['telegram']['parse_mode']
- if disable_web_page_preview or 'disable_web_page_preview' in config['telegram']:
+ if disable_web_page_preview:
data['disable_web_page_preview'] = 1
- return data, config['telegram']['token']
+ return data, chat_data['token']