-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtelegram_bot.py
More file actions
32 lines (24 loc) · 968 Bytes
/
telegram_bot.py
File metadata and controls
32 lines (24 loc) · 968 Bytes
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 import Bot
from telegram.ext import Updater, CommandHandler
class TelegramBot:
def __init__(self, API_TOKEN):
self.API_TOKEN = API_TOKEN
self.updater = Updater(self.API_TOKEN)
self.bot = Bot(self.API_TOKEN)
self.ADMINS = []
def start(self):
self.updater.start_polling()
self.updater.idle()
def stop(self):
self.updater.stop()
def add_handler(self, hot_phrase, callback):
#TODO:add shortcut to telegram
self.updater.dispatcher.add_handler(CommandHandler(hot_phrase, callback))
def remove_handler(self, hot_phrase):
try:
del self.updater.dispatcher.handlers[hot_phrase]
except LookupError:
print("element " + str(hot_phrase) + " doesn't exist.")
def notify_users(self):
for admin in self.ADMINS:
self.bot.send_message(chat_id=admin, text="I'm sorry Dave I'm afraid I can't let you do that.")