Python telegram.ext 模块,InlineQueryHandler() 实例源码

我们从Python开源项目中,提取了以下8个代码示例,用于说明如何使用telegram.ext.InlineQueryHandler()

项目:TelegramBots    作者:d-qoi    | 项目源码 | 文件源码
def main():
    # Create the Updater and pass it your bot's token.
    updater = Updater("321091178:AAG5ve7E5keE3zRHJLsmGgs-r3D6OV0UNzc")

    # 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(InlineQueryHandler(inlinequery))

    # log all errors
    dp.add_error_handler(error)

    # Start the Bot
    updater.start_polling()

    # Block until the user 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()
项目:Motux    作者:kagir    | 项目源码 | 文件源码
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()
项目:animebot    作者:EV3REST    | 项目源码 | 文件源码
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()
项目:python-telegram-dialog-bot    作者:Saluev    | 项目源码 | 文件源码
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 = {}
项目:bpastebot    作者:mostafaasadi    | 项目源码 | 文件源码
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()
项目:TBot8-1    作者:Danzilla-cool    | 项目源码 | 文件源码
def main():
    # Create the Updater 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(InlineQueryHandler(inlinequery))

    # log all errors
    dp.add_error_handler(error)

    # Start the Bot
    updater.start_polling()

    # Block until the user 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()
项目:ptbtest    作者:Eldinnie    | 项目源码 | 文件源码
def test_inline_bot(self):
        # create some handlers and add them
        def escape_markdown(text):
            """Helper function to escape telegram markup symbols"""
            escape_chars = '\*_`\['
            return re.sub(r'([%s])' % escape_chars, r'\\\1', text)

        def inlinequery(bot, update):
            query = update.inline_query.query
            results = list()

            results.append(InlineQueryResultArticle(id=uuid4(),
                                                    title="Caps",
                                                    input_message_content=InputTextMessageContent(
                                                        query.upper())))
            results.append(InlineQueryResultArticle(id=uuid4(),
                                                    title="Bold",
                                                    input_message_content=InputTextMessageContent(
                                                        "*%s*" % escape_markdown(query),
                                                        parse_mode=ParseMode.MARKDOWN)))
            results.append(InlineQueryResultArticle(id=uuid4(),
                                                    title="Italic",
                                                    input_message_content=InputTextMessageContent(
                                                        "_%s_" % escape_markdown(query),
                                                        parse_mode=ParseMode.MARKDOWN)))
            update.inline_query.answer(results)

        dp = self.updater.dispatcher
        dp.add_handler(InlineQueryHandler(inlinequery))
        self.updater.start_polling()

        # Now test the handler
        u1 = self.iqg.get_inline_query(query="test data")
        self.bot.insertUpdate(u1)

        data = self.bot.sent_messages[-1]
        self.assertEqual(len(data['results']), 3)
        results = data['results']
        self.assertEqual(results[0]['title'], "Caps")
        self.assertEqual(results[0]['input_message_content']['message_text'], "TEST DATA")
        self.assertEqual(results[1]['title'], "Bold")
        self.assertEqual(results[1]['input_message_content']['message_text'], "*test data*")
        self.assertEqual(results[2]['title'], "Italic")
        self.assertEqual(results[2]['input_message_content']['message_text'], "_test data_")

        self.updater.stop()
项目:tinder-telegram-bot    作者:arthurdk    | 项目源码 | 文件源码
def main():
    db.db.connect()

    try:
        db.db.create_tables([db.Conversation, db.User, db.IsMod, db.Vote])
    except pw.OperationalError:
        pass

    updater = Updater(settings.KEY)

    dispatcher = updater.dispatcher
    dispatcher.add_handler(CommandHandler('start', start))
    dispatcher.add_handler(CommandHandler('help', send_help_message))

    dispatcher.add_handler(CommandHandler('auto', set_auto))
    dispatcher.add_handler(CommandHandler('location', set_location, pass_args=True))
    dispatcher.add_handler(CommandHandler('set_account', set_account))
    dispatcher.add_handler(CommandHandler('unlink', unlink))
    dispatcher.add_handler(CommandHandler('matches', send_matches))
    dispatcher.add_handler(CallbackQueryHandler(inline.do_press_inline_button, pass_job_queue=True))
    dispatcher.add_handler(MessageHandler(Filters.text, message_handler, pass_job_queue=True))
    dispatcher.add_handler(MessageHandler(Filters.location, update_location))
    dispatcher.add_handler(CommandHandler('new_vote', start_vote_session, pass_job_queue=True))
    dispatcher.add_handler(CommandHandler('timeout', set_timeout, pass_args=True))
    dispatcher.add_handler(CommandHandler('about', send_about))

    # Chat functionality
    dispatcher.add_handler(CommandHandler('poll_msgs', chat.poll_messages, pass_args=True))
    dispatcher.add_handler(CommandHandler('poll_unanswered', chat.poll_unanswered_messages, pass_args=True))
    dispatcher.add_handler(CommandHandler('unblock', chat.unblock))

    # Settings
    dispatcher.add_handler(CommandHandler('set_setting', admin.set_setting, pass_args=True))
    dispatcher.add_handler(CommandHandler('list_settings', admin.list_settings))
    dispatcher.add_handler(CommandHandler('help_settings', admin.help_settings))

    # Moderators
    dispatcher.add_handler(CommandHandler('make_me_a_mod', admin.make_me_a_mod))

    inline_caps_handler = InlineQueryHandler(inline.inline_preview)
    dispatcher.add_handler(inline_caps_handler)

    dispatcher.add_handler(MessageHandler(Filters.command, custom_command_handler))
    dispatcher.add_error_handler(error_callback)
    updater.start_polling()
    updater.idle()