https://github.com/mdb/node-slack-integrator
An Express-based starter kit for creating Slack integrations
https://github.com/mdb/node-slack-integrator
Last synced: 8 months ago
JSON representation
An Express-based starter kit for creating Slack integrations
- Host: GitHub
- URL: https://github.com/mdb/node-slack-integrator
- Owner: mdb
- License: mit
- Created: 2015-01-25T21:56:15.000Z (over 11 years ago)
- Default Branch: master
- Last Pushed: 2016-07-01T12:02:44.000Z (almost 10 years ago)
- Last Synced: 2025-04-09T03:13:51.936Z (about 1 year ago)
- Language: JavaScript
- Size: 19.5 KB
- Stars: 7
- Watchers: 2
- Forks: 1
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
[](https://travis-ci.org/mdb/node-slack-integrator)
# node-slack-integrator
A very simple Express-based server for creating Slack integrations.
`node-slack-integrator` runs an Express server with an `/integration` endpoint.
## How to use
1. Log into your Slack and configure a slash command integration that posts to `/integration` when a Slack user enters `/some command`.
2. Deploy a `node-slack-integrator` instance to ``. Your `node-slack-integrator` instance should be instantiated with a `payload` method & a `hookPath` property.
The `payload` method receives Slack's post request and generates the appropriate payload your integration should post in your Slack.
The `hookPath` property specifies the unique part of your Slack hook endpoint. This can be found in your Slack's admin.
## Example
```javascript
// slack_integration.js
var Integrator = require('slack-integrator');
new Integrator({
// a 'payload' method to generate a Slack-formatted payload object
// this method receives the request Slack issues to your integration
// in response to a user's `/command`, as well as a callback called
// with the Slack-formatted payload object
payload: function(request, callback) {
// this should return the payload object containing the
// data you wish to display in Slack
// see Slack documentation regarding its format
// example:
callback({
username: 'my bot',
text: 'some text',
channel: request.body.channel_id,
icon_emoji: ':ghost:'
});
},
// optional; if set, this ensures against requests from un-authorized Slacks
token: 'the token provided by your Slack instance',
// https://hooks.slack.com/services/
hookPath: "the path to your Slack instance's hook endpoint"
});
```
Running `node slack_integration.js` runs an Express app at port 3000. Port 3000 can be overridden via a `PORT` environment variable, or by a `port` declared on the options object passed to your integrator during instantiation.
The slack integration instance's `/integration` endpoint can be used to receive slash command-prompted POST requests from Slack.