TL;DR - I would like to setup a Slack slash command that works on Google Apps Script. How do you recommend I do so?
Context:
I currently use google.com/script with Sheets to trigger a webhook call to Slack when someone fills out a Google Form. Here it is for reference. My question is an additional feature I'd like to add that won't overlap with this code.
I want to listen in Google Apps for a Slack slash command, so I've been looking through tons of examples of callbacks. I don't understand the dance necessary to get this going. Here are the variables:
token for verification of the outgoing payload. client ID and secret token.https://script.google.com/macros/d/{SCRIPT ID}/usercallback, but if I'm reading it correctly in this guide it would require user authorizationI've reviewed other questions that mention callback (this and this) but haven't found anything relevant.
Guidance toward the next steps of just being able to configure a callback URL and understand how it will authentication and ultimately consume the API call from Slack in Google would be awesome.
You are on the right track, i'm fiddling around with this since couple of weeks so maybe this helps:
Google App Script
https://script.google.com/macros/s/xxx-ver-long-number-xxx/execSlack Integrations
Create new Slash Command
Method POST / URL: Paste The url from your web app
Copy the Secure Token, you need it in the Google App Script
Set all the other settings as you like.
Don't forget to save
Back to Google App Script
Copy paste this basic stuff
function doPost(request) {
//// SET SECURITY TOKEN (FROM SLACK COMMAND)
var your_token = "YOUR_SLASH_COMMAND_TOKEN";
var output;
//// GET PARAMETES FROM SLACK POST REQUEST
var params = request.parameters;
//// ... and store them into variables
var cmd_token = params.token; // or params.token[0] idk
//// CHECK RECEIVED TOKEN AGAINST YOUR SAVED TOKEN
if (your_token == cmd_token) {
output = {"text":"SUCCESS"};
} else {
output = {"text":"INVALID TOKEN"};
}
//// SEND RESPONSE BACK TO SLACK
return ContentService.createTextOutput(JSON.stringify(output)).setMimeType(ContentService.MimeType.JSON);
}
Save script and again publish the script as web app (you have to do this everytime you change something, always choose "new" as version
Additional Info
This is the stuff you get from every slash command. In the example above I only use token ...
token=gIkuvaNzQIHg97ATvDxqgjtO
team_id=T0001
team_domain=example
channel_id=C2147483705
channel_name=test
user_id=U2147483697
user_name=Steve
command=/weather
text=94070
response_url=https://hooks.slack.com/commands/1234/5678
Works perfect for me, hope it helps :) Good luck !
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With