def test_pass_user_or_chat_data(self, dp, shiping_query): handler = ShippingQueryHandler(self.callback_data_1, pass_user_data=True) dp.add_handler(handler) dp.process_update(shiping_query) assert self.test_flag dp.remove_handler(handler) handler = ShippingQueryHandler(self.callback_data_1, pass_chat_data=True) dp.add_handler(handler) self.test_flag = False dp.process_update(shiping_query) assert self.test_flag dp.remove_handler(handler) handler = ShippingQueryHandler(self.callback_data_2, pass_chat_data=True, pass_user_data=True) dp.add_handler(handler) self.test_flag = False dp.process_update(shiping_query) assert self.test_flag
def test_pass_job_or_update_queue(self, dp, shiping_query): handler = ShippingQueryHandler(self.callback_queue_1, pass_job_queue=True) dp.add_handler(handler) dp.process_update(shiping_query) assert self.test_flag dp.remove_handler(handler) handler = ShippingQueryHandler(self.callback_queue_1, pass_update_queue=True) dp.add_handler(handler) self.test_flag = False dp.process_update(shiping_query) assert self.test_flag dp.remove_handler(handler) handler = ShippingQueryHandler(self.callback_queue_2, pass_job_queue=True, pass_update_queue=True) dp.add_handler(handler) self.test_flag = False dp.process_update(shiping_query) assert self.test_flag
def test_basic(self, dp, shiping_query): handler = ShippingQueryHandler(self.callback_basic) dp.add_handler(handler) assert handler.check_update(shiping_query) dp.process_update(shiping_query) assert self.test_flag
def test_slot_behaviour(self, recwarn, mro_slots): inst = ShippingQueryHandler(self.callback_basic) for attr in inst.__slots__: assert getattr(inst, attr, 'err') != 'err', f"got extra slot '{attr}'" assert not inst.__dict__, f"got missing slot(s): {inst.__dict__}" assert len(mro_slots(inst)) == len(set(mro_slots(inst))), "duplicate slot" inst.custom, inst.callback = 'should give warning', self.callback_basic assert len(recwarn) == 1 and 'custom' in str(recwarn[0].message), recwarn.list
async def test_context(self, app, shiping_query): handler = ShippingQueryHandler(self.callback) app.add_handler(handler) async with app: await app.process_update(shiping_query) assert self.test_flag
def test_slot_behaviour(self, mro_slots): inst = ShippingQueryHandler(self.callback) for attr in inst.__slots__: assert getattr(inst, attr, "err") != "err", f"got extra slot '{attr}'" assert len(mro_slots(inst)) == len(set( mro_slots(inst))), "duplicate slot"
def main(): # Create the EventHandler and pass it your bot's token. updater = Updater(token="534849104:AAHGnCHl4Q3u-PauqDZ1tspUdoWzH702QQc") # Get the dispatcher to register handlers dp = updater.dispatcher # simple start function dp.add_handler(CommandHandler("start", start_callback)) # Add command handler to start the payment invoice dp.add_handler(CommandHandler("shipping", start_with_shipping_callback)) dp.add_handler(CommandHandler("noshipping", start_without_shipping_callback)) # Optional handler if your product requires shipping dp.add_handler(ShippingQueryHandler(shipping_callback)) # Pre-checkout handler to final check dp.add_handler(PreCheckoutQueryHandler(precheckout_callback)) # Success! Notify your user! dp.add_handler(MessageHandler(Filters.successful_payment, successful_payment_callback)) # log all errors dp.add_error_handler(error) # Start the Bot updater.start_polling() # Run the bot until you press Ctrl-C or the process receives SIGINT, # SIGTERM or SIGABRT. This should be used most of the time, since # start_polling() is non-blocking and will stop the bot gracefully. updater.idle()
def main(): # Create the Updater and pass it your bot's token. # 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(config.TOKEN, use_context=True) # Get the dispatcher to register handlers dispatcher = updater.dispatcher # simple start function dispatcher.add_handler(CommandHandler("start", start)) # Add command handler to start the payment invoice dispatcher.add_handler(CommandHandler("shipping", pay)) # Optional handler if your product requires shipping dispatcher.add_handler(ShippingQueryHandler(shipping_callback)) # Pre-checkout handler to final check dispatcher.add_handler(PreCheckoutQueryHandler(precheckout_callback)) # Success! Notify your user! dispatcher.add_handler( MessageHandler(Filters.successful_payment, successful_payment_callback)) # Start the Bot updater.start_polling() # Run the bot until you press Ctrl-C or the process receives SIGINT, # SIGTERM or SIGABRT. This should be used most of the time, since # start_polling() is non-blocking and will stop the bot gracefully. updater.idle()
def main() -> None: """Run the bot.""" # Create the Application and pass it your bot's token. application = Application.builder().token("TOKEN").build() # simple start function application.add_handler(CommandHandler("start", start_callback)) # Add command handler to start the payment invoice application.add_handler( CommandHandler("shipping", start_with_shipping_callback)) application.add_handler( CommandHandler("noshipping", start_without_shipping_callback)) # Optional handler if your product requires shipping application.add_handler(ShippingQueryHandler(shipping_callback)) # Pre-checkout handler to final check application.add_handler(PreCheckoutQueryHandler(precheckout_callback)) # Success! Notify your user! application.add_handler( MessageHandler(filters.SUCCESSFUL_PAYMENT, successful_payment_callback)) # Run the bot until the user presses Ctrl-C application.run_polling()
def main() -> None: """Run the bot.""" # Create the Updater and pass it your bot's token. updater = Updater("TOKEN") # Get the dispatcher to register handlers dispatcher = updater.dispatcher # simple start function dispatcher.add_handler(CommandHandler("start", start_callback)) # Add command handler to start the payment invoice dispatcher.add_handler( CommandHandler("shipping", start_with_shipping_callback)) dispatcher.add_handler( CommandHandler("noshipping", start_without_shipping_callback)) # Optional handler if your product requires shipping dispatcher.add_handler(ShippingQueryHandler(shipping_callback)) # Pre-checkout handler to final check dispatcher.add_handler(PreCheckoutQueryHandler(precheckout_callback)) # Success! Notify your user! dispatcher.add_handler( MessageHandler(Filters.successful_payment, successful_payment_callback)) # Start the Bot updater.start_polling() # Run the bot until you press Ctrl-C or the process receives SIGINT, # SIGTERM or SIGABRT. This should be used most of the time, since # start_polling() is non-blocking and will stop the bot gracefully. updater.idle()
def main(): dp = DjangoTelegramBot.dispatcher dp.add_handler(CommandHandler("start", start)) dp.add_handler(CallbackQueryHandler(add_to_basket)) dp.add_handler(MessageHandler(Filters.text, text_processing)) # Optional handler if your product requires shipping dp.add_handler(ShippingQueryHandler(shipping_callback)) # Pre-checkout handler to final check dp.add_handler(PreCheckoutQueryHandler(precheckout_callback)) # Success! Notify your user! dp.add_handler( MessageHandler(Filters.successful_payment, successful_payment_callback)) dp.add_error_handler(error)
def main(): # Optional handler if your product requires shipping dp.add_handler(ShippingQueryHandler(shipping_callback)) # Pre-checkout handler to final check dp.add_handler(PreCheckoutQueryHandler(precheckout_callback)) # Success! Notify your user! dp.add_handler( MessageHandler(Filters.successful_payment, successful_payment_callback)) dp.add_handler( CallbackQueryHandler(mostrar_donacion, pattern="^donation_new-\d*")) dp.add_handler( CallbackQueryHandler(start_without_shipping_callback, pattern="^donate-\d*")) # Start the Bot updater.start_polling()
def add_handlers(updater): dp = updater.dispatcher # simple start function dp.add_handler(CommandHandler('start', start_callback)) dp.add_handler(RegexHandler("start", start_callback)) dp.add_handler(CallbackQueryHandler(start_callback, pattern='start')) # Add command handler to start the payment invoice dp.add_handler(CommandHandler("shipping", start_with_shipping_callback)) dp.add_handler( CommandHandler("noshipping", start_without_shipping_callback)) # Optional handler if your product requires shipping dp.add_handler(ShippingQueryHandler(shipping_callback)) # Pre-checkout handler to final check dp.add_handler(PreCheckoutQueryHandler(precheckout_callback)) # Success! Notify your user! dp.add_handler( MessageHandler(Filters.successful_payment, successful_payment_callback))
def main(): updater = Updater("443645682:AAFjUhUmNIicWQxpgZP-fQWOVC3OF-EkvVk") dp = updater.dispatcher updater.dispatcher.add_handler(CommandHandler('start', start)) updater.dispatcher.add_handler(CommandHandler('random', randomBook)) updater.dispatcher.add_handler(RegexHandler('^/info_\d+', moreInfo)) updater.dispatcher.add_handler( CallbackQueryHandler(download, pattern='^downloadAfterMoreInfo_\d+')) conv_handler = ConversationHandler( entry_points=[CommandHandler('search', search)], states={ 0: [MessageHandler(Filters.text, sendResults)], 1: [RegexHandler('^/info_\d+', moreInfo)], 2: [ CallbackQueryHandler(download, pattern='^downloadAfterMoreInfo_\d+') ], 3: [PreCheckoutQueryHandler(precheckout)], 4: [ShippingQueryHandler(sendPaidPdf)] }, fallbacks=[CommandHandler('cancel', done)]) dp.add_handler(conv_handler) updater.start_polling() updater.idle()
def main(): load_dotenv() global redis_conn redis_conn = redis.Redis(host=os.getenv('REDIS_HOST'), password=os.getenv('REDIS_PASSWORD'), port=os.getenv('REDIS_PORT'), db=0, decode_responses=True) updater = Updater(token=os.getenv("TG_TOKEN"), use_context=True) dispatcher = updater.dispatcher dispatcher.add_error_handler(error_handler) dispatcher.add_handler(CallbackQueryHandler(handle_users_reply)) dispatcher.add_handler(MessageHandler(Filters.text, handle_users_reply)) dispatcher.add_handler(PreCheckoutQueryHandler(precheckout_callback)) dispatcher.add_handler(ShippingQueryHandler(shipping_callback)) dispatcher.add_handler( MessageHandler(Filters.successful_payment, successful_payment_callback)) dispatcher.add_handler(MessageHandler(Filters.location, handle_users_reply)) dispatcher.add_handler(CommandHandler('start', handle_users_reply)) updater.start_polling()
show_upcoming_events_handler = CommandHandler('show_upcoming_events', show_upcoming_events) dispatcher.add_handler(show_upcoming_events_handler) add_friend_handler = CommandHandler('add_friend', add_friend) dispatcher.add_handler(add_friend_handler) # Add command handler to start the payment invoice dispatcher.add_handler(CommandHandler("shipping", start_with_shipping_callback)) dispatcher.add_handler( CommandHandler("noshipping", start_without_shipping_callback)) # Optional handler if your product requires shipping dispatcher.add_handler(ShippingQueryHandler(shipping_callback)) # Pre-checkout handler to final check dispatcher.add_handler(PreCheckoutQueryHandler(precheckout_callback)) # Success! Notify your user! dispatcher.add_handler( MessageHandler(Filters.successful_payment, successful_payment_callback)) # log all errors dispatcher.add_error_handler(error) echo_handler = MessageHandler(Filters.text, respond) dispatcher.add_handler(echo_handler) logger.info("Start polling")
def test_context(self, cdp, shiping_query): handler = ShippingQueryHandler(self.callback_context) cdp.add_handler(handler) cdp.process_update(shiping_query) assert self.test_flag
def test_other_update_types(self, false_update): handler = ShippingQueryHandler(self.callback_basic) assert not handler.check_update(false_update)