1 year ago
#289319
Albaraa Kefaya
Slack command does not trigger App script
I have created a slack app and granted it the needed permissions, then I added a slack command that is connected to a simple google app script that adds info to a google sheet and installed the app on my slack workspace. But when I try to use the command, I always get /register failed with the error "dispatch_failed" and from the logs, I can tell that the request is not reaching the script.
The app script
function doPost(request){
console.log("GOT here");
var params = request.parameter;
var text = params.text; //the options provided after the command as a single string
//visit https://api.slack.com/slash-commands/#app_command_handling for available payload sent by slack
var names = text.split(" ");
var firstName = names[0];
var lastName = names[1];
addRow(firstName, lastName);//call function to add row as declared below
var response = {
"response_type": "ephemeral",
"text": firstName + " " + lastName +" has been added to our records",
};
//finally we return the reponse back to slack
return ContentService.createTextOutput(JSON.stringify(response)).setMimeType(ContentService.MimeType.JSON);
}
function addRow(firstName, lastName) {
// more info https://developers.google.com/apps-script/guides/sheets
var sheet = SpreadsheetApp.getActiveSheet();
sheet.appendRow([firstName, lastName]);//adds a new row to the sheet
}
Can you please help to find why it is not working as expected?
google-apps-script
web-applications
http-post
slack
slack-commands
0 Answers
Your Answer