I'm building my first Chat app where I post an interactive card with two buttons: Approve and Reject. I created my card where I specify function name for Apps script. The script should get two parameters sent with the event.
At the moment, the buttons are visible OK. But when I click any of the two buttons, I don't see any trace of this click in Logs Explorer. So, how do I debug this situation.
These are my button list:
` "buttonList": {
"buttons": [
{
"text": "Approve",
"onClick": {
"action": {
"function": "postToApprove",
"parameters": [
{
"key": "url",
"value": "https://example.com"
},
{
"key": "body",
"value": "{.......}"
}
]
}
}
},
{
"text": "Reject",
"onClick": {
"action": {
"function": "postToReject",
"parameters": [
{
"key": "url",
"value": "https://example.com"
},
{
"key": "body",
"value": "{.......}"
}
]
}
}
}
],
}
},
],
`
and this is my Apps script to response to the click:
`/**
* Responds to a CARD_CLICKED event triggered in Hangouts Chat.
*
* @param event the event object from Hangouts Chat
* @return JSON-formatted response
*/
function onCardClick(event) {
console.info(event);
console.log(event);
var message = "";
var urlToCall = event.action.parameters[0].value;
var bodyToPass = event.action.parameters[1].value;
if (event.action.actionMethodName == "postToApprove") {
postToApprove(urlToCall, bodyToPass);
message = "Invoked approval process.";
} else if (event.action.actionMethodName == "postToReject") {
blockOutCalendar(urlToCall, bodyToPass);
message = "Invoked rejection process.";
} else {
message = "I'm sorry; I'm not sure which button you clicked.";
}
return { "text": message };
}
/**
* Turns on the user's vacation response for today in Gmail.
*
* @param urlToCall URL to invoke to approve a subscription
* @param bodyToPass body of the POST request
*/
function postToApprove(urlToCall, bodyToPass) {
var currentTime = (new Date()).getTime();
// Declare option for invoking our API
var options = {
'method': 'post',
'payload': bodyToPass,
'contentType': 'application/json'
};
UrlFetchApp.fetch(urlToCall, options);
}
`
I've used this video as an example to build my project and script: https://youtu.be/dUjn3DfYMno
My understanding that Logs Explorer should have some traces of the script invocation. FYI, if I push the "Run" button in the script editor, I can see error messages in the Logs Explorer, so it looks like the right place to find any log.