Skip to content

Commit 805e355

Browse files
committed
Update readme.
1 parent 94d3474 commit 805e355

2 files changed

Lines changed: 47 additions & 2 deletions

File tree

‎README.md‎

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
* [Message handlers](#message-handlers)
1818
* [TeleBot](#telebot)
1919
* [Reply markup](#reply-markup)
20+
* [Inline Mode](#inlinemode)
2021
* [Advanced use of the API](#advanced-use-of-the-api)
2122
* [Asynchronous delivery of messages](#asynchronous-delivery-of-messages)
2223
* [Sending large text messages](#sending-large-text-messages)
@@ -321,6 +322,33 @@ ForceReply:
321322

322323
![ForceReply](https://pp.vk.me/c624430/v624430512/473ec/602byyWUHcs.jpg "ForceReply")
323324

325+
### Inline Mode
326+
327+
More information about [Inline mode](https://core.telegram.org/bots/inline).
328+
329+
#### inline_handler
330+
Now, you can use inline_handler to get inline_query in telebot.
331+
```python
332+
333+
@bot.inline_handler(lambda query: query.query == 'text')
334+
def query_text(inline_query):
335+
# Query message is text
336+
```
337+
338+
#### answer_inline_query
339+
340+
```python
341+
@bot.inline_handler(lambda query: query.query == 'text')
342+
def query_text(inline_query):
343+
try:
344+
r = types.InlineQueryResultArticle('1', 'Result', inline_query.query)
345+
r2 = types.InlineQueryResultArticle('2', 'Result2', inline_query.query)
346+
bot.answer_inline_query(inline_query.id, [r, r2])
347+
except Exception as e:
348+
print(e)
349+
350+
```
351+
324352
## Advanced use of the API
325353

326354
### Asynchronous delivery of messages

‎examples/inline_example.py‎

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,35 @@
22
import telebot
33
import time
44
import sys
5+
import logging
56
from telebot import types
67

78
API_TOKEN = '<api_token>'
89

910
bot = telebot.TeleBot(API_TOKEN)
11+
telebot.logger.setLevel(logging.DEBUG)
1012

1113

1214
@bot.inline_handler(lambda query: query.query == 'text')
13-
def query(inline_query):
15+
def query_text(inline_query):
1416
try:
1517
r = types.InlineQueryResultArticle('1', 'Result', inline_query.query)
16-
bot.answer_inline_query(inline_query.id, [r])
18+
r2 = types.InlineQueryResultArticle('2', 'Result2', inline_query.query)
19+
bot.answer_inline_query(inline_query.id, [r, r2])
20+
except Exception as e:
21+
print(e)
22+
23+
24+
@bot.inline_handler(lambda query: query.query == 'photo')
25+
def query_photo(inline_query):
26+
try:
27+
r = types.InlineQueryResultPhoto('1',
28+
'https://raw.githubusercontent.com/eternnoir/pyTelegramBotAPI/master/examples/detailed_example/kitten.jpg',
29+
thumb_url='https://raw.githubusercontent.com/eternnoir/pyTelegramBotAPI/master/examples/detailed_example/kitten.jpg')
30+
r2 = types.InlineQueryResultPhoto('2',
31+
'https://raw.githubusercontent.com/eternnoir/pyTelegramBotAPI/master/examples/detailed_example/rooster.jpg',
32+
thumb_url='https://raw.githubusercontent.com/eternnoir/pyTelegramBotAPI/master/examples/detailed_example/rooster.jpg')
33+
bot.answer_inline_query(inline_query.id, [r, r2])
1734
except Exception as e:
1835
print(e)
1936

0 commit comments

Comments
 (0)