Slack API Library for Google Apps Script
M3W5Ut3Q39AaIwLquryEPMwV62A3znfOO
https://script.google.com/macros/library/versions/d/M3W5Ut3Q39AaIwLquryEPMwV62A3znfOO
- Import
SlackApp
library to your project. See Documents
- Library Key
M3W5Ut3Q39AaIwLquryEPMwV62A3znfOO
- Get a Slack API token from Slack.
- Write a code!
function myFunction(){
//Get properties.
var prop = PropertiesService.getUserProperties().getProperties();
//Create an instance.
var slackApp = SlackApp.create(prop.slackToken);
//My first Message!
slackApp.chatPostMessage(prop.slackChannel, "Hi Slack.", {
username : "My First Bot",
icon_emoji : ":+1:"
});
}
//If you want to create a replyable bot, you can use doGet method and [Outgoing WebHooks](https://exchaos.slack.com/services/new/outgoing-webhook) via Slack.
function doGet(e) {
//Get properties.
var prop = PropertiesService.getScriptProperties().getProperties();
if (!e) {
//for Test
e = {
parameter : {
token : prop.verifyToken,
team_id : "T0001",
channel_id : "C2147483705",
channel_name : "test",
timestamp : "1355517523.000005",
user_id : "U2147483697",
user_name : "Steve",
text : "MyFirstBot: Hi",
trigger_word : "MyFirstBot:"
}
};
}
if (prop.verifyToken != e.parameter.token) {
throw new Error("invalid token.");
}
//Create an instance.
var slackApp = SlackApp.create(prop.slackToken);
//My first Message!
slackApp.chatPostMessage(e.parameter.channel_id, "Hi " + e.parameter.user_name, {
username : "My First Bot",
icon_emoji : ":+1:"
});
return null;
}
TODO (Library is already supported, but not documented.)