-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
70 lines (54 loc) · 2.45 KB
/
main.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
60
61
62
63
64
65
66
67
68
69
70
import constants as const
from telegram.ext import *
import responses as R
import telegram
import api_calls as api
import display as dy
import os
PORT = int(os.environ.get('PORT', '8443'))
TOKEN = const.API_KEY
print('Bot started ...')
bot = telegram.Bot(token=const.API_KEY)
print (bot.getMe())
print (api.getDate())
def start_command(update, context):
bot.send_message(update.message.chat.id, const.welcome_message)
def help_command(update, context):
bot.send_message(update.message.chat.id, const.help_message)
def pin_command(update, context):
bot.send_message(update.message.chat.id, const.findByPin_message)
def calendar_command(update,context):
bot.send_message(update.message.chat.id, const.findCalendarByPin_message)
def handle_message(update, context):
text = str(update.message.text).lower()
response = R.sample_responses(text)
if isinstance(response, list):
for i in response:
if i == response[-1]:
bot.send_message(update.message.chat.id, i + '\nBook your vaccination now at : https://www.cowin.gov.in/home')
else:
bot.send_chat_action(chat_id = update.message.chat.id, action= telegram.ChatAction.TYPING)
bot.send_message(update.message.chat.id, i)
else:
bot.send_chat_action(chat_id = update.message.chat.id, action= telegram.ChatAction.TYPING)
update.message.reply_text(response)
def error(update, context):
print(f"Update {update} caused error {context.error}")
def main():
updater = Updater(const.API_KEY, use_context=True)
dp = updater.dispatcher #dispatcher
dp.add_handler(CommandHandler("start", start_command))
dp.add_handler(CommandHandler("help", help_command))
dp.add_handler(CommandHandler("pin", pin_command))
dp.add_handler(CommandHandler("calendar", calendar_command))
dp.add_handler(MessageHandler(Filters.text, handle_message))
dp.add_error_handler(error)
#Start the bot
updater.start_webhook(listen="0.0.0.0",
port=PORT,
url_path=TOKEN,
webhook_url='https://stark-castle-26205.herokuapp.com/' + const.API_KEY)
#updater.bot.setWebhook('https://peaceful-atoll-46044.herokuapp.com/' + const.API_KEY)
# updater.start_polling() #command that starts the programme. If want time delay before taking next input from user, use : updater.start_polling(5) (means delay of 5 seconds)
updater.idle()
main()