slack-integrator
v0.1.0
Published
Express-based starter kit for creating Slack integrations
Downloads
4
Readme
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
Log into your Slack and configure a slash command integration that posts to
<your-integration-host.com>/integration
when a Slack user enters/some command
.Deploy a
node-slack-integrator
instance to<your-integration-host.com>
. Yournode-slack-integrator
instance should be instantiated with apayload
method & ahookPath
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
// 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/<YOUR_HOOK_PATH>
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.