Skip to content

Instantly share code, notes, and snippets.

@chrenova
Created May 24, 2018 14:52
Show Gist options
  • Select an option

  • Save chrenova/fa8cd91cfb57c9e1dfc7050f2ea49e38 to your computer and use it in GitHub Desktop.

Select an option

Save chrenova/fa8cd91cfb57c9e1dfc7050f2ea49e38 to your computer and use it in GitHub Desktop.
import logging
logging.basicConfig(level=logging.INFO)
from telegram.ext import Updater
from telegram import InlineKeyboardButton, InlineKeyboardMarkup
from telegram.ext import CallbackQueryHandler
TOKEN = ''
updater = Updater(token=TOKEN)
dispatcher = updater.dispatcher
def create_markup():
button_list = [
[InlineKeyboardButton("12:00 Hlavna stanica -> Opavska", callback_data='1')],
[InlineKeyboardButton("12:10 Hlavna stanica -> Autobusova stanica", callback_data='2')],
[InlineKeyboardButton("12:15 Opavska -> Hlavna stanica", callback_data='3')]
]
reply_markup = InlineKeyboardMarkup(button_list)
return reply_markup
def start(bot, update):
bot.send_message(chat_id=update.message.chat_id, text="I'm a bot, please talk to me!")
reply_markup = create_markup()
#update.message.reply_text('Please choose:', reply_markup=reply_markup)
bot.send_message(chat_id=update.message.chat_id, text=None, reply_markup=reply_markup)
def button(bot, update):
query = update.callback_query
reply_markup = create_markup()
bot.edit_message_text(text="Selected option: %s" % query.data,
chat_id=query.message.chat_id,
message_id=query.message.message_id, reply_markup=reply_markup)
def echo(bot, update):
logging.info(update.message)
bot.send_message(chat_id=update.message.chat_id, text=update.message.text)
from telegram.ext import MessageHandler, Filters
echo_handler = MessageHandler(Filters.location, echo)
dispatcher.add_handler(echo_handler)
from telegram.ext import CommandHandler
start_handler = CommandHandler('start', start)
dispatcher.add_handler(start_handler)
dispatcher.add_handler(CallbackQueryHandler(button))
updater.start_polling()
updater.idle()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment