forked from unmonoqueteclea/calendar-telegram
-
Notifications
You must be signed in to change notification settings - Fork 0
/
bot_example.py
executable file
·48 lines (32 loc) · 1.58 KB
/
bot_example.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
#!/usr/bin/python3
import logging
from telegram.ext import Updater,CallbackQueryHandler,CommandHandler
from telegram import ReplyKeyboardRemove,ParseMode
import telegramcalendar
# Go to botfather and create a bot and copy the token and paste it here in token
TOKEN = "" # token of the bot
logging.basicConfig(format='%(asctime)s - %(name)s - %(levelname)s - %(message)s',
level=logging.INFO)
logger = logging.getLogger(__name__)
def start(update,context):
context.bot.send_message(chat_id=update.message.chat_id,text="Hey {}! I am calender bot \n \n Please type /calendar to view my power".format(update.message.from_user.first_name),parse_mode=ParseMode.HTML)
# A simple command to display the calender
def calendar_handler(update,context):
update.message.reply_text(text="Please select a date: ",
reply_markup=telegramcalendar.create_calendar())
def inline_handler(update,context):
selected,date = telegramcalendar.process_calendar_selection(update,context)
if selected:
context.bot.send_message(chat_id=update.callback_query.from_user.id,
text="You selected %s" % (date.strftime("%d/%m/%Y")),
reply_markup=ReplyKeyboardRemove())
if TOKEN == "":
print("Please write TOKEN into file")
else:
updater = Updater(TOKEN,use_context=True)
dp=updater.dispatcher
dp.add_handler(CommandHandler("start",start))
dp.add_handler(CommandHandler("calendar",calendar_handler))
dp.add_handler(CallbackQueryHandler(inline_handler))
updater.start_polling()
updater.idle()