Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/soundTricker/SlackApp
Slack API Library for Google Apps Script
https://github.com/soundTricker/SlackApp
Last synced: 13 days ago
JSON representation
Slack API Library for Google Apps Script
- Host: GitHub
- URL: https://github.com/soundTricker/SlackApp
- Owner: soundTricker
- License: mit
- Created: 2014-12-08T02:08:18.000Z (almost 10 years ago)
- Default Branch: master
- Last Pushed: 2014-12-08T05:19:58.000Z (almost 10 years ago)
- Last Synced: 2024-08-01T06:20:45.060Z (3 months ago)
- Language: JavaScript
- Size: 148 KB
- Stars: 149
- Watchers: 13
- Forks: 18
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome-apps-script - SlackApp
README
SlackApp
========Slack API Library for Google Apps Script
## Library Key
```
M3W5Ut3Q39AaIwLquryEPMwV62A3znfOO
```## API Document
https://script.google.com/macros/library/versions/d/M3W5Ut3Q39AaIwLquryEPMwV62A3znfOO
## How to use.
### Use Slack API Token.
1. Import `SlackApp` library to your project. See [Documents](https://developers.google.com/apps-script/guide_libraries?hl=ja)
* Library Key `M3W5Ut3Q39AaIwLquryEPMwV62A3znfOO`
2. Get a Slack API token from [Slack](https://api.slack.com/).
3. Write a code!
```javascript
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;
}```
### Use OAuth2
TODO (Library is already supported, but not documented.)