-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbot.py
59 lines (40 loc) · 1.59 KB
/
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
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
import os
from telegram.ext import Updater, ConversationHandler, CommandHandler, MessageHandler, Filters
INITIAl, MIDDLE, FINAL = range(3)
def start(bot, updater):
updater.message.reply_text('Hello')
return INITIAl
def say_hello(bot, updater):
updater.message.reply_text('I am in INITIAL state')
return MIDDLE
def say_howdy(bot, updater):
updater.message.reply_text('I am in MIDDLE state')
return FINAL
def say_good_bye(bot, updater):
updater.message.reply_text('I am in FINAL state, goodbye')
def cancel(bot, updater):
updater.message.reply_text('Good bye')
return ConversationHandler.END
def help(bot, updater):
updater.message.reply_text('Bot started')
def main():
TOKEN = os.environ['TELEGRAM_TOKEN']
PORT = int(os.environ.get('PORT', '8443'))
updater = Updater(TOKEN)
dispatcher = updater.dispatcher
command = CommandHandler('help', help)
conv_handler = ConversationHandler(
entry_points=[CommandHandler('start', start)],
states= { INITIAl: [MessageHandler(Filters.text, say_hello), CommandHandler('init', start)],
MIDDLE: [MessageHandler(Filters.text, say_howdy)],
FINAL: [MessageHandler(Filters.text, say_good_bye)]},
fallbacks= [CommandHandler('cancel', cancel)]
)
dispatcher.add_handler(conv_handler)
dispatcher.add_handler(command)
# updater.start_polling()
updater.start_webhook(listen="0.0.0.0", port=PORT, url_path=TOKEN)
updater.bot.set_webhook("https://zethumanbot.herokuapp.com/" + TOKEN)
updater.idle()
if __name__ == '__main__':
main()