-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtgReciver.py
87 lines (74 loc) · 2.1 KB
/
tgReciver.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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
import logging
from aiogram import Bot, Dispatcher, executor, types
from main import main
from config import tgToken
# Configure logging
logging.basicConfig(level=logging.INFO)
# Initialize bot and dispatcher
bot = Bot(token=tgToken)
dp = Dispatcher(bot)
@dp.message_handler(commands=['start'])
async def start_reciver(message: types.Message):
# print(message)
event = 'start'
task = {
'message_id': message['message_id'],
'channel': 'telegram',
'chat_id': message['from']['id'],
'event': event,
'message': {
'type': 'text',
'text': message['text']
},
'user': {
'channel': 'telegram',
'chat_id': message['from']['id'],
'first_name': message['from']['first_name'],
'username': message['from']['username']
}
}
await main(task, bot)
@dp.message_handler(regexp=r'^\/start\s\w+')
async def start_with_contex_reciver(message: types.Message):
event = 'context'
task = {
'message_id': message['message_id'],
'channel': 'telegram',
'chat_id': message['from']['id'],
'event': event,
'message': {
'type': 'text',
'text': message['text']
}
}
await main(task, bot)
@dp.message_handler(regexp=r'^\/\w+')
async def command_reciver(message: types.Message):
event = 'command'
task = {
'message_id': message['message_id'],
'channel': 'telegram',
'chat_id': message['from']['id'],
'event': event,
'message': {
'type': 'text',
'text': message['text']
}
}
await main(task, bot)
@dp.message_handler()
async def tg_reciver(message: types.Message):
event = 'text'
task = {
'message_id': message['message_id'],
'channel': 'telegram',
'chat_id': message['from']['id'],
'event': event,
'message': {
'type': 'text',
'text': message['text']
}
}
await main(task, bot)
if __name__ == '__main__':
executor.start_polling(dp, skip_updates=True)