-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathtelegram-bot.py
34 lines (25 loc) · 902 Bytes
/
telegram-bot.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
from telegram.ext import Updater, CommandHandler
from engine import get_random_quote
# Your bot token (from BotFather)
token = "YOUR TOKEN HERE"
def start(bot, update):
bot.sendMessage(chat_id=update.message.chat_id, text=("Hi %s. Send me /quote command to get a random quote from "
"me!" %
update.message.from_user.name))
def quote(bot, update):
bot.sendMessage(chat_id=update.message.chat_id,
text=get_random_quote())
def main():
updater = Updater(token);
dp = updater.dispatcher
# Define all the commands that the bot will receive
dp.add_handler(CommandHandler("start", start))
dp.add_handler(CommandHandler("quote", quote))
# Start the bot
updater.start_polling()
print("================================")
print("========= Bot Running ==========")
print("================================")
updater.idle()
if __name__ == "__main__":
main()