-
Notifications
You must be signed in to change notification settings - Fork 0
Tutorial: Slack slash command
This tutorial will guide you through creation of the pipeline that will act as a receiver for Slack slash command. It assumes that you have either registered at cloud version of Exynize or deployed your own copy of the platform, and finished the "Hello world" tutorial.
First, we'll create a source component that will accept requests from Slack slash commands.
Here's how the code will look:
const subj = new Rx.Subject();
// listen for all requests
export const routeHandler = (req) => subj.onNext(req);
// main function
export default (obs) => {
// (optional) send init for debugging purposes
obs.onNext('init');
// pipe HTTP requests to output
subj.subscribe(obs);
};
This component will keep dispatching HTTP requests as they come in without ever completing (so, it has to be stopped manually).
Next, we'll create a simple stringify component that will output stringified version of incoming object.
Here's how the code will look:
export default (data) => {
return Rx.Observable.return(`Here's what we've got: ${JSON.stringify(data)}`);
};
Since we don't really need a renderer for this pipeline, we'll use basic string renderer from "Hello world" tutorial for debugging purposes.
Now that all the components have been created, we need to assemble them into a pipeline.
No configuration for the source or components is required.
Make sure to test the pipeline by pressing "Test" button before saving it using the "Save" button.
After you have assembled the pipeline and know its URI, you can create and configure new Slack slash command using this link.
Now that you've assembled, tested and saved your new pipeline, you can start it and view the rendered result by clicking "Web" button next to pipeline name.
Once you send execute slash command in Slack, you should see the incoming request appear in web UI immediately.