1
0
mirror of https://github.com/eternnoir/pyTelegramBotAPI.git synced 2023-08-10 21:12:57 +03:00

Almost done.

This commit is contained in:
eternnoir 2016-01-05 14:07:47 +08:00
parent c706a7aba3
commit 94f1bbd402
2 changed files with 30 additions and 4 deletions

View File

@ -415,6 +415,9 @@ class TeleBot:
"""
return self.send_message(message.chat.id, text, reply_to_message_id=message.message_id, **kwargs)
def answer_inline_query(self, inline_query_id, results, cache_time=None, is_personal=None, next_offset=None):
return apihelper.answer_inline_query(self.token, inline_query_id, results, cache_time, is_personal, next_offset)
def register_for_reply(self, message, callback):
"""
Registers a callback function to be notified when a reply to `message` arrives.

View File

@ -258,11 +258,34 @@ def get_method_by_type(data_type):
return r'sendSticker'
def answer_inline_query(token, inline_query_id, results, cache_time=None, is_personal=None, next_offset=None):
method_url = 'answerInlineQuery'
payload = {'inline_query_id': inline_query_id, 'results': _convert_inline_results(results)}
if cache_time:
payload['cache_time'] = cache_time
if is_personal:
payload['is_personal'] = is_personal
if next_offset:
payload['next_offset'] = next_offset
return _make_request(token, method_url, params=payload)
def _convert_inline_results(results):
ret = ''
for r in results:
if isinstance(r, types.JsonSerializable):
ret = ret + r.to_json() + ','
if len(ret) > 0:
ret = ret[:-1]
return '[' + ret + ']'
def _convert_markup(markup):
if isinstance(markup, types.JsonSerializable):
return markup.to_json()
return markup
class ApiException(Exception):
"""
This class represents an Exception thrown when a call to the Telegram API fails.