From 805e3554debcbd65b7bb5e60d76e1c3c0aba3f08 Mon Sep 17 00:00:00 2001 From: eternnoir Date: Tue, 5 Jan 2016 21:54:47 +0800 Subject: [PATCH] Update readme. --- README.md | 28 ++++++++++++++++++++++++++++ examples/inline_example.py | 21 +++++++++++++++++++-- 2 files changed, 47 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index fb872c6..7d0709f 100644 --- a/README.md +++ b/README.md @@ -17,6 +17,7 @@ * [Message handlers](#message-handlers) * [TeleBot](#telebot) * [Reply markup](#reply-markup) + * [Inline Mode](#inlinemode) * [Advanced use of the API](#advanced-use-of-the-api) * [Asynchronous delivery of messages](#asynchronous-delivery-of-messages) * [Sending large text messages](#sending-large-text-messages) @@ -321,6 +322,33 @@ ForceReply: ![ForceReply](https://pp.vk.me/c624430/v624430512/473ec/602byyWUHcs.jpg "ForceReply") +### Inline Mode + +More information about [Inline mode](https://core.telegram.org/bots/inline). + +#### inline_handler +Now, you can use inline_handler to get inline_query in telebot. +```python + +@bot.inline_handler(lambda query: query.query == 'text') +def query_text(inline_query): + # Query message is text +``` + +#### answer_inline_query + +```python +@bot.inline_handler(lambda query: query.query == 'text') +def query_text(inline_query): + try: + r = types.InlineQueryResultArticle('1', 'Result', inline_query.query) + r2 = types.InlineQueryResultArticle('2', 'Result2', inline_query.query) + bot.answer_inline_query(inline_query.id, [r, r2]) + except Exception as e: + print(e) + +``` + ## Advanced use of the API ### Asynchronous delivery of messages diff --git a/examples/inline_example.py b/examples/inline_example.py index 4273178..91ebb13 100644 --- a/examples/inline_example.py +++ b/examples/inline_example.py @@ -2,18 +2,35 @@ import telebot import time import sys +import logging from telebot import types API_TOKEN = '' bot = telebot.TeleBot(API_TOKEN) +telebot.logger.setLevel(logging.DEBUG) @bot.inline_handler(lambda query: query.query == 'text') -def query(inline_query): +def query_text(inline_query): try: r = types.InlineQueryResultArticle('1', 'Result', inline_query.query) - bot.answer_inline_query(inline_query.id, [r]) + r2 = types.InlineQueryResultArticle('2', 'Result2', inline_query.query) + bot.answer_inline_query(inline_query.id, [r, r2]) + except Exception as e: + print(e) + + +@bot.inline_handler(lambda query: query.query == 'photo') +def query_photo(inline_query): + try: + r = types.InlineQueryResultPhoto('1', + 'https://raw.githubusercontent.com/eternnoir/pyTelegramBotAPI/master/examples/detailed_example/kitten.jpg', + thumb_url='https://raw.githubusercontent.com/eternnoir/pyTelegramBotAPI/master/examples/detailed_example/kitten.jpg') + r2 = types.InlineQueryResultPhoto('2', + 'https://raw.githubusercontent.com/eternnoir/pyTelegramBotAPI/master/examples/detailed_example/rooster.jpg', + thumb_url='https://raw.githubusercontent.com/eternnoir/pyTelegramBotAPI/master/examples/detailed_example/rooster.jpg') + bot.answer_inline_query(inline_query.id, [r, r2]) except Exception as e: print(e)