Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from telegram import (ReplyKeyboardMarkup, ReplyKeyboardRemove, InlineKeyboardButton, InlineKeyboardMarkup, CallbackQuery)
- from telegram.ext import (Updater, CommandHandler, MessageHandler, Filters, RegexHandler,
- ConversationHandler, CallbackQueryHandler)
- import logging
- # Enable logging
- logging.basicConfig(format='%(asctime)s - %(name)s - %(levelname)s - %(message)s',
- level=logging.INFO)
- logger = logging.getLogger(__name__)
- USERNAME, PASSWORD = range(2)
- def start(bot, update):
- reply_keyboard = [['Boy', 'Girl', 'Other']]
- update.message.reply_text(
- 'Hi! I am a bot. I will hold a conversation with you. '
- 'Send /cancel to stop talking to me.\n\n'
- 'I will log you into classeviva!\n\n'
- 'Send me your username or email!')
- return USERNAME
- def username(bot, update):
- button_list = [[InlineKeyboardButton("Riprova", callback_data='riprova')]]
- reply_retry = InlineKeyboardMarkup(button_list)
- user = update.message.from_user
- logger.info("Username of %s: %s", user.first_name, update.message.text)
- update.message.reply_text('If it is correct send me you password',
- reply_markup=reply_retry)
- if update.callback_query.data == 'riprova':
- return USERNAME
- else:
- return PASSWORD
- def password(bot, update):
- user = update.message.from_user
- logger.info("Password of %s: %s", user.first_name, update.message.text)
- def cancel(bot, update):
- user = update.message.from_user
- logger.info("User %s canceled the conversation.", user.first_name)
- update.message.reply_text('Bye! I hope we can talk again some day.',
- reply_markup=ReplyKeyboardRemove())
- return ConversationHandler.END
- def error(bot, update, error):
- """Log Errors caused by Updates."""
- logger.warning('Update "%s" caused error "%s"', update, error)
- def main():
- updater = Updater("")
- dp = updater.dispatcher
- conv_handler = ConversationHandler(
- entry_points=[CommandHandler('start', start)],
- states={
- USERNAME: [MessageHandler(Filters.text, us LOCATION, BIOername),
- CallbackQueryHandler(username, pass_user_data=True)],
- PASSWORD: [MessageHandler(Filters.text, password)],
- },
- fallbacks=[CommandHandler('cancel', cancel)]
- )
- dp.add_handler(conv_handler)
- dp.add_error_handler(error)
- updater.start_polling()
- updater.idle()
- if __name__ == '__main__':
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement