2016-04-16 20:32:44 +02:00
|
|
|
#!/usr/bin/env python
|
|
|
|
# -*- coding: utf-8 -*-
|
2017-10-20 20:24:00 +02:00
|
|
|
# This program is dedicated to the public domain under the CC0 license.
|
2019-02-13 13:38:07 +01:00
|
|
|
|
|
|
|
"""
|
|
|
|
Basic example for a bot that uses inline keyboards.
|
2017-10-20 20:24:00 +02:00
|
|
|
"""
|
2016-04-16 20:32:44 +02:00
|
|
|
import logging
|
2018-09-21 08:57:01 +02:00
|
|
|
|
2016-07-20 00:15:03 +02:00
|
|
|
from telegram import InlineKeyboardButton, InlineKeyboardMarkup
|
|
|
|
from telegram.ext import Updater, CommandHandler, CallbackQueryHandler
|
2016-04-16 20:32:44 +02:00
|
|
|
|
2016-05-23 22:45:01 +02:00
|
|
|
logging.basicConfig(format='%(asctime)s - %(name)s - %(levelname)s - %(message)s',
|
2016-07-20 00:15:03 +02:00
|
|
|
level=logging.INFO)
|
2017-10-20 20:24:00 +02:00
|
|
|
logger = logging.getLogger(__name__)
|
2016-04-16 20:32:44 +02:00
|
|
|
|
|
|
|
|
2018-09-21 08:57:01 +02:00
|
|
|
def start(update, context):
|
2016-07-20 00:15:03 +02:00
|
|
|
keyboard = [[InlineKeyboardButton("Option 1", callback_data='1'),
|
|
|
|
InlineKeyboardButton("Option 2", callback_data='2')],
|
2016-04-16 20:32:44 +02:00
|
|
|
|
2016-07-20 00:15:03 +02:00
|
|
|
[InlineKeyboardButton("Option 3", callback_data='3')]]
|
2016-04-16 20:32:44 +02:00
|
|
|
|
2016-07-20 00:15:03 +02:00
|
|
|
reply_markup = InlineKeyboardMarkup(keyboard)
|
2016-04-16 20:32:44 +02:00
|
|
|
|
2016-09-24 15:32:22 +02:00
|
|
|
update.message.reply_text('Please choose:', reply_markup=reply_markup)
|
2016-04-16 20:32:44 +02:00
|
|
|
|
|
|
|
|
2018-09-21 08:57:01 +02:00
|
|
|
def button(update, context):
|
2016-04-16 20:55:43 +02:00
|
|
|
query = update.callback_query
|
2016-07-20 00:15:03 +02:00
|
|
|
|
2018-09-21 08:57:01 +02:00
|
|
|
query.edit_message_text(text="Selected option: {}".format(query.data))
|
2016-04-16 20:32:44 +02:00
|
|
|
|
|
|
|
|
2018-09-21 08:57:01 +02:00
|
|
|
def help(update, context):
|
2016-09-24 15:32:22 +02:00
|
|
|
update.message.reply_text("Use /start to test this bot.")
|
2016-04-16 20:32:44 +02:00
|
|
|
|
|
|
|
|
2018-09-21 08:57:01 +02:00
|
|
|
def error(update, context):
|
2017-10-20 20:24:00 +02:00
|
|
|
"""Log Errors caused by Updates."""
|
2018-09-21 08:57:01 +02:00
|
|
|
logger.warning('Update "%s" caused error "%s"', update, context.error)
|
2017-10-20 20:24:00 +02:00
|
|
|
|
|
|
|
|
|
|
|
def main():
|
|
|
|
# Create the Updater and pass it your bot's token.
|
2018-09-21 08:57:01 +02:00
|
|
|
# Make sure to set use_context=True to use the new context based callbacks
|
|
|
|
# Post version 12 this will no longer be necessary
|
|
|
|
updater = Updater("TOKEN", use_context=True)
|
2016-04-16 20:32:44 +02:00
|
|
|
|
2017-10-20 20:24:00 +02:00
|
|
|
updater.dispatcher.add_handler(CommandHandler('start', start))
|
|
|
|
updater.dispatcher.add_handler(CallbackQueryHandler(button))
|
|
|
|
updater.dispatcher.add_handler(CommandHandler('help', help))
|
|
|
|
updater.dispatcher.add_error_handler(error)
|
2016-07-20 00:15:03 +02:00
|
|
|
|
2017-10-20 20:24:00 +02:00
|
|
|
# Start the Bot
|
|
|
|
updater.start_polling()
|
2016-04-16 20:32:44 +02:00
|
|
|
|
2017-10-20 20:24:00 +02:00
|
|
|
# Run the bot until the user presses Ctrl-C or the process receives SIGINT,
|
|
|
|
# SIGTERM or SIGABRT
|
|
|
|
updater.idle()
|
2016-04-16 20:32:44 +02:00
|
|
|
|
|
|
|
|
2017-10-20 20:24:00 +02:00
|
|
|
if __name__ == '__main__':
|
|
|
|
main()
|