def main(): global token_tlgrm, id_conversacion, up token_tlgrm = '509446248:AAECtz3wUMKaa5d4TOEHmeQnvxBqA9Mb8YM'#DiegoBot id_conversacion = 500840093 up = Updater(token=token_tlgrm) up.bot.send_message(chat_id=id_conversacion, text="Hola, el bot se acaba de iniciar.") up.dispatcher.add_handler(CommandHandler('STOP', stop)) up.dispatcher.add_handler(CommandHandler('start', start, pass_args=True)) up.dispatcher.add_handler(MessageHandler(Filters.text, echo)) # log all errors up.dispatcher.add_error_handler(error) # Start the Bot up._clean_updates() up.start_polling() # Block 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. up.idle()
dp.add_handler(CallbackQueryHandler(help_button_handler, pattern=r"^help:.+$")) dp.add_handler(MessageHandler(Filters.all, update_cache, edited_updates=True), group=-1) dp.add_error_handler(handle_error) core.init(bot=updater.bot, job_queue=updater.job_queue, callback=auto_spin) if config.TELESOCKET_TOKEN: from TeleSocketClient import TeleSocket updater.bot.set_webhook() sock = TeleSocket() sock.login(config.TELESOCKET_TOKEN) sock.add_telegram_handler(lambda update: core.read_update(updater, update)) webhook = sock.set_webhook(updater.bot.username) updater._clean_updates() updater.bot.set_webhook(url=webhook.url, allowed_updates=ALLOWED_UPDATES) updater.job_queue.start() updater._init_thread(updater.dispatcher.start, "dispatcher") updater.running = True elif config.USE_WEBHOOKS: updater.start_webhook(listen='0.0.0.0', port=8443, cert=config.WEBHOOK_CERT, key=config.WEBHOOK_KEY, clean=True, allowed_updates=ALLOWED_UPDATES, webhook_url=f'https://{config.WEBHOOK_URL}:8443') else: updater.start_polling(clean=True, allowed_updates=ALLOWED_UPDATES)