mirror of
https://github.com/python-telegram-bot/python-telegram-bot.git
synced 2024-11-22 15:17:00 +01:00
36d49ea9cd
* Render-fixes for BP * docs: fix simple typo, submition -> submission (#2260) There is a small typo in tests/test_bot.py. Should read `submission` rather than `submition`. * Type on rawapibot.py docstring * typo * Typo: Filters.document(s) * Typo fix * Doc fix for messageentity (#2311) * Add New Shortcuts to Chat (#2291) * Add shortcuts * Add a note * Add run_async Parameter to ConversationHandler (#2292) * Add run_async parameter * Update docstring * Update test to explicitly specify parameter * Fix test job queue * Add version added tag to docs * Update docstring Co-authored-by: Poolitzer <25934244+Poolitzer@users.noreply.github.com> * Doc nitpicking Co-authored-by: Poolitzer <25934244+Poolitzer@users.noreply.github.com> Co-authored-by: Hinrich Mahler <hinrich.mahler@freenet.de> * Fix rendering in messageentity Co-authored-by: Bibo-Joshi <hinrich.mahler@freenet.de> Co-authored-by: zeshuaro <joshuaystang@gmail.com> Co-authored-by: Poolitzer <25934244+Poolitzer@users.noreply.github.com> * fix: type hints for TelegramError changed :class:`telegram.TelegramError` to :class:`telegram.error.TelegramError` * fix: the error can be more then just a Telegram error * Doc fix for inlinekeyboardbutton.py added missing colon which broke rendering * fix: remove context argument and doc remark look at us already being in post 12 * use rtd badge * filters doc fixes * fix some rendering * Doc & Rendering fixes for helpers.py Co-authored-by: Tim Gates <tim.gates@iress.com> Co-authored-by: Harshil <37377066+harshil21@users.noreply.github.com> Co-authored-by: zeshuaro <joshuaystang@gmail.com> Co-authored-by: Poolitzer <25934244+Poolitzer@users.noreply.github.com> Co-authored-by: Harshil <ilovebhagwan@gmail.com>
65 lines
1.9 KiB
Python
65 lines
1.9 KiB
Python
#!/usr/bin/env python
|
|
# pylint: disable=W0613, C0116
|
|
# type: ignore[union-attr]
|
|
# This program is dedicated to the public domain under the CC0 license.
|
|
|
|
"""
|
|
Basic example for a bot that uses inline keyboards.
|
|
"""
|
|
import logging
|
|
|
|
from telegram import InlineKeyboardButton, InlineKeyboardMarkup, Update
|
|
from telegram.ext import Updater, CommandHandler, CallbackQueryHandler, CallbackContext
|
|
|
|
logging.basicConfig(
|
|
format='%(asctime)s - %(name)s - %(levelname)s - %(message)s', level=logging.INFO
|
|
)
|
|
logger = logging.getLogger(__name__)
|
|
|
|
|
|
def start(update: Update, context: CallbackContext) -> None:
|
|
keyboard = [
|
|
[
|
|
InlineKeyboardButton("Option 1", callback_data='1'),
|
|
InlineKeyboardButton("Option 2", callback_data='2'),
|
|
],
|
|
[InlineKeyboardButton("Option 3", callback_data='3')],
|
|
]
|
|
|
|
reply_markup = InlineKeyboardMarkup(keyboard)
|
|
|
|
update.message.reply_text('Please choose:', reply_markup=reply_markup)
|
|
|
|
|
|
def button(update: Update, context: CallbackContext) -> None:
|
|
query = update.callback_query
|
|
|
|
# CallbackQueries need to be answered, even if no notification to the user is needed
|
|
# Some clients may have trouble otherwise. See https://core.telegram.org/bots/api#callbackquery
|
|
query.answer()
|
|
|
|
query.edit_message_text(text=f"Selected option: {query.data}")
|
|
|
|
|
|
def help_command(update: Update, context: CallbackContext) -> None:
|
|
update.message.reply_text("Use /start to test this bot.")
|
|
|
|
|
|
def main():
|
|
# Create the Updater and pass it your bot's token.
|
|
updater = Updater("TOKEN")
|
|
|
|
updater.dispatcher.add_handler(CommandHandler('start', start))
|
|
updater.dispatcher.add_handler(CallbackQueryHandler(button))
|
|
updater.dispatcher.add_handler(CommandHandler('help', help_command))
|
|
|
|
# Start the Bot
|
|
updater.start_polling()
|
|
|
|
# Run the bot until the user presses Ctrl-C or the process receives SIGINT,
|
|
# SIGTERM or SIGABRT
|
|
updater.idle()
|
|
|
|
|
|
if __name__ == '__main__':
|
|
main()
|