我们从Python开源项目中,提取了以下50个代码示例,用于说明如何使用telegram.ext.MessageHandler()。
def start_bot(): my_bot = Updater(settings.TELEGRAM_API_KEY) dp = my_bot.dispatcher dp.add_handler(CommandHandler("start", reply_to_start_command)) conv_handler = ConversationHandler( entry_points=[RegexHandler('^(????????? ??????)$', start_anketa, pass_user_data=True)], states={ "name": [MessageHandler(Filters.text, get_name, pass_user_data=True)], "attitude": [RegexHandler('^(1|2|3|4|5)$', attitude, pass_user_data=True)], "understanding": [RegexHandler('^(1|2|3|4|5)$', understanding, pass_user_data=True)], "comment": [MessageHandler(Filters.text, comment, pass_user_data=True), CommandHandler('skip', skip_comment, pass_user_data=True)], }, fallbacks=[MessageHandler(Filters.text, dontknow, pass_user_data=True)] ) dp.add_handler(conv_handler) my_bot.start_polling() my_bot.idle()
def setup(webhook_url=None): """If webhook_url is not passed, run with long-polling.""" logging.basicConfig(level=logging.WARNING) if webhook_url: bot = Bot(TOKEN) update_queue = Queue() dp = Dispatcher(bot, update_queue) else: updater = Updater(TOKEN) bot = updater.bot dp = updater.dispatcher dp.add_handler(MessageHandler([], example_handler)) # Remove this line # Add your handlers here if webhook_url: bot.set_webhook(webhook_url=webhook_url) thread = Thread(target=dp.start, name='dispatcher') thread.start() return update_queue, bot else: bot.set_webhook() # Delete webhook updater.start_polling() updater.idle()
def bot_hook(): """Entry point for the Telegram connection.""" bot = telegram.Bot(botdata['BotToken']) dispatcher = Dispatcher(bot, None, workers=0) dispatcher.add_handler(CommandHandler('Abfahrten', abfahrten, pass_args=True)) dispatcher.add_handler(CommandHandler('abfahrten', abfahrten, pass_args=True)) dispatcher.add_handler(CommandHandler('Abfahrt', abfahrten, pass_args=True)) dispatcher.add_handler(CommandHandler('abfahrt', abfahrten, pass_args=True)) dispatcher.add_handler(CommandHandler('A', abfahrten, pass_args=True)) dispatcher.add_handler(CommandHandler('a', abfahrten, pass_args=True)) dispatcher.add_handler(CommandHandler('Hilfe', hilfe)) dispatcher.add_handler(CommandHandler('hilfe', hilfe)) dispatcher.add_handler(CommandHandler('help', hilfe)) dispatcher.add_handler(MessageHandler(Filters.location, nearest_stations)) update = telegram.update.Update.de_json(request.json, bot) dispatcher.process_update(update) return 'OK'
def main(): # Create the EventHandler and pass it your bot's token. updater = Updater(api_key, workers=64) # Get the dispatcher to register handlers dp = updater.dispatcher # on noncommand i.e message - return not found dp.add_handler(MessageHandler(Filters.command, maintenance)) dp.add_handler(MessageHandler(Filters.text, maintenance)) # log all errors dp.add_error_handler(error) # Start the Bot #updater.start_polling() updater.start_webhook(listen='127.0.0.1', port=int(listen_port), url_path=api_key) updater.bot.setWebhook('https://{0}/{1}'.format(domain, api_key)) # 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(): # define the updater updater = Updater(token=botconfig.bot_token) # define the dispatcher dp = updater.dispatcher # messages dp.add_handler(MessageHandler(~Filters.command, util.process_message, edited_updates=True)) dp.add_handler(CommandHandler(('start'), commands.help_command)) dp.add_handler(CommandHandler(('stats'), commands.stats_command)) dp.add_handler(CommandHandler(('globalstats'), commands.global_stats_command)) # handle errors dp.add_error_handler(error) updater.start_polling() updater.idle()
def main(): logger.info("Loading handlers for telegram bot") # Default dispatcher (this is related to the first bot in settings.TELEGRAM_BOT_TOKENS) dp = DjangoTelegramBot.dispatcher # To get Dispatcher related to a specific bot # dp = DjangoTelegramBot.getDispatcher('BOT_n_token') #get by bot token # dp = DjangoTelegramBot.getDispatcher('BOT_n_username') #get by bot username # on different commands - answer in Telegram dp.add_handler(CommandHandler("start", start)) dp.add_handler(CommandHandler("help", help)) dp.add_handler(CommandHandler("startgroup", startgroup)) dp.add_handler(CommandHandler("me", me)) dp.add_handler(CommandHandler("chat", chat)) dp.add_handler(MessageHandler(Filters.forwarded , forwarded)) # on noncommand i.e message - echo the message on Telegram dp.add_handler(MessageHandler(Filters.text, echo)) # log all errors dp.add_error_handler(error)
def main(): logger.info("Loading handlers for telegram bot") # Default dispatcher (this is related to the first bot in settings.TELEGRAM_BOT_TOKENS) dp = DjangoTelegramBot.dispatcher # To get Dispatcher related to a specific bot # dp = DjangoTelegramBot.getDispatcher('BOT_n_token') #get by bot token # dp = DjangoTelegramBot.getDispatcher('BOT_n_username') #get by bot username # on different commands - answer in Telegram dp.add_handler(CommandHandler("start", start)) dp.add_handler(CommandHandler("help", help)) # on noncommand i.e message - echo the message on Telegram dp.add_handler(MessageHandler([Filters.text], echo)) # log all errors dp.add_error_handler(error) # log all errors dp.addErrorHandler(error)
def __init__(self): token = rospy.get_param('/telegram/token', None) if token is None: rospy.logerr("No token found in /telegram/token param server.") exit(0) else: rospy.loginfo("Got telegram bot token from param server.") # Set CvBridge self.bridge = CvBridge() # Create the EventHandler and pass it your bot's token. updater = Updater(token) # Get the dispatcher to register handlers dp = updater.dispatcher # on noncommand i.e message - echo the message on Telegram dp.add_handler(MessageHandler(Filters.text, self.pub_received)) # log all errors dp.add_error_handler(self.error) # Start the Bot updater.start_polling()
def main(token): # Create the EventHandler and pass it your bot's token. updater = Updater(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)) # on noncommand i.e message - echo the message on Telegram dp.add_handler(MessageHandler(Filters.text, echo)) # log all errors dp.add_error_handler(error) # Start the Bot 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 __init__(self): self.base_pub = rospy.Publisher("/base_controller/command", Twist, queue_size=1) token = rospy.get_param('/telegram/token', None) # Create the Updater and pass it your bot's token. updater = Updater(token) # Add command and error handlers updater.dispatcher.add_handler(CommandHandler('start', self.start)) updater.dispatcher.add_handler(CommandHandler('help', self.help)) updater.dispatcher.add_handler(MessageHandler(Filters.text, self.echo)) updater.dispatcher.add_error_handler(self.error) # Start the Bot updater.start_polling()
def __init__(self): self.history = {} self.updater = Updater(TOKEN) self.name = str(self).split(' ')[-1][:-1] self.dp = self.updater.dispatcher self.dp.add_handler(CommandHandler("start", start)) self.dp.add_handler(CommandHandler("help", help)) self.dp.add_handler(MessageHandler([Filters.text], echo)) self.dp.add_error_handler(error) self.stories = StoriesHandler() logger.info('I\'m alive!')
def test_echo(self): def echo(bot, update): update.message.reply_text(update.message.text) self.updater.dispatcher.add_handler(MessageHandler(Filters.text, echo)) self.updater.start_polling() update = self.mg.get_message(text="first message") update2 = self.mg.get_message(text="second message") self.bot.insertUpdate(update) self.bot.insertUpdate(update2) self.assertEqual(len(self.bot.sent_messages), 2) sent = self.bot.sent_messages self.assertEqual(sent[0]['method'], "sendMessage") self.assertEqual(sent[0]['text'], "first message") self.assertEqual(sent[1]['text'], "second message") self.updater.stop()
def telegram_command_handle(updater): """ ????????? ?????? ?? ???? Telegram :param updater: :return: """ dispatcher = updater.dispatcher start_handler = CommandHandler('start', start) dispatcher.add_handler(start_handler) help_me_handler = CommandHandler('help', help_me) dispatcher.add_handler(help_me_handler) echo_handler = MessageHandler(Filters.text, echo) dispatcher.add_handler(echo_handler)
def main(): # Create the EventHandler and pass it your bot's token. updater = Updater(<TOKENNAME>) # 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("schedule", schedule)) # on noncommand i.e message - echo the message on Telegram dp.add_handler(MessageHandler([Filters.text], echo)) # log all errors dp.add_error_handler(error) # Start the Bot 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(): # Create the EventHandler and pass it your bot's token. # sara #updater = Updater("223436029:AAEgihik3KXielXe7lBuP9H7o4M-eUdL_LU") #testbot updater = Updater("223436029:AAH9iIhGXP8EAB4qxXx4wJ0-YpYtplYVOkY") # 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)) # on noncommand i.e message - echo the message on Telegram dp.add_handler(MessageHandler([Filters.text], chatter)) # Start the Bot 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(): test_handler = MessageHandler(Filters.all, test, edited_updates=True, message_updates=False) start_handler = CommandHandler("start", start) help_handler = CommandHandler("help", get_help) migrate_handler = MessageHandler(Filters.status_update.migrate, migrate_chats) # dispatcher.add_handler(test_handler) dispatcher.add_handler(start_handler) dispatcher.add_handler(help_handler) dispatcher.add_handler(migrate_handler) # dispatcher.add_error_handler(error_callback) if HEROKU: port = int(os.environ.get('PORT', 5000)) updater.start_webhook(listen="0.0.0.0", port=port, url_path=TOKEN) updater.bot.set_webhook("https://tgpolbot.herokuapp.com/" + TOKEN) else: updater.start_polling() updater.idle()
def main(): updater = Updater(cfg['botapi_token']) dp = updater.dispatcher dp.add_handler(CommandHandler("start", start)) dp.add_handler(CommandHandler("help", help)) dp.add_handler(CommandHandler("ping", ping)) # on no command dp.add_handler(MessageHandler(Filters.text & (~ Filters.forwarded), echo)) # Message is text and is not forwarded # log all errors dp.add_error_handler(error) # Start the Bot updater.start_polling() # Run the bot until process receives SIGINT, SIGTERM or SIGABRT updater.idle()
def __init__(self, token, db_url): # connect to Telegram with the desired token self.updater = Updater(token=token) self.bot = self.updater.bot # configure the bot behavior dispatcher = self.updater.dispatcher dispatcher.add_handler(CommandHandler("start", self.send_welcome)) dispatcher.add_handler(MessageHandler([Filters.text], self.filter_tags)) # create a digester backed by the desired database try: self.digester = digester.Digester(db_url) except Exception as e: self.stop() raise e self.db_url = db_url # dispatcher methods self.get_config = self.digester.get_config self.get_chat = self.bot.getChat
def main(): updater = Updater(AUTHTOKEN, workers=10) dp = updater.dispatcher dp.add_handler(CommandHandler('start', start)) dp.add_handler(CommandHandler('help', help)) dp.add_handler(CommandHandler('info', info)) dp.add_handler(CommandHandler('support', support, pass_chat_data=True)) dp.add_handler(CommandHandler('getStats', getMessageStats)) dp.add_handler(CommandHandler('chooselang', chooseLanguage, pass_chat_data=True, pass_args=True)) dp.add_handler(MessageHandler(Filters.voice, receiveMessage, pass_chat_data=True)) dp.add_handler(MessageHandler(Filters.all, countme)) dp.add_handler(CallbackQueryHandler(callbackHandler, pass_chat_data=True)) dp.add_error_handler(error) updater.start_polling() logger.debug("Setiup complete, Idling.") updater.idle()
def register_text_handler(self, callback, allow_edited=False): """Registers text message handler Args: callback(function): callable object to execute allow_edited(Optional[bool]): pass edited messages """ @utils.log(logger, print_ret=False) def process_update(bot, update): lang = utils.get_lang(self._storage, update.effective_user) callback(update.effective_message, lang) self._dispatcher.add_handler(MessageHandler(Filters.text, process_update, edited_updates=allow_edited))
def main(): u = Updater('YOUR-TOKEN') dp = u.dispatcher dp.add_handler(CommandHandler("start", start)) dp.add_handler(MessageHandler(Filters.text, music)) u.start_polling() u.idle()
def main(): # Create the EventHandler and pass it your bot's token. updater = Updater("386765167:AAEAeiO5sgg5AjlQFIw6OiYWTXr1qBeQsrE") # 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("begin_simple_arbitrage", begin_simple_arbitrage)) dp.add_handler(CommandHandler("stop_simple_arbitrage", stop_simple_arbitrage)) # on noncommand i.e message - echo the message on Telegram dp.add_handler(MessageHandler(Filters.text, non_command)) #Start scheduler t1 = Thread(target=ThreadFunctionScheduler, args=(updater.bot,)) t1.start() # Start the Bot t2 = Thread(target=ThreadBot, args=(updater,)) t2.start() # 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 setup(): '''GAE DISPATCHER SETUP''' global dispatcher # Note that update_queue is setted to None and # 0 workers are allowed on Google app Engine (If not-->Problems with multithreading) dispatcher = Dispatcher(bot=bot, update_queue=None, workers=0) # ---Register handlers here--- dispatcher.add_handler(CommandHandler("start", start)) dispatcher.add_handler(CommandHandler("help", help)) dispatcher.add_handler(MessageHandler([Filters.text], echo)) dispatcher.add_error_handler(error) return dispatcher
def main(): # Create the EventHandler and pass it your bot's token. updater = Updater("") # 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("reportcard", reportcard,pass_args=True,pass_chat_data=True)) dp.add_handler(CommandHandler("s", s,pass_args=True,pass_chat_data=True)) dp.add_handler(CommandHandler("DeleteFromThisHell", DeleteFromThisHell,pass_args=True,pass_chat_data=True)) dp.add_handler(CommandHandler("github", github) # on noncommand i.e message - echo the message on Telegram dp.add_handler(MessageHandler(Filters.text, echo)) # log all errors dp.add_error_handler(error) # Start the Bot updater.start_polling() updater.idle() if __name__ == '__main__': main()
def main(): # Create the EventHandler and pass it your bot's token. updater = Updater(os.environ['BOT_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("dolartoday", dolartoday)) dp.add_handler(CommandHandler("bolivarcucuta", bolivarcucuta)) dp.add_handler(CommandHandler("imagen", dolartodayImg)) # on noncommand i.e message - echo the message on Telegram #dp.add_handler(MessageHandler([Filters.text], echo)) # log all errors dp.add_error_handler(error) # Start the Bot 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(): updtr = Updater(settings.TELEGRAM_API_KEY) updtr.dispatcher.add_handler(CommandHandler("start", start_bot)) updtr.dispatcher.add_handler(MessageHandler(Filters.text, chat)) updtr.start_polling() updtr.idle()
def start_bot(): my_bot = Updater(settings.TELEGRAM_API_KEY) dp = my_bot.dispatcher dp.add_handler(CommandHandler("start", reply_to_start_command)) dp.add_handler(MessageHandler(Filters.photo, check_cat)) my_bot.start_polling() my_bot.idle()
def start_bot(): my_bot = Updater(settings.TELEGRAM_API_KEY) dp = my_bot.dispatcher dp.add_handler(CommandHandler("start", reply_to_start_command, pass_user_data=True)) dp.add_handler(CommandHandler("countwords", count_words, pass_args=True, pass_user_data=True)) dp.add_handler(CommandHandler("cat", send_cat, pass_user_data=True)) dp.add_handler(MessageHandler(Filters.text, chat_with_user, pass_user_data=True)) my_bot.start_polling() my_bot.idle()
def start_bot(): my_bot = Updater(TELEGRAM_API_KEY) dp = my_bot.dispatcher dp.add_handler(CommandHandler("start", reply_to_start_command, pass_user_data=True)) dp.add_handler(CommandHandler("cat", send_cat, pass_user_data=True)) dp.add_handler(RegexHandler("^(???????? ??????)$", send_cat, pass_user_data=True)) dp.add_handler(RegexHandler("^(??????? ????????)$", change_avatar_step1, pass_user_data=True)) dp.add_handler(CommandHandler("avatar", change_avatar_step2, pass_args=True, pass_user_data=True)) dp.add_handler(MessageHandler(Filters.contact, get_contact, pass_user_data=True)) dp.add_handler(MessageHandler(Filters.location, get_location, pass_user_data=True)) my_bot.start_polling() my_bot.idle()
def __init__(self): token = rospy.get_param('/telegram/token', None) if token is None: rospy.logerr("No token found in /telegram/token param server.") exit(0) else: rospy.loginfo("Got telegram bot token from param server.") # Set CvBridge self.bridge = CvBridge() # Create the EventHandler and pass it your bot's token. updater = Updater(token) # Get the dispatcher to register handlers dp = updater.dispatcher # on message... dp.add_handler(MessageHandler(Filters.text, self.pub_received)) dp.add_handler(CallbackQueryHandler(self.button)) # log all errors dp.add_error_handler(self.error) # Start the Bot updater.start_polling()
def __init__(self): token = rospy.get_param('/telegram/token', None) if token is None: rospy.logerr("No token found in /telegram/token param server.") exit(0) else: rospy.loginfo("Got telegram bot token from param server.") self.str_pub = rospy.Publisher("~telegram_chat", String, queue_size=1) rospy.loginfo("Publishing received messages in topic: " + str(self.str_pub.resolved_name)) # Create the EventHandler and pass it your bot's token. updater = Updater(token) # Get the dispatcher to register handlers dp = updater.dispatcher # on noncommand i.e message - echo the message on Telegram dp.add_handler(MessageHandler(Filters.text, self.pub_received)) # log all errors dp.add_error_handler(self.error) # Start the Bot updater.start_polling() # Define a few command handlers
def main(): updater = Updater("INSERT TOKEN HERE") dp = updater.dispatcher dp.add_handler(CommandHandler("start", cmd_start)) dp.add_handler(CommandHandler("md", cmd_markdown, allow_edited=True)) dp.add_handler(CommandHandler("markdown", cmd_markdown, allow_edited=True)) dp.add_handler(CommandHandler("pin", cmd_pin, allow_edited=True)) dp.add_handler(CommandHandler("welcome", cmd_welcome, allow_edited=True)) dp.add_handler(CommandHandler("goodbye", cmd_goodbye, allow_edited=True)) dp.add_handler(CommandHandler("del_welcome", cmd_clear_welcome)) dp.add_handler(CommandHandler("del_goodbye", cmd_clear_goodbye)) dp.add_handler(CommandHandler("set_bot_admin", cmd_set_bot_admin, allow_edited=True)) dp.add_handler(CommandHandler("remove_bot_admin", cmd_remove_bot_admin, allow_edited=True)) dp.add_handler(CommandHandler("settings", cmd_settings)) dp.add_handler(CommandHandler("shortcut", cmd_shortcut_set, allow_edited=True)) dp.add_handler(CommandHandler("del_shortcut", cmd_shortcut_del, allow_edited=True)) dp.add_handler(CommandHandler("shortcuts", cmd_shortcut_getall, allow_edited=True)) dp.add_handler(MessageHandler(Filters.audio | Filters.command | Filters.contact | Filters.document | Filters.photo | Filters.sticker | Filters.text | Filters.video | Filters.voice | Filters.status_update, msg_parse, allow_edited=True)) dp.add_handler(CallbackQueryHandler(inline_button_callback)) dp.add_error_handler(error) updater.start_polling() updater.idle()
def run(self): """ :return: None """ self.__updater = Updater(token=self.__config['KEYS']['bot_api']) self.__dispatcher = self.__updater.dispatcher executeHandler = MessageHandler([Filters.text], self.executer) self.__dispatcher.add_handler(executeHandler) self.__dispatcher.add_handler(InlineQueryHandler(self.getInlineQuery)) self.__dispatcher.add_error_handler(self.error) # Define Job Queue self.__job_queue = self.__updater.job_queue for key, hook in self.__hooks.items(): self.__job_queue.put(Job(hook.get('hook').job, hook.get('timer'), True), next_t=0.0) # Start the Motux Bot self.__updater.start_polling(poll_interval=0.1, timeout=10, network_delay=5, clean=False) # Run the Motux Bot until the you presses Ctrl-C or the process receives SIGINT, # SIGTERM or SIGABRT. This should be used most of the time, since self.__updater.idle()
def main(): token = "TOKEN" updater = Updater(token, workers=20) updater.dispatcher.add_handler(CommandHandler('start', start)) updater.dispatcher.add_handler(CommandHandler('help', help)) updater.dispatcher.add_handler(CommandHandler('anime', anime)) updater.dispatcher.add_handler(CommandHandler('hentai', hentai)) updater.dispatcher.add_handler(CommandHandler('ecchi', ecchi)) updater.dispatcher.add_handler(CommandHandler('uncensored', uncensored)) updater.dispatcher.add_handler(CommandHandler('yuri', ecchi)) updater.dispatcher.add_handler(CommandHandler('loli', loli)) updater.dispatcher.add_handler(CommandHandler('neko', neko)) updater.dispatcher.add_handler(CommandHandler('wallpaper', wallpaper)) updater.dispatcher.add_handler(CommandHandler('id', idd)) updater.dispatcher.add_handler(CommandHandler('tag', tag)) updater.dispatcher.add_handler(CommandHandler('ping', ping)) updater.dispatcher.add_handler(CommandHandler('info', info)) updater.dispatcher.add_handler(CommandHandler('su', su)) updater.dispatcher.add_handler(CommandHandler('feedback', feedback)) updater.dispatcher.add_handler(CommandHandler("mes", mes)) updater.dispatcher.add_handler(CallbackQueryHandler(callback)) updater.dispatcher.add_handler(MessageHandler(Filters.text, text)) updater.dispatcher.add_handler(InlineQueryHandler(inline)) updater.dispatcher.add_error_handler(error) updater.start_polling(bootstrap_retries=4, clean=True) updater.idle()
def __add_mention_receiver(self): message_handler = MessageHandler(Filters.text, self.__mention) self.dispatcher.add_handler(message_handler)
def __init__(self, token, generator): self.updater = Updater(token=token) # ??????? ????????? handler = MessageHandler(Filters.text | Filters.command, self.handle_message) self.updater.dispatcher.add_handler(handler) # ?????? ?????????? ???? ????????? ????????? self.handlers = collections.defaultdict(generator) # ??????? ???? "id ???? -> ?????????"
def __init__(self, token, generator, handlers=None): self.updater = Updater(token=token) message_handler = MessageHandler(Filters.text | Filters.command, self.handle_message) inline_query_handler = InlineQueryHandler(self.handle_inline_query) self.updater.dispatcher.add_handler(message_handler) self.updater.dispatcher.add_handler(inline_query_handler) self.generator = generator self.handlers = handlers or {} self.last_message_ids = {}
def main(): # manage conversation conv_handler = ConversationHandler( entry_points=[CommandHandler('start', start)], states={ second: [MessageHandler(Filters.text,second)], }, fallbacks=[CommandHandler('cancel', cancel)]) # it handle start command start_handler = CommandHandler('start', start) # handle all text second_handler = MessageHandler(Filters.text , second) filef_handler = MessageHandler(Filters.document, filef) # handle cancel cancel_handler = CommandHandler('cancel', cancel) # handle cancel about_handler = CommandHandler('about', about) # handle dispatcher dispatcher.add_handler(InlineQueryHandler(inlinequery)) dispatcher.add_handler(start_handler) dispatcher.add_handler(second_handler) dispatcher.add_handler(conv_handler) dispatcher.add_handler(cancel_handler) dispatcher.add_handler(about_handler) dispatcher.add_handler(filef_handler) # run updater.start_polling() updater.idle() updater.stop()
def main(): # Create the EventHandler and pass it your bot's token. updater = Updater(TOKEN) # Get the dispatcher to register handlers dp = updater.dispatcher # Parse text for intent dp.add_handler(MessageHandler([Filters.text], intent_extractor)) # on different commands - answer in Telegram dp.add_handler(CommandHandler('start_consensus', start_consensus)) dp.add_handler(CommandHandler('end_consensus', end_consensus)) dp.add_handler(CommandHandler('times', times)) dp.add_handler(CommandHandler('export', export)) # log all errors dp.add_error_handler(error) # Start the Bot 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 __init__(self): self.handlers = [ CommandHandler('start', self.download_command, pass_args=True), CommandHandler('baixa', self.download_command, pass_args=True), CommandHandler('android', self.android_command), CommandHandler('ios', self.ios_command), CommandHandler('tdesktop', self.tdesktop_command), CommandHandler('stats', self.stats_command), CommandHandler('getfiles', self.getfiles_command), CommandHandler('testfiles', self.testfiles_command), CallbackQueryHandler(self.platform_handler) #MessageHandler([Filters.text], self.message) ] self.store = TinyDBStore() self.inline = InlineModule()
def main(): token = open("token.txt", "r") token_name = token.readline() token.close() # Create the EventHandler and pass it your bot's token. updater = Updater(token_name) # 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("timet", get_timetable, pass_args=True)) dp.add_handler(CommandHandler("set", set, pass_args=True, pass_job_queue=True)) dp.add_handler(CommandHandler("unset", unset, pass_job_queue=True)) dp.add_handler(CommandHandler("mates", get_mates)) dp.add_handler(CommandHandler("????", meat)) dp.add_handler(CommandHandler("spam", spam, pass_args=True)) # on noncommand i.e message - echo the message on Telegram dp.add_handler(MessageHandler([Filters.text], text_echo)) dp.add_handler(MessageHandler([Filters.sticker], sticker_echo)) # log all errors dp.add_error_handler(error) # Start the Bot 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(): updater = Updater(config['token']) updater.dispatcher.add_handler(CommandHandler('start', start)) updater.dispatcher.add_handler(CommandHandler('restart', restart_qq)) updater.dispatcher.add_handler(CommandHandler('setme', set_remark)) updater.dispatcher.add_handler(CommandHandler('resetme', reset_remark)) updater.dispatcher.add_handler(MessageHandler(Filters.all, handle_message)) ts = TelegramSender() ts.start() logger.info('Sync started') start_new_thread(app.run, ('127.0.0.1', config['tg_port'])) updater.start_polling(clean=True)
def add_handlers(self, add_handler): add_handler(MessageHandler(Filters.text, self.text_responses)) add_handler( MessageHandler(Filters.text & reply_to_bot_filter, self.reply_responses)) add_handler(CommandHandler('me', self._me, pass_args=True))
def add_handlers(self, add_handler): add_handler(MessageHandler(Filters.all, self._run))
def add_handlers(self, add_handler): add_handler(CommandHandler('ktozloy', self._kto_zloy)) add_handler(MessageHandler(Filters.all, self._update_last_users))
def add_handlers(self, add_handler): add_handler(MessageHandler(Filters.text, self._update_statistic)) add_handler(CommandHandler('top10', self._top10)) add_handler(CommandHandler('statistic', self._display_statistic))
def main(): # logging.basicConfig(format='%(asctime)s - %(name)s - %(levelname)s - %(message)s', level=logging.INFO) updater = Updater(config.token) updater.dispatcher.add_handler(MessageHandler(FilterPr(), pr)) updater.dispatcher.add_handler(MessageHandler(FilterPrOther(), pr_other)) # updater.dispatcher.add_handler(MessageHandler(Filters.all, debug)) updater.start_polling() updater.idle()
def main(): # Create the EventHandler and pass it your bot's token. updater = Updater(secrets.bot_token) # Get the dispatcher to register handlers dp = updater.dispatcher # on different commands - answer in Telegram dp.addHandler(CommandHandler("start", start)) dp.addHandler(CommandHandler("help", help)) dp.addHandler(CommandHandler("tts", tts)) dp.addHandler(CommandHandler("otts", otts)) dp.addHandler(CommandHandler("developer", developer)) # on noncommand i.e message - echo the message on Telegram dp.addHandler(MessageHandler([Filters.text], echo)) # log all errors dp.addErrorHandler(error) 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()