-
Notifications
You must be signed in to change notification settings - Fork 2
/
telegram.py
33 lines (28 loc) · 953 Bytes
/
telegram.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import requests
class Telegram:
"""Класс телеграм бота."""
def __init__(self, data):
self.chat_id = data.get('chat_id')
self.endpoint = data.get('endpoint')
self.token = data.get('token')
self.message = ''
self.data = {}
def check_tokens(self):
"""Проверяет наличие всех переменных окружения."""
return all((
self.chat_id,
self.endpoint,
self.token,
))
def send_message(self, message):
"""Отправляет сообщение в телеграм."""
self.message = message
self.data = {
'url': self.endpoint.format(token=self.token),
'data': {
'chat_id': self.chat_id,
'text': self.message,
'parse_mode': 'markdown',
},
}
requests.post(**self.data)