-
Notifications
You must be signed in to change notification settings - Fork 4
/
telegram_helper.py
32 lines (23 loc) · 928 Bytes
/
telegram_helper.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
from telegram.error import BadRequest
ADMIN_CHAT_ID = 123456789 # Your chat id
ADMIN_FIRST_NAME = "Your_telegram_first_name"
ADMIN_LAST_NAME = "Your_telegram_last_name"
def utf8len(s):
return len(s.encode('utf-8'))
def is_admin_texting(update):
if update.message.chat_id == ADMIN_CHAT_ID and \
update.message.from_user.first_name == "Deve" and \
update.message.from_user.last_name == "Scie":
return True
else:
return False
def replay_to_user(bot, update, message):
try:
bot.send_message(chat_id=update.message.chat_id, text=message)
except BadRequest as e:
bot.send_message(chat_id=update.message.chat_id, text=e.message)
def send_message_to_admin(bot, message):
try:
bot.send_message(chat_id=ADMIN_CHAT_ID, text=message)
except BadRequest as e:
bot.send_message(chat_id=ADMIN_CHAT_ID, text=e.message)