我有此代码,但是在使用我制作的功能键盘时显示消息和键盘无效。
function sendText(id,text) {
var url = telegramUrl + "/sendMessage?chat_id=" + id + "&text=" + text;
var response = UrlFetchApp.fetch(url);
Logger.log(response.getContentText());
}
function Keyboard (id, text, reply_markup ){
var url = telegramUrl + "/sendMessage?chat_id=" + id + "&text=" + text + "&reply_markup=" + reply_markup ;
var response = UrlFetchApp.fetch(url);
Logger.log(response.getContentText());
}
function doPost(e) {
// this is where telegram works
var data = JSON.parse(e.postData.contents);
var text = data.message.text;
var id = data.message.chat.id;
if (text == "/start"){
var message = "Selamat datang. Untuk mencari data pelanggan silahkan memasukkan @ODP_NAME.%0AContoh : @ODP-UBN-FAC/100";
var opts = JSON.stringify({
keyboard: [['OK','Cancel']],
one_time_keyboard: true,
resize_keyboard: true
})
;
//sendText(id, "hola", opts);
Keyboard(id,"hi", opts);
}
}
**,然后我尝试使用像这样的Function sendText()来使url为true,但这只是给我文本而不显示键盘。 **
sendText(id,"hi", {reply_markup: JSON.stringify({
keyboard: [['OK','Cancel']],
one_time_keyboard: true,
resize_keyboard: true
})
});
您能告诉我我的代码有什么问题吗?
答案 0 :(得分:0)
我认为您的reply_markup应该如下所示:
{
keyboard: [[{text: 'OK'}, {text: 'Cancel'}]],
one_time_keyboard: true,
resize_keyboard: true
}
答案 1 :(得分:0)
代替使用获取尝试使用后 例子:
var keyBoard =JSON.stringify({
"keyboard": [["OK","Cancel"]],
"one_time_keyboard":true,
"resize_keyboard":true
});
var url = "https://api.telegram.org/bot123456:ABC-DEF1234ghIkl-zyx57W2v1u123ew11";
function replyKeyboard(){
var formData = {
'chat_id': "1234567",
'text': 'Hello',
'reply_markup': keyBoard
};
var options = {
'method' : 'post',
'payload' : formData
};
UrlFetchApp.fetch(url + "/sendMessage?", options);
}