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

Support ReplyKeyboardMarkup object.

This commit is contained in:
eternnoir 2015-06-30 13:20:44 +08:00
parent 9e27680266
commit 77580e6784
3 changed files with 23 additions and 5 deletions

View File

@ -111,6 +111,18 @@ tb.send_location(chat_id, lat, lon)
# find_location. # find_location.
tb.send_chat_action(chat_id, action_string) tb.send_chat_action(chat_id, action_string)
# ReplyKeyboardMarkup.
# Use ReplyKeyboardMarkup class.
# Thanks pevdh.
markup = types.ReplyKeyboardMarkup()
markup.add('a', 'v', 'd')
tb.send_message(chat_id, message, None, None, markup)
# or use row method
markup = types.ReplyKeyboardMarkup()
markup.row('a', 'v')
markup.row('c', 'd', 'e')
tb.send_message(chat_id, message, None, None, markup)
``` ```
## Message notifier ## Message notifier

View File

@ -2,7 +2,7 @@
from setuptools import setup from setuptools import setup
setup(name='pyTelegramBotAPI', setup(name='pyTelegramBotAPI',
version='0.1.7', version='0.1.8',
description='Python Telegram bot api. ', description='Python Telegram bot api. ',
author='eternnoir', author='eternnoir',
author_email='eternnoir@gmail.com', author_email='eternnoir@gmail.com',

View File

@ -3,6 +3,7 @@
import requests import requests
import telebot import telebot
from telebot import types
def get_me(token): def get_me(token):
@ -33,7 +34,7 @@ def send_message(token, chat_id, text, disable_web_page_preview=None, reply_to_m
if reply_to_message_id: if reply_to_message_id:
payload['reply_to_message_id'] = reply_to_message_id payload['reply_to_message_id'] = reply_to_message_id
if reply_markup: if reply_markup:
payload['reply_markup'] = reply_markup payload['reply_markup'] = convert_markup(reply_markup)
req = requests.get(request_url, params=payload) req = requests.get(request_url, params=payload)
return check_result(method_url, req) return check_result(method_url, req)
@ -69,7 +70,7 @@ def send_photo(token, chat_id, photo, caption=None, reply_to_message_id=None, re
if reply_to_message_id: if reply_to_message_id:
payload['reply_to_message_id'] = reply_to_message_id payload['reply_to_message_id'] = reply_to_message_id
if reply_markup: if reply_markup:
payload['reply_markup'] = reply_markup payload['reply_markup'] = convert_markup(reply_markup)
req = requests.post(request_url, params=payload, files=files) req = requests.post(request_url, params=payload, files=files)
return check_result(method_url, req) return check_result(method_url, req)
@ -82,7 +83,7 @@ def send_location(token, chat_id, latitude, longitude, reply_to_message_id=None,
if reply_to_message_id: if reply_to_message_id:
payload['reply_to_message_id'] = reply_to_message_id payload['reply_to_message_id'] = reply_to_message_id
if reply_markup: if reply_markup:
payload['reply_markup'] = reply_markup payload['reply_markup'] = convert_markup(reply_markup)
req = requests.get(request_url, params=payload) req = requests.get(request_url, params=payload)
return check_result(method_url, req) return check_result(method_url, req)
@ -105,7 +106,7 @@ def send_data(token, chat_id, data, data_type, reply_to_message_id=None, reply_m
if reply_to_message_id: if reply_to_message_id:
payload['reply_to_message_id'] = reply_to_message_id payload['reply_to_message_id'] = reply_to_message_id
if reply_markup: if reply_markup:
payload['reply_markup'] = reply_markup payload['reply_markup'] = convert_markup(reply_markup)
req = requests.post(request_url, params=payload, files=files) req = requests.post(request_url, params=payload, files=files)
return check_result(method_url, req) return check_result(method_url, req)
@ -132,6 +133,11 @@ def check_result(func_name, result):
raise ApiError(func_name + r' error.', result) raise ApiError(func_name + r' error.', result)
return result_json return result_json
def convert_markup(markup):
if isinstance(markup, types.ReplyKeyboardMarkup):
return markup.to_json()
else:
return markup
class ApiError(Exception): class ApiError(Exception):
def __init__(self, message, result): def __init__(self, message, result):