电报机器人 api 键盘 [英] Telegram bot api keyboard

查看:70
本文介绍了电报机器人 api 键盘的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在使用 Telegram Bot Api 和ReplyKeyboard"时遇到问题.我正在使用 Python 2.7 并发送 post 请求:

I have problem with Telegram Bot Api and with "ReplyKeyboard". I'm using Python 2.7 and I send post request:

TelegramAPI.post(TELEGRAM_URL + "sendMessage", data=dict(chat_id=CHAT_ID, text="", keyboard={'keyboard': keyboard, 'one_time_keyboard': False, 'resize_keyboard': True})

这种格式的键盘:

[["A button"], ["B button"]]

但是在 Telegram 中我没有看到键盘.可能是什么问题?

But in Telegram I don't see keyboard. What problem can be?

推荐答案

根据 Bot API 文档,自定义键盘需要一个 reply_markup 参数,其值为键盘的 JSON 序列化规范.假设您的 TelegramAPI.post() 函数没有为您进行 JSON 序列化,我会尝试以下操作:

According to the Bot API documentations, a custom keyboard requires a reply_markup parameter, whose value is a JSON-serialized specification of the keyboard. Assuming your TelegramAPI.post() function does not JSON-serialize for you, I would try the following:

import json

json_keyboard = json.dumps({'keyboard': [["A button"], ["B button"]], 
                            'one_time_keyboard': False, 
                            'resize_keyboard': True})

TelegramAPI.post(TELEGRAM_URL + "sendMessage", 
                 data=dict(chat_id=CHAT_ID, 
                           text="Has to be non-empty", 
                           reply_markup=json_keyboard))

注意 text 必须非空.

这篇关于电报机器人 api 键盘的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆