-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtele_interface.py
More file actions
64 lines (48 loc) · 1.92 KB
/
tele_interface.py
File metadata and controls
64 lines (48 loc) · 1.92 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
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
import telegram
from telegram import InlineKeyboardButton, InlineKeyboardMarkup
import time
pp = telegram.utils.request.Request(proxy_url='socks5://103.216.82.206:6667')
auth_token = '417489646:AAGLf-uoQ_ZoIUBmiBTEa-7yHNmKiRQv44E'
bot = telegram.Bot(token=auth_token, request=pp)
id = '-343921014'
def send_image(img, caption = 'Visitor detected'):
# img - image in bytes
bot.send_photo(chat_id=id, photo=img, caption = caption)
def build_menu(buttons,
n_cols,
header_buttons=None,
footer_buttons=None):
menu = [buttons[i:i + n_cols] for i in range(0, len(buttons), n_cols)]
if header_buttons:
menu.insert(0, [header_buttons])
if footer_buttons:
menu.append([footer_buttons])
return menu
def send_prompt():
button_list = [
InlineKeyboardButton("Yes", callback_data='yes'),
InlineKeyboardButton("No", callback_data='no')
]
reply_markup = InlineKeyboardMarkup(build_menu(button_list, n_cols=2))
bot.send_message(id, "Do you want to allow the visitor inside?",
reply_markup=reply_markup)
def get_menu_response(last_id):
updates = bot.get_updates(limit=1, offset=-1, timeout=120)
if updates == []:
return '', last_id
recent_update = [update for update in updates if update.update_id is not last_id][0]
if recent_update.update_id != last_id:
last_id = recent_update.update_id
else:
return '', last_id
message = recent_update.callback_query.data
return message, last_id
if __name__ == '__main__':
send_prompt()
# bot.send_message(id, 'hi')
# last_id = 0
# while True:
# updates = bot.get_updates(limit=1, offset=-1, timeout=20)
# recent_update = [update for update in updates if update.update_id is not last_id][0]
# last_id = recent_update.update_id
# message = last_id.callback_query.data