def test_pass_user_or_chat_data(self, dp, pre_checkout_query): handler = PreCheckoutQueryHandler(self.callback_data_1, pass_user_data=True) dp.add_handler(handler) dp.process_update(pre_checkout_query) assert self.test_flag dp.remove_handler(handler) handler = PreCheckoutQueryHandler(self.callback_data_1, pass_chat_data=True) dp.add_handler(handler) self.test_flag = False dp.process_update(pre_checkout_query) assert self.test_flag dp.remove_handler(handler) handler = PreCheckoutQueryHandler(self.callback_data_2, pass_chat_data=True, pass_user_data=True) dp.add_handler(handler) self.test_flag = False dp.process_update(pre_checkout_query) assert self.test_flag
def test_basic(self, dp, pre_checkout_query): handler = PreCheckoutQueryHandler(self.callback_basic) dp.add_handler(handler) assert handler.check_update(pre_checkout_query) dp.process_update(pre_checkout_query) assert self.test_flag
def test_basic(self, dp, pre_checkout_query): handler = PreCheckoutQueryHandler(self.callback_basic) dp.add_handler(handler) assert handler.check_update(pre_checkout_query) dp.process_update(pre_checkout_query) assert self.test_flag
def test_pass_job_or_update_queue(self, dp, pre_checkout_query): handler = PreCheckoutQueryHandler(self.callback_queue_1, pass_job_queue=True) dp.add_handler(handler) dp.process_update(pre_checkout_query) assert self.test_flag dp.remove_handler(handler) handler = PreCheckoutQueryHandler(self.callback_queue_1, pass_update_queue=True) dp.add_handler(handler) self.test_flag = False dp.process_update(pre_checkout_query) assert self.test_flag dp.remove_handler(handler) handler = PreCheckoutQueryHandler(self.callback_queue_2, pass_job_queue=True, pass_update_queue=True) dp.add_handler(handler) self.test_flag = False dp.process_update(pre_checkout_query) assert self.test_flag
def test_slot_behaviour(self, recwarn, mro_slots): inst = PreCheckoutQueryHandler(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
def main(): coffee_bot = CoffeeBot() # API бота updater = Updater(token="718571818:AAE3kvTrfr9P7sUMeJAsMmVi7Tv8ghTAwC0") # Хэндлеры для выполнении функции при вводе определенных команда dp = updater.dispatcher # Старт dp.add_handler(CommandHandler("start", coffee_bot.start_callback)) # Заказ dp.add_handler(CommandHandler("order", coffee_bot.order)) dp.add_handler(CommandHandler("menu", coffee_bot.menu)) dp.add_handler(CommandHandler("choose", coffee_bot.choose)) # Заключительная проверка dp.add_handler(PreCheckoutQueryHandler(coffee_bot.precheckout_callback)) # Маршрутизатор нажатий кнопок после выбора /select_coffee dp.add_handler(CallbackQueryHandler(coffee_bot.select_menu_actions)) # Успешная оплата dp.add_handler( MessageHandler(Filters.successful_payment, coffee_bot.successful_payment_callback)) updater.start_polling()
def run_bot(): load_dotenv() logging.basicConfig( level=logging.INFO, format='%(levelname)s:%(name)s:%(message)s' ) logger.addHandler(LogsHandler()) req = {'proxy_url': 'https://158.69.62.161:3128/'} updater = Updater(os.getenv('TELEGRAM_TOKEN'), request_kwargs=req) # updater = Updater(os.getenv('TELEGRAM_TOKEN')) dispather = updater.dispatcher dispather.add_handler(CommandHandler('start', handle_users_reply)) dispather.add_handler(CallbackQueryHandler(handle_users_reply)) dispather.add_handler(MessageHandler(Filters.text, handle_users_reply)) dispather.add_handler(CommandHandler('start', handle_users_reply)) dispather.add_handler(PreCheckoutQueryHandler(handle_pre_checkout)) dispather.add_handler( MessageHandler( Filters.successful_payment, create_job_queue, pass_job_queue=True ) ) dispather.add_handler( MessageHandler( Filters.location, handle_users_reply, edited_updates=True ) ) updater.start_polling() logger.info('The bot is running')
def main(): updater = Updater(TOKEN, use_context=True) dp = updater.dispatcher dp.add_handler(CommandHandler('start', start)) dp.add_handler(CallbackQueryHandler(button)) dp.add_handler(CommandHandler('help', help_)) dp.add_handler(CommandHandler('myid', myid)) dp.add_handler(CommandHandler('subscription', subscription)) dp.add_handler(PreCheckoutQueryHandler(precheckout_callback)) dp.add_handler( MessageHandler(Filters.successful_payment, successful_payment_callback)) text_handler = MessageHandler(Filters.text, help_) dp.add_handler(text_handler) main_polling_thread = threading.Thread(target=updater.start_polling) unsubsribe_thread = threading.Thread(target=unsubscribe) mailing_thread = threading.Thread(target=mailing) main_polling_thread.start() unsubsribe_thread.start() mailing_thread.start() main_polling_thread.join() unsubsribe_thread.join() mailing_thread.join() updater.idle()
def main(): logging.basicConfig( format='%(asctime)s - %(name)s - %(levelname)s - %(message)s', level=logging.INFO, handlers=[LogsHandler()]) logger.info('(pizza) OdodoPizza запущен') load_dotenv() token = os.environ.get('TELEGRAM_BOT_TOKEN') updater = Updater(token) dispatcher = updater.dispatcher dispatcher.add_handler( CallbackQueryHandler(handle_users_reply, pass_job_queue=True)) dispatcher.add_handler( MessageHandler(Filters.location, handle_users_reply, pass_job_queue=True, edited_updates=True)) dispatcher.add_handler( MessageHandler(Filters.text, handle_users_reply, pass_job_queue=True)) dispatcher.add_handler( CommandHandler('start', handle_users_reply, pass_job_queue=True)) dispatcher.add_handler(PreCheckoutQueryHandler(handle_precheckout)) dispatcher.add_handler( MessageHandler(Filters.successful_payment, handle_successful_payment)) dispatcher.add_error_handler(handle_error) updater.start_polling()
def main(): load_dotenv() logging.basicConfig( format='%(asctime)s - %(name)s - %(levelname)s - %(message)s', level=logging.INFO) telegram_token = os.getenv('TELEGRAM_ACCESS_TOKEN') updater = Updater(telegram_token, use_context=True) dispatcher = updater.dispatcher dispatcher.add_handler( CallbackQueryHandler(handle_users_reply, pass_job_queue=True)) dispatcher.add_handler( MessageHandler(Filters.text, handle_users_reply, pass_job_queue=True)) dispatcher.add_handler(CommandHandler('start', start)) dispatcher.add_handler(MessageHandler(Filters.location, handle_users_reply)) dispatcher.add_handler( MessageHandler(Filters.regex('^(Вы)$'), handle_payment)) dispatcher.add_handler(PreCheckoutQueryHandler(precheckout_callback)) dispatcher.add_handler( MessageHandler(Filters.successful_payment, successful_payment_callback)) dispatcher.add_error_handler(error) updater.start_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() -> 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(): # 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()
async def test_context(self, app, pre_checkout_query): handler = PreCheckoutQueryHandler(self.callback) app.add_handler(handler) async with app: await app.process_update(pre_checkout_query) assert self.test_flag
def main(): updater = Updater(BOT_TOKEN) dispatcher = updater.dispatcher dispatcher.add_handler(InlineQueryHandler(inline_query)) dispatcher.add_handler(ChosenInlineResultHandler(chosen_result)) dispatcher.add_handler(CallbackQueryHandler(add_me_to_list, pattern="(si\*)|(puede\*)|(no\*)")) dispatcher.add_handler(CallbackQueryHandler(close_list, pattern="close\*")) dispatcher.add_handler(CallbackQueryHandler(change_donation_quantity, pattern=r"don\*", pass_user_data=True)) dispatcher.add_handler(CallbackQueryHandler(donate, pattern=r"donate$", pass_user_data=True)) dispatcher.add_handler(CallbackQueryHandler(callback_query_exception)) dispatcher.add_handler(CommandHandler("start", start_command, pass_args=True, pass_user_data=True)) dispatcher.add_handler(MessageHandler(filters=Filters.successful_payment, callback=completed_donation)) dispatcher.add_handler(PreCheckoutQueryHandler(aprove_transaction)) dispatcher.add_error_handler(error) updater.start_polling() # CONSOLA while True: inp = raw_input("") if inp: input_c = inp.split()[0] args = inp.split()[1:] strig = "" for e in args: strig = strig + " " + e if input_c == "stop": stopBot(updater) break else: print "Comando desconocido"
def test_slot_behaviour(self, mro_slots): inst = PreCheckoutQueryHandler(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 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(): global update_id TOKEN = os.environ['TOKEN'] updater = Updater(TOKEN, use_context=True) dp = updater.dispatcher #In source.py dp.add_handler(CommandHandler("Source", source, filters=~Filters.group)) dp.add_handler(CommandHandler("start", start, filters=~Filters.group)) dp.add_handler(CommandHandler("openbot", open_bot, filters=Filters.group)) dp.add_handler(CommandHandler("openday", open_day)) dp.add_handler(CommandHandler("endday", end_day)) dp.add_handler(CommandHandler("gpaday", gpa_day)) dp.add_handler(CommandHandler("date", important_date)) dp.add_handler(CommandHandler("checkTemp", checkTemp)) dp.add_handler(CommandHandler("samgor", samgor, pass_args=True)) #updater.dispatcher.add_handler(CallbackQueryHandler(button)) dp.add_handler(CommandHandler("Source", source, filters=~Filters.group)) dp.add_handler( MessageHandler(Filters.status_update.new_chat_members, newmember)) # dp.add_handler(CommandHandler("lecturer",lecturer,filters=~Filters.group)) #updater.dispatcher.add_handler(CallbackQueryHandler(rating)) ############ dp.add_handler(CommandHandler("help", help_command)) dp.add_handler(CommandHandler("addcanteen", addcanteen, pass_args=True)) dp.add_handler(CommandHandler("username", username, pass_args=True)) dp.add_handler(CommandHandler("donate", payment, pass_args=True)) dp.add_handler( MessageHandler(Filters.successful_payment, successful_payment_callback)) dp.add_handler(PreCheckoutQueryHandler(precheckout_callback)) dp.add_handler( CommandHandler("canteen", listCanteen, filters=~Filters.group)) dp.add_handler(CommandHandler("pin9", pin9, filters=Filters.group)) dp.add_handler(CommandHandler("week", week, filters=Filters.group)) dp.add_handler(CommandHandler("exam", exam, pass_args=True)) dp.add_handler(MessageHandler(Filters.text & ~Filters.group, showlocation)) updater.dispatcher.add_handler(CallbackQueryHandler(button)) #dp.add_handler(MessageHandler(Filters.text & Filters.group, dllm)) #dp.add_handler(CommandHandler("donateToMe",donateToMe,pass_args = True)) # Start the Bot updater.start_webhook(listen="0.0.0.0", port=int(PORT), url_path=TOKEN) updater.bot.setWebhook('https://serene-depths-59599.herokuapp.com/' + TOKEN) # 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(): """Start the context.bot.""" # Create the EventHandler and pass it your bot's token. updater = Updater(TELEGRAM_TOKEN) # Get the dispatcher to register handlers dp = updater.dispatcher # on different commands - answer in Telegram dp.add_handler(CommandHandler("start", start)) dp.add_handler(CommandHandler("help", help)) dp.add_handler(CommandHandler("license", license)) dp.add_handler(CommandHandler("dividend", dividend)) dp.add_handler(CommandHandler("div", dividend)) dp.add_handler(CommandHandler("news", news)) dp.add_handler(CommandHandler("info", information)) dp.add_handler(CommandHandler("stat", stat)) dp.add_handler(CommandHandler("stats", stat)) dp.add_handler(CommandHandler("cap", cap)) dp.add_handler(CommandHandler("trending", trending)) dp.add_handler(CommandHandler("search", search)) dp.add_handler(CommandHandler("random", rand_pick)) dp.add_handler(CommandHandler("donate", donate)) dp.add_handler(CommandHandler("status", status)) dp.add_handler(CommandHandler("inline", inline_query)) # Charting can be slow so they run async. dp.add_handler(CommandHandler("intra", intra, run_async=True)) dp.add_handler(CommandHandler("intraday", intra, run_async=True)) dp.add_handler(CommandHandler("day", intra, run_async=True)) dp.add_handler(CommandHandler("chart", chart, run_async=True)) dp.add_handler(CommandHandler("month", chart, run_async=True)) # on noncommand i.e message - echo the message on Telegram dp.add_handler(MessageHandler(Filters.text, symbol_detect)) # Inline Bot commands dp.add_handler(InlineQueryHandler(inline_query)) # Pre-checkout handler to final check dp.add_handler(PreCheckoutQueryHandler(precheckout_callback)) # Payment success dp.add_handler( MessageHandler(Filters.successful_payment, successful_payment_callback)) # log all errors dp.add_error_handler(error) # Start the Bot updater.start_polling() updater.idle()
def main(): updater=Updater(keys.apiKey) dp = updater.dispatcher dp.add_handler(CommandHandler("start", start_command)) dp.add_handler(CommandHandler("help", help_command)) dp.add_handler(CallbackQueryHandler(category_callback, pattern='^(c+)')) dp.add_handler(CallbackQueryHandler(products_callback, pattern='^(p+)')) dp.add_handler(MessageHandler(Filters.text,handle_message)) dp.add_handler(MessageHandler(Filters.successful_payment, successful_payment_callback)) dp.add_handler(PreCheckoutQueryHandler(callback=precheckout_callback)) updater.start_polling() updater.is_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(os.environ['token'], use_context=True) # Get the dispatcher to register handlers dp = updater.dispatcher conv_handler = ConversationHandler( entry_points=[CommandHandler('start', start)], allow_reentry=True, states={ CHOOSING: [ MessageHandler(Filters.regex('^О боте 👾$'), about_bot), MessageHandler(Filters.regex('^О авторе 👨🏻💻$'), about_author), MessageHandler(Filters.regex('^Пример 💶$'), custom_choice), MessageHandler(Filters.regex('^Контакты 📲$'), contacts), MessageHandler(Filters.regex('^Статистика 📊$'), stats), MessageHandler(Filters.regex('^Хочу такого бота 🚀$'), order), CommandHandler('stats', stats), CommandHandler('photo', photo), CommandHandler('doc', doc), MessageHandler(Filters.document, echo) ], PAYMENT: [CallbackQueryHandler(button)], TYPING_REPLY: [CallbackQueryHandler(received_information)], }, fallbacks=[MessageHandler(Filters.regex('^Назад$'), get_back)]) # 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(conv_handler) # 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(): if BOT_TOKEN == "": logger.error("TOKEN not defined. Put your bot token on bot_tokens.py") return updater = Updater(BOT_TOKEN) h = updater.dispatcher.add_handler const.aux.BOT_USERNAME = updater.bot.get_me().username # Assigning handlers h(CommandHandler("start", handlers.start, pass_args=True)) h(CommandHandler("help", handlers.help)) h(CommandHandler("more", handlers.more)) h(CommandHandler("ping", handlers.ping)) h(CommandHandler("donate", handlers.donate, pass_user_data=True)) h(CommandHandler("support", handlers.support, filters=Filters.private)) h(CommandHandler("support", handlers.support_group, filters=Filters.group)) h(CommandHandler("about", handlers.about)) h(CallbackQueryHandler(handlers.change_donation_quantity, pattern=r"don\*", pass_user_data=True)) h(CallbackQueryHandler(handlers.send_donation_receipt, pattern=r"donate$", pass_user_data=True)) h(MessageHandler(filters=Filters.successful_payment, callback=handlers.completed_donation)) h(PreCheckoutQueryHandler(handlers.approve_transaction)) h(InlineQueryHandler(handlers.full_query, pattern=".+")) h(InlineQueryHandler(handlers.empty_query)) h(ChosenInlineResultHandler(handlers.chosen_result)) h(CallbackQueryHandler(handlers.cast_vote, pattern=r"vote\*.*\*")) h(CallbackQueryHandler(handlers.get_clist, pattern=r"get_clist\*.*\*")) updater.dispatcher.add_error_handler(handlers.error) updater.start_polling() # CONSOLE while True: inp = input("") if inp: input_c = inp.split()[0] args = inp.split()[1:] strig = "" for e in args: strig = strig + " " + e if input_c == "stop": stop_bot(updater) break else: print("Unknown command")
def main(): if BOT_TOKEN == "": logger.error("TOKEN not defined. Put your bot token on bot_tokens.py") return updater = Updater(BOT_TOKEN) h = updater.dispatcher.add_handler # Assigning handlers h(CommandHandler("fill_hands", handlers.fill_hands, pass_args=True)) h(CommandHandler("send_hands", handlers.send_hands)) h(CommandHandler("send_picks", handlers.send_picks)) h(CommandHandler("clear_hands", handlers.clear_hands)) h(CommandHandler("clear_picks", handlers.clear_picks)) h(CommandHandler("toggle_voting", handlers.toggle_voting)) h(CommandHandler("start", handlers.start)) h(MessageHandler(callback=handlers.private_message, filters=Filters.private)) h(CommandHandler("help", handlers.help)) h(CommandHandler("more", handlers.more)) h(CommandHandler("ping", handlers.ping)) h(CommandHandler("donate", handlers.donate, pass_user_data=True)) h(CommandHandler("support", handlers.support, filters=Filters.private)) h(CommandHandler("support", handlers.support_group, filters=Filters.group)) h(CommandHandler("about", handlers.about)) h(CallbackQueryHandler(handlers.change_donation_quantity, pattern=r"don\*", pass_user_data=True)) h(CallbackQueryHandler(handlers.send_donation_receipt, pattern=r"donate$", pass_user_data=True)) h(MessageHandler(filters=Filters.successful_payment, callback=handlers.completed_donation)) h(PreCheckoutQueryHandler(handlers.approve_transaction)) # updater.dispatcher.add_error_handler(handlers.error) updater.start_polling() # CONSOLE while True: inp = input("") if inp: input_c = inp.split()[0] args = inp.split()[1:] strig = "" for e in args: strig = strig + " " + e if input_c == "stop": stop_bot(updater) break else: print("Unknown command")
def main(): # Create the EventHandler and pass it your bot's token. updater = Updater(telegram_token) # Get the dispatcher to register handlers dp = updater.dispatcher # on different commands - answer in Telegram dp.add_handler(CommandHandler("start", start)) dp.add_handler(CommandHandler("help", help_msg)) dp.add_handler(CommandHandler("command", command)) dp.add_handler(CommandHandler("donate", donate)) dp.add_handler(CommandHandler("setlang", set_lang)) dp.add_handler(CommandHandler("setjointimer", set_join_timer, pass_args=True)) dp.add_handler(CommandHandler("setpasstimer", set_pass_timer, pass_args=True)) dp.add_handler(CommandHandler("setgamemode", set_game_mode, pass_args=True)) dp.add_handler(CommandHandler("startgame", start_game, pass_job_queue=True)) dp.add_handler(CommandHandler("join", join, pass_job_queue=True)) dp.add_handler(CommandHandler("forcestop", force_stop)) dp.add_handler(CommandHandler("showdeck", show_deck)) dp.add_handler(CommandHandler("stats", show_stat)) dp.add_handler(CallbackQueryHandler(in_line_button, pass_job_queue=True)) dp.add_handler(CommandHandler("coffee", recharge)) dp.add_handler(PreCheckoutQueryHandler(precheckout_recharge)) dp.add_handler(MessageHandler(Filters.successful_payment, successful_recharge, pass_job_queue=True)) dp.add_handler(feedback_cov_handler()) dp.add_handler(CommandHandler("send", send, pass_args=True)) # log all errors dp.add_error_handler(error) # Start the Bot if app_url: updater.start_webhook(listen="0.0.0.0", port=port, url_path=telegram_token) updater.bot.set_webhook(app_url + telegram_token) else: updater.start_polling() # Run the bot until the you presses 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 start_bot(): updater = Updater(TELEGRAM_TOKEN, request_kwargs=REQUEST_KWARGS) dispatcher = updater.dispatcher dispatcher.add_handler(CallbackQueryHandler(handle_users_reply)) dispatcher.add_handler(MessageHandler(Filters.text, handle_users_reply)) dispatcher.add_handler( MessageHandler(Filters.location, handle_users_reply, edited_updates=True)) dispatcher.add_handler(CommandHandler('start', handle_users_reply)) dispatcher.add_handler(PreCheckoutQueryHandler(process_precheckout)) dispatcher.add_handler( MessageHandler(Filters.successful_payment, process_successful_payment, pass_job_queue=True)) updater.start_polling() logger.info(f'TG bot started')
def main(argv): updater = Updater(get_bot_token(), use_context=True) conv_handler = ConversationHandler( entry_points=[ CommandHandler('menu', menu_callback, Filters.private), CommandHandler('start', menu_callback, Filters.private) ], states={ MAIN_MENU: [ CallbackQueryHandler(help_callback, pattern='^' + str(HELP) + '$'), CallbackQueryHandler(balance_callback, pattern='^' + str(BALANCE) + '$'), CallbackQueryHandler(topup_callback, pattern='^' + str(TOPUP) + '$'), #CallbackQueryHandler(addad_callback, pattern='^' + str(ADDAD) + '$')], addad_handler ], TOPUP_MENU: [ CallbackQueryHandler(main_menu_callback, pattern='^' + str(BACK) + '$'), CallbackQueryHandler(buy_callback, pattern=r'^topup_\d+$') ] }, fallbacks=[MessageHandler(Filters.private, fallback_callback)], allow_reentry=True) # updater.dispatcher.add_handler(CommandHandler('start', start_callback)) # updater.dispatcher.add_handler(MessageHandler(Filters.text & (~Filters.command), message_handler)) updater.dispatcher.add_handler(conv_handler) #updater.dispatcher.add_handler(addad_handler) # updater.dispatcher.add_handler(CommandHandler('start', group_activation_callback, Filters.group)) # updater.dispatcher.add_handler(MessageHandler(Filters.chat(test_group) | Filters.chat(test_group2) | Filters.chat(FusionClubBotTest) | Filters.chat(FusionClubUkraine), group_message)) updater.dispatcher.add_handler( MessageHandler(CustomFilter(), group_message)) updater.dispatcher.add_handler( PreCheckoutQueryHandler(precheckout_callback)) updater.dispatcher.add_handler( MessageHandler(Filters.successful_payment, successful_payment_callback)) updater.dispatcher.add_error_handler(error) run_updater(updater)
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 __init__(self, tg_token, states_functions, **params): self.tg_token = tg_token self.params = params self.updater = Updater(token=tg_token) self.updater.dispatcher.add_handler( CallbackQueryHandler(self.handle_users_reply)) self.updater.dispatcher.add_handler( MessageHandler(Filters.successful_payment, self.handle_users_reply)) self.updater.dispatcher.add_handler( MessageHandler(Filters.text, self.handle_users_reply)) self.updater.dispatcher.add_handler( MessageHandler(Filters.location, self.handle_geodata)) self.updater.dispatcher.add_handler( CommandHandler('start', self.handle_users_reply)) self.updater.dispatcher.add_handler( PreCheckoutQueryHandler(self.handle_users_reply)) self.updater.dispatcher.add_error_handler(self.error) self.states_functions = states_functions self.motlin_token, self.token_expires = None, 0 self.params['job'] = self.updater.job_queue
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(): 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()
def test_other_update_types(self, false_update): handler = PreCheckoutQueryHandler(self.callback_basic) assert not handler.check_update(false_update)