Skip to content

Instantly share code, notes, and snippets.

@alisher-matkurbanov
Last active March 27, 2019 12:00
Show Gist options
  • Save alisher-matkurbanov/3898a6d192c5eb047c0b38fcbdb7cf15 to your computer and use it in GitHub Desktop.
Save alisher-matkurbanov/3898a6d192c5eb047c0b38fcbdb7cf15 to your computer and use it in GitHub Desktop.
import telegram
from telegram.ext import Updater, CallbackQueryHandler, MessageHandler, Filters, ConversationHandler, PrefixHandler
import logging
logging.basicConfig(
format='%(asctime)s - %(name)s - %(levelname)s - %(message)s',
level=logging.DEBUG
)
TOKEN = ""
MAIN = "MAIN"
INLINE = "INLINE"
MIDDLE = "MIDDLE"
def start_callback(update, context):
m = telegram.InlineKeyboardMarkup([
[telegram.InlineKeyboardButton(text='variant 1', callback_data='1')],
[telegram.InlineKeyboardButton(text='variant 1', callback_data='2')]
])
context.bot.send_message(
update.message.from_user.id,
text='Start',
reply_markup=m
)
return INLINE
def inline_callback(update, context):
context.bot.send_message(
update.message.from_user.id,
text='message will not be sent'
)
return ConversationHandler.END
conv = ConversationHandler(
entry_points=[PrefixHandler('/', 'start', start_callback)],
states={
INLINE: [CallbackQueryHandler('[0-9]', inline_callback)]
},
fallbacks=[]
)
def main():
updater = Updater(token=TOKEN, use_context=True)
dispatcher = updater.dispatcher
dispatcher.add_handler(conv)
updater.start_polling()
updater.idle()
if __name__ == "__main__":
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment