From 8278eef7f38740adafe5eee925b8a95ab61c468a Mon Sep 17 00:00:00 2001 From: eternnoir Date: Tue, 5 Jan 2016 14:58:19 +0800 Subject: [PATCH] Add inline bot example. --- examples/inline_example.py | 41 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 examples/inline_example.py diff --git a/examples/inline_example.py b/examples/inline_example.py new file mode 100644 index 0000000..4273178 --- /dev/null +++ b/examples/inline_example.py @@ -0,0 +1,41 @@ +# This example show how to write an inline mode telegramt bot use pyTelegramBotAPI. +import telebot +import time +import sys +from telebot import types + +API_TOKEN = '' + +bot = telebot.TeleBot(API_TOKEN) + + +@bot.inline_handler(lambda query: query.query == 'text') +def query(inline_query): + try: + r = types.InlineQueryResultArticle('1', 'Result', inline_query.query) + bot.answer_inline_query(inline_query.id, [r]) + except Exception as e: + print(e) + + +@bot.inline_handler(lambda query: len(query.query) is 0) +def default_query(inline_query): + try: + r = types.InlineQueryResultArticle('1', 'default', 'default') + bot.answer_inline_query(inline_query.id, [r]) + except Exception as e: + print(e) + + +def main_loop(): + bot.polling(True) + while 1: + time.sleep(3) + + +if __name__ == '__main__': + try: + main_loop() + except KeyboardInterrupt: + print >> sys.stderr, '\nExiting by user request.\n' + sys.exit(0)