Reputation: 11
I have this code, but it doesn't work to showing message and keyboard while using Function Keyboard that I made.
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);
}
}
**and then i try to use Function sendText() like this to make the url true, but it's only give me the text and not showing the keyboard. **
sendText(id,"hi", {reply_markup: JSON.stringify({
keyboard: [['OK','Cancel']],
one_time_keyboard: true,
resize_keyboard: true
})
});
Can you tell me what's wrong with my code?
Upvotes: 0
Views: 2042
Reputation: 11
instead of use get try use post example :
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);
}
Upvotes: 1
Reputation: 364
i think your reply_markup should look like this:
{
keyboard: [[{text: 'OK'}, {text: 'Cancel'}]],
one_time_keyboard: true,
resize_keyboard: true
}
Upvotes: 0