- Saved searches
- Use saved searches to filter your results more quickly
- License
- grcanosa/telegram-calendar-keyboard
- Name already in use
- Sign In Required
- Launching GitHub Desktop
- Launching GitHub Desktop
- Launching Xcode
- Launching Visual Studio Code
- Latest commit
- Git stats
- Files
- README.md
- Getting Started
- Advanced use
- Several calendars
- Date ranges
- Custom style
- Custom Translation
- Examples
- Contributing
- Authors
- License
- Saved searches
- Use saved searches to filter your results more quickly
- License
- purgy/telebot-calendar
- Name already in use
- Sign In Required
- Launching GitHub Desktop
- Launching GitHub Desktop
- Launching Xcode
- Launching Visual Studio Code
- Latest commit
- Git stats
- Files
- README.md
- Saved searches
- Use saved searches to filter your results more quickly
- License
- unmonoqueteclea/calendar-telegram
- Name already in use
- Sign In Required
- Launching GitHub Desktop
- Launching GitHub Desktop
- Launching Xcode
- Launching Visual Studio Code
- Latest commit
- Git stats
- Files
- README.md
Saved searches
Use saved searches to filter your results more quickly
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session. You switched accounts on another tab or window. Reload to refresh your session.
A simple inline calendar for Telegram bots
License
grcanosa/telegram-calendar-keyboard
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Sign In Required
Please sign in to use Codespaces.
Launching GitHub Desktop
If nothing happens, download GitHub Desktop and try again.
Launching GitHub Desktop
If nothing happens, download GitHub Desktop and try again.
Launching Xcode
If nothing happens, download Xcode and try again.
Launching Visual Studio Code
Your codespace will open once ready.
There was a problem preparing your codespace, please try again.
Latest commit
Git stats
Files
Failed to load latest commit information.
README.md
Date Selection tool for Telegram Bots
A simple inline calendar for Telegram bots written in Python using python-telegram-bot. Based on calendar-telegram.
The file telegramcalendar.py proved the API to create an inline keyboard for a Telegram Bot. The user can either select a date or move to the next or previous month by clicking a singe button.
The file telegramcalendar.py provides the user with two methods:
- create_calendar: This method returns a InlineKeyboardMarkup object with the calendar in the provided year and month.
- process_calendar_selection: This method can be used inside a CallbackQueryHandler method to check if the user has selected a date or wants to move to a different month. It also creates a new calendar with the same text if necessary.
To use the telecram-calendar-keyboard you need to have python-telegram-bot installed first. A full working example on how to use telegram-calendar-keyboard is provided in bot_example.py. As you can see below, you create a calendar and add it to a message with a reply_markup parameter and then you can process it in a callbackqueyhandler method using the process_calendar_selection method:
def calendar_handler(bot,update): update.message.reply_text("Please select a date: ", reply_markup=telegramcalendar.create_calendar()) def inline_handler(bot,update): selected,date = telegramcalendar.process_calendar_selection(bot, update) if selected: bot.send_message(chat_id=update.callback_query.from_user.id, text="You selected %s" % (date.strftime("%d/%m/%Y")), reply_markup=ReplyKeyboardRemove())
For a more complex example please check out renfe-notifier-bot
Getting Started
There is one main class — DetailedTelegramCalendar that can be used as follows. This is the example for pyTelegramBotAPI library. Other libraries are also supported.
In start handler the calendar is created. Several arguments can be passed:
- calendar_id — small integer or string, used for calendar identification. It used when you need several different calendars (default — 0)
- current_date — datetime.date object, initial date value (default — today date)
- additional_buttons — 1D list of buttons that will be added to the bottom of the calendar
- locale — either en , ru , or eo , can be added more
- min_date and max_date — both are used as min and max values for the calendar
As you can see, special function that is provided should be passed to callback query handler. It will automatically work. The function takes only one argument — calendar_id that is 0 by default.
In the body of the handler function you need to call process function on callback data. WARNING! You need to create the calendar object again if it was not saved before.
The function process return tuple of size 3 — result , keyboard , step .
- result — datetime.date object if user finished selecting. Otherwise None
- keyboard — inline keyboard markup if the result is not ready. Otherwise None
- step — YEAR , MONTH , or DAY if not ready. None is also possible if there is no change in keyboard.
Advanced use
Several calendars
You can create as many calendars as you want. However, in order to handle them properly set different calendar_id’s when you want to distinguish them. Take a look at examples.
Date ranges
In the class constructor min_date and max_date — both are used as min and max values for the calendar. If you add them, the calendar will not show undesired dates. Example:
Custom style
You can also write your own code. One of the examples is redefining the steps order.
In the package you can find WMonthTelegramCalendar and WYearTelegramCalendar that start from day and month selecting, not from year.
You can also redefine style parameters. Example:
Custom Translation
Examples
- simple_pytelegrambotapi.py — simple example with pyTelegramBotAPI
- simple_aiogram.py — simple example with aiogram
- simple_telethon.py — simple example with telethon
- custom_translation.py — custom translation of calendar
- date_ranges.py — define date ranges for the bot
- redefine_style.py — simple example of redefining styles
- several_calendars.py — several calendars in one bot
Contributing
Contributions are what make the open source community such an amazing place to be learn, inspire, and create. Any contributions you make are greatly appreciated.
- Fork the Project
- Create your Feature Branch ( git checkout -b feature/yourFeature )
- Commit your Changes ( git commit -m ‘Add some yourFeature’ )
- Push to the Branch ( git push origin feature/yourFeature )
- Open a Pull Request
Authors
License
This project is licensed under the MIT License — see the LICENSE file for details
Saved searches
Use saved searches to filter your results more quickly
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session. You switched accounts on another tab or window. Reload to refresh your session.
Telegram bot inline keyboard calendar
License
purgy/telebot-calendar
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Sign In Required
Please sign in to use Codespaces.
Launching GitHub Desktop
If nothing happens, download GitHub Desktop and try again.
Launching GitHub Desktop
If nothing happens, download GitHub Desktop and try again.
Launching Xcode
If nothing happens, download Xcode and try again.
Launching Visual Studio Code
Your codespace will open once ready.
There was a problem preparing your codespace, please try again.
Latest commit
Git stats
Files
Failed to load latest commit information.
README.md
Inline calendar for Telebot
pip install telebot-calendar
The file telebot_calendar.py used to create, modify, and retrieve user data from an inline keyboard calendar created by the user.
To use the telebot_calendar you need to have Telebot installed first. Working example.py
@bot.message_handler(commands=["start"]) def check_other_messages(message): """ Catches a message with the command "start" and sends the calendar :param message: :return: """ now = datetime.datetime.now() # Get the current date bot.send_message( message.chat.id, "Selected date", reply_markup=telebot_calendar.create_calendar( name=calendar_1.prefix, year=now.year, month=now.month, # Specify the NAME of your calendar ), ) @bot.callback_query_handler(func=lambda call: call.data.startswith(calendar_1.prefix)) def callback_inline(call: CallbackQuery): """ Обработка inline callback запросов :param call: :return: """ # At this point, we are sure that this calendar is ours. So we cut the line by the separator of our calendar name, action, year, month, day = call.data.split(calendar_1.sep) # Processing the calendar. Get either the date or None if the buttons are of a different type date = telebot_calendar.calendar_query_handler( bot=bot, call=call, name=name, action=action, year=year, month=month, day=day ) # There are additional steps. Let's say if the date DAY is selected, you can execute your code. I sent a message. if action == "DAY": bot.send_message( chat_id=call.from_user.id, text=f"You have chosen date.strftime('%d.%m.%Y')>", reply_markup=ReplyKeyboardRemove(), ) print(f"calendar_1>: Day: date.strftime('%d.%m.%Y')>") elif action == "CANCEL": bot.send_message( chat_id=call.from_user.id, text="Cancellation", reply_markup=ReplyKeyboardRemove(), ) print(f"calendar_1>: Cancellation")
Saved searches
Use saved searches to filter your results more quickly
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session. You switched accounts on another tab or window. Reload to refresh your session.
A simple inline calendar for Telegram bots
License
unmonoqueteclea/calendar-telegram
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Sign In Required
Please sign in to use Codespaces.
Launching GitHub Desktop
If nothing happens, download GitHub Desktop and try again.
Launching GitHub Desktop
If nothing happens, download GitHub Desktop and try again.
Launching Xcode
If nothing happens, download Xcode and try again.
Launching Visual Studio Code
Your codespace will open once ready.
There was a problem preparing your codespace, please try again.
Latest commit
Git stats
Files
Failed to load latest commit information.
README.md
Date Selection tool for Telegram Bots
A simple inline calendar for Telegram bots written in Python using python-telegram-bot. Based on calendar-telegram.
The file telegramcalendar.py proved the API to create an inline keyboard for a Telegram Bot. The user can either select a date or move to the next or previous month by clicking a singe button.
The file telegramcalendar.py provides the user with two methods:
- create_calendar: This method returns a InlineKeyboardMarkup object with the calendar in the provided year and month.
- process_calendar_selection: This method can be used inside a CallbackQueryHandler method to check if the user has selected a date or wants to move to a different month. It also creates a new calendar with the same text if necessary.
To use the telecram-calendar-keyboard you need to have python-telegram-bot installed first. A full working example on how to use telegram-calendar-keyboard is provided in bot_example.py. As you can see below, you create a calendar and add it to a message with a reply_markup parameter and then you can process it in a callbackqueyhandler method using the process_calendar_selection method:
def calendar_handler(bot,update): update.message.reply_text("Please select a date: ", reply_markup=telegramcalendar.create_calendar()) def inline_handler(bot,update): selected,date = telegramcalendar.process_calendar_selection(bot, update) if selected: bot.send_message(chat_id=update.callback_query.from_user.id, text="You selected %s" % (date.strftime("%d/%m/%Y")), reply_markup=ReplyKeyboardRemove())
For a more complex example please check out renfe-notifier-bot