我想创建一个自定义键盘。
我有这个GAS代码:
function sendText(chatId,text){
var payload = { "method": "sendMessage", "chat_id": String(chatId),"text": text, "parse_mode": "HTML" }
var data = {
"method": "post",
"payload": payload,
"reply_markup": JSON.stringify({
"keyboard": [
[
"A",
"B"
],
[
"C",
"D"
]
],
"resize_keyboard":true
})
}
UrlFetchApp.fetch('https://api.telegram.org/bot' + token + '/', data);
}
它作为echo bot工作得很好,但我无法创建自定义键盘。它只是不起作用,我不明白为什么。我在网上搜索了解决方案,但我一无所获。请帮帮我:)
答案 0 :(得分:2)
在@Sean和@Kos的帮助下,我解决了我的问题,这是工作代码。我还添加了inline_keyboard类型。
function sendText(chatId,text,keyBoard){
keyBoard = keyBoard || 0;
if(keyBoard.inline_keyboard || keyBoard.keyboard){
var data = {
method: "post",
payload: {
method: "sendMessage",
chat_id: String(chatId),
text: text,
parse_mode: "HTML",
reply_markup: JSON.stringify(keyBoard)
}
}
}else{
var data = {
method: "post",
payload: {
method: "sendMessage",
chat_id: String(chatId),
text: text,
parse_mode: "HTML"
}
}
}
UrlFetchApp.fetch('https://api.telegram.org/bot' + token + '/', data);
}
keyBoard格式必须如下:
{
keyboard: [
[
"A",
"B"
],
[
"C",
"D"
]
],
resize_keyboard:true,
one_time_keyboard:true
}
{
inline_keyboard: [
[
{text:'Sandwich',callback_data:'sandwich'},
{text:'A juicy steak',callback_data:'steak'}
],
[
{text:'Sandwich2',callback_data:'sandwich2'},
{text:'A juicy steak2',callback_data:'steak2'}
]
]
}
答案 1 :(得分:1)
显示,请问您如何使用应用脚本中的callback_data?
答案 2 :(得分:0)