def main(): """Start the bot.""" # Bale Bot Authorization Token updater = Updater("TOKEN") # Get the dispatcher to register handlers dp = updater.dispatcher # on different commands - answer in Bale dp.add_handler(CommandHandler("start", start)) dp.add_handler(CommandHandler("help", help)) # on noncommand i.e message - echo the message on Bale dp.add_handler(MessageHandler(DefaultFilter(), echo)) # log all errors dp.add_error_handler(error) # Start the Bot updater.run()
@dispatcher.command_handler(["/start"]) def conversation_starter(bot, update): message = TextMessage("Hi , nice to meet you :)\nplease send me a photo") user_peer = update.get_effective_user() bot.send_message(message, user_peer, success_callback=success, failure_callback=failure) dispatcher.register_conversation_next_step_handler( update, MessageHandler(PhotoFilter(), purchase_message)) @dispatcher.message_handler(PhotoFilter()) def purchase_message(bot, update): message = update.get_effective_message() user_peer = update.get_effective_user() first_purchase_message = PurchaseMessage( msg=message, account_number=6037991067471130, amount=10, money_request_type=MoneyRequestType.normal) bot.send_message(first_purchase_message, user_peer, success_callback=success, failure_callback=failure) dispatcher.finish_conversation(update) updater.run()
use get_file_download_url() and take a token from server. """ print("upload was successful : ", result) print(user_data) url = user_data.get("url", None) url_message = TextMessage(url) bot.send_message(url_message, user_peer, success_callback=success, failure_callback=failure) message = TextMessage("Uploading ...") user_peer = update.get_effective_user() bot.send_message(message, user_peer, success_callback=success, failure_callback=failure) bot.upload_file(file="../files/upload_file_test.jpeg", file_type="file", success_callback=file_upload_success, failure_callback=failure) message = TextMessage("Uploading is finish.\nyou can try this link and see nothing show to you\n" "finish conversion with below command\n" "[/finish](send:/finish)") bot.send_message(message, user_peer, success_callback=success, failure_callback=failure) dispatcher.register_conversation_next_step_handler(update, CommandHandler("/finish", finish_conversion)) def finish_conversion(bot, update): message = TextMessage("Thanks \ngoodbye ;)") user_peer = update.get_effective_user() bot.send_message(message, user_peer, success_callback=success, failure_callback=failure) dispatcher.finish_conversation(update) updater.run()