-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbot.py
More file actions
34 lines (26 loc) · 1.01 KB
/
bot.py
File metadata and controls
34 lines (26 loc) · 1.01 KB
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
34
import aiohttp
from urllib.parse import quote
class TelegramBot:
"""Main class for manage telegram bot"""
def __init__(self, token):
"""Init function for class
Args:
token (str): Token for telegram bot
"""
self.token: str = token
async def send_message(self, text: str, chat_id: int, **kwargs) -> dict:
"""sendMessage method for send messages
Args:
text (str): The text of message
chat_id (int): Chat id where send message
**kwargs: Any arguments applied to sendMessage
Returns:
dict: Json answer from telegram
"""
async with aiohttp.ClientSession(
headers={"Accept": "application/json"}
) as session:
url = f"https://api.telegram.org/bot{str(self.token)}/sendMessage"
params = {"chat_id": chat_id, "text": text, **kwargs}
async with session.post(url, json=params) as response:
return await response.json()