From f336f178d9eb6ef2dd0d330344be3582fbc54c8e Mon Sep 17 00:00:00 2001 From: Ashley Williams Date: Thu, 26 May 2016 17:05:08 -0400 Subject: [PATCH] add help command --- src/resources/subscriptions/helpers.js | 1 + src/resources/subscriptions/routes/create.js | 67 ++++++++++++-------- 2 files changed, 40 insertions(+), 28 deletions(-) diff --git a/src/resources/subscriptions/helpers.js b/src/resources/subscriptions/helpers.js index be0397f..0a27a76 100644 --- a/src/resources/subscriptions/helpers.js +++ b/src/resources/subscriptions/helpers.js @@ -2,6 +2,7 @@ module.exports = { parseRequestBody: function (request) { var messages = request._body.split('&')[8].split('+'); return { + command: messages[0], type: messages[1], name: messages[2], event: messages[3], diff --git a/src/resources/subscriptions/routes/create.js b/src/resources/subscriptions/routes/create.js index c3f68e5..31d83f8 100644 --- a/src/resources/subscriptions/routes/create.js +++ b/src/resources/subscriptions/routes/create.js @@ -9,49 +9,60 @@ const Subscription = require("../model"); const helpers = require("../helpers"); const messenger = require("../messenger"); -var checkSub = function(info) { - User.where({ id: 1 }) - .fetch({ withRelated: ['subscriptions'] }) - .then(function(user) { - var subscriptions = user.related('subscriptions'); - for (var i=0; i `\n" + + "\n" + + "\t\t*command*: `subscribe` (create a new webhook), `help`\n" + + "\t\t*type*: `package` or `scope`\n" + + "\t\t*name*: the name of the package or scope, e.g. `lodash`\n" + + "\t\t*event*: this doesn't actually work yet :grimacing: :sweat_smile:\n"; + slack.chat.postMessage(channelID, message, opts); +}; + +// receive outgoing integration from slack `/captain-hook` +module.exports = function(request, response, next) { + var info = helpers.parseRequestBody(request); + var command = info.command.slice(5); + var message; + switch(command) { + case "subscribe": + subscribe(info); + break; + case "help": + help(); + break; + default: + help(); + break; + } next(); };