forked from noXplode/aiogram_calendar
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexample_bot.py
31 lines (22 loc) · 1.16 KB
/
example_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
import logging
from aiogram import Bot, Dispatcher
from aiogram.types import Message, CallbackQuery, ReplyKeyboardRemove
from aiogram.utils import executor
from aiogramcalendar import calendar_callback, create_calendar, process_calendar_selection
API_TOKEN = '' # insert your telegram bot API key here
# Configure logging
logging.basicConfig(level=logging.INFO)
# Initialize bot and dispatcher
bot = Bot(token=API_TOKEN)
dp = Dispatcher(bot)
# starting bot when user sends `/start` command, answering with inline calendar
@dp.message_handler(commands=['start'])
async def cmd_start(message: Message):
await message.answer("Please select a date: ", reply_markup=create_calendar())
@dp.callback_query_handler(calendar_callback.filter()) # handler is processing only calendar_callback queries
async def process_name(callback_query: CallbackQuery, callback_data: dict):
selected, date = await process_calendar_selection(callback_query, callback_data)
if selected:
await callback_query.message.answer(f'You selected {date.strftime("%d/%m/%Y")}', reply_markup=ReplyKeyboardRemove())
if __name__ == '__main__':
executor.start_polling(dp, skip_updates=True)