0stone 0:解决了问题;谢谢,谢谢+谢谢;
ADW:感谢您对键盘对象的说明,采用;
基于JavaScript的Google应用程序将JSON对象发送给电报机器人;使用按钮实现基于电报的菜单,以便用户按下选定的按钮并执行相应的动作;
用户类型:菜单
按钮列表显示在“电报组”屏幕上。
解决办法如下:
function menu( chat_id ) {
let url = vUrlTelegram + "/sendMessage";
var keyboard = {
'inline_keyboard' :
[
[{'text' : 'admin', 'callback_data' : 'admin'}], // Row 1
[{'text' : 'squad', 'callback_data' : 'squad'}], // Row 2
[{'text' : 'carioca', 'callback_data' : 'carioca'}], // Row 3
[{'text' : 'brasileiro', 'callback_data' : 'brasileiro'}], // Row 4
[{'text' : 'sponsors', 'callback_data' : 'sponsors'}], // Row 5
[{'text' : 'test', 'callback_data' : 'test'}] // Row 6
]
};
var data = {
'chat_id': chat_id,
'text': "main menu",
'reply_markup': keyboard
};
var options = {
'method' : 'post',
'contentType': 'application/json',
'payload' : JSON.stringify(data)
};
var response = UrlFetchApp.fetch(url, options);
Logger.log(response);
}
发布于 2020-04-05 15:16:23
刚刚度过了一个繁忙的周末;)
设法使它在谷歌应用程序脚本中工作;
function myFunction() {
let token = '123456788:AAdadadadbMTcMvY10SZGsbIJ2rdFXJiXmbFw';
let url = "https://api.telegram.org/bot" + token + "/sendMessage";
var options = {
'method' : 'post',
'contentType': 'application/json',
'payload' : JSON.stringify({
'chat_id': 11111111,
'text': 'fsdfdsfsdf',
'reply_markup': {
inline_keyboard: [
[{ text: 'Some button text 1', callback_data: '1' }],
[{ text: 'Some button text 2', callback_data: '2' }],
[{ text: 'Some button text 3', callback_data: '3' }]
]
}
})
};
var response = UrlFetchApp.fetch(url, options);
var res = UrlFetchApp.fetch(url);
Logger.log(res);
}
问题在于嵌套的有效载荷/ reply_markup对象。
发布于 2020-04-05 12:23:51
这假设您试图使用Google脚本将内联键盘发送到Telegram。
我编写了这个示例脚本,它可能会有帮助:
function sample_inlineKeyboard() {
var chat_id = '123456789';
var text = 'Please pick a button:';
var keyboard = {
'inline_keyboard' :
[
[{'text' : 'blue', 'callback_data' : 'blue'},
{'text' : 'green', 'callback_data' : 'green'},
{'text' : 'red', 'callback_data' : 'red'}], // Row 1
[{'text' : 'yellow', 'callback_data' : 'yellow'},
{'text' : 'brown', 'callback_data' : 'brown'},
{'text' : 'black', 'callback_data' : 'black'}] // Row 2
]
}
var data = {
'chat_id': chat_id,
'text': text,
'reply_markup': keyboard
};
var options = {
'method' : 'post',
'contentType': 'application/json',
'payload' : JSON.stringify(data)
};
var token = "0123456789:AABBCC....."; // Bot token
var vUrlTelegram = 'https://api.telegram.org/bot' + token + '/sendMessage';
var response = UrlFetchApp.fetch(vUrlTelegram, options);
Logger.log(response);
}
https://stackoverflow.com/questions/61039034
复制相似问题