auth0/slash

Name: slash

Owner: Auth0

Description: Slash Webtasks: Extend Slack with Node.js

Created: 2016-12-15 21:55:49.0

Updated: 2018-02-24 01:11:43.0

Pushed: 2017-01-10 16:59:41.0

Homepage: https://webtask.io/slack

Size: 8

Language: null

GitHub Committers

UserMost Recent Commit# Commits

Other Committers

UserEmailMost Recent Commit# Commits

README

Slash Webtasks: Extend Slack With Node.js

Install on your Slack team
File an issue

Hello, world

After you have installed Slash Webtasks on your Slack team, you can create your first webtask by typing

make hello

in any Slack channel, and following the provided link to edit the code in Webtask Editor. The simplest webtask will immediately return a response:

le.exports = (ctx, cb) => cb(null, { text: 'Hello, world!' });

You can invoke your webtask from any Slack channel with /wt hello.

Type in /wt help to see all available operations.

Inputs and outputs

The ctx.body input parameter contains the payload which Slack sends to your webtask, e.g.:


am_id": "T025590N6",
am_domain": "auth0",
annel_id": "D1KFTMMTJ",
annel_name": "directmessage",
er_id": "U02FMKT1L",
er_name": "tomek",
mmand": "/wt run hello",
xt": "foo bar baz",
sponse_url": "https://hooks.slack.com/commands/T025540N6/86862216608/4DNA0LVn6QG7xqfBhGSTIqoc"

Note that ctx.body.text contains the parameters to the webtask you typed in Slack following /wt {webtask_name}. This allows users to pass arbitrary input parameters. Check out Slack documentation for more information about the input payload.

The response your command sends back to Slack is a JSON object and is fully documented in Slack docs. To test how it will render, use the response builder. The two most commonly used properties are:


ext": "This is the text of the response",
esponse_type": "in_channel" // you can omit this if you want the response 
                            // to be only visible to the caller

Sending responses

You can respond with a message that will be posted back to Slack by passing the Slack JSON response message as the second parameter to the callback function.

If you need to later post additinal messages to Slack (e.g. when longer running work completes), you can send similarly formatted JSON object via HTTP POST to the URL provided in ctx.body.response_url. You can do it multiple times.

This sample webtask demostrates this pattern:

le.exports = function (ctx, cb) {
 Send a response to indicate work has started.
 Useful if you foresee the code to take some time to comlete.
nc_response(cb, `:hourglass: Working on it...`);

tTimeout(() => {
// Once work is completed, results can be posted asynchronously
async_response(ctx, `Hello, @${ctx.body.user_name}!`);
 5000);


tion async_response(ctx, text, only_caller) {
quire('superagent').post(ctx.body.response_url)
.send({ text: text, response_type: only_caller ? 'emphemeral' : 'in_channel' })
.end();


tion sync_response(cb, text, only_caller) {
(null, { text: text, response_type: only_caller ? 'emphemeral' : 'in_channel' });


This work is supported by the National Institutes of Health's National Center for Advancing Translational Sciences, Grant Number U24TR002306. This work is solely the responsibility of the creators and does not necessarily represent the official views of the National Institutes of Health.