diff --git a/lib/slack/format-dialog.js b/lib/slack/format-dialog.js index e2fb9a5..7f7bc15 100644 --- a/lib/slack/format-dialog.js +++ b/lib/slack/format-dialog.js @@ -1,7 +1,7 @@ 'use strict'; class SlackDialog { - constructor(token, triggerId, title, submitLabel, callbackId, notifyOnCancel = false) { + constructor(token, triggerId, title, submitLabel, callbackId, notifyOnCancel = false, state) { if (!token || !triggerId || !title) throw new Error('token, triggerId and title are requeired for dialog.open method'); @@ -21,6 +21,9 @@ class SlackDialog { if (notifyOnCancel && typeof(notifyOnCancel) !== 'boolean') throw new Error('notify_on_cancel needs to be a boolean'); + if (state && state.length > 3000) + throw new Error('state needs to be less or equal to 3000 characters'); + this.template = { token: token, trigger_id: triggerId, @@ -31,6 +34,9 @@ class SlackDialog { } }; + if (state) + this.template.dialog.state = state + if (submitLabel) this.template.dialog.submit_label = submitLabel; diff --git a/lib/slack/format-message.js b/lib/slack/format-message.js index 4ae5169..26ac925 100644 --- a/lib/slack/format-message.js +++ b/lib/slack/format-message.js @@ -198,7 +198,7 @@ class SlackTemplate { return this; } - addSelect(text, name, options, dataSource = 'static', minQueryLength) { + addSelect(text, name, options, dataSource = 'static', selectedOptions, minQueryLength) { if (this.getLatestAttachment().actions.length === 5) throw new Error('You can not add more than 5 actions'); @@ -227,6 +227,12 @@ class SlackTemplate { action.options = options; } + if (selectedOptions && !Array.isArray(selectedOptions)) + throw new Error('selectedOptions needs to be a valid array'); + + if (selectedOptions) + action.selected_options = selectedOptions; + if (dataSource) action.data_source = dataSource; diff --git a/lib/slack/parse.js b/lib/slack/parse.js index f2b74d5..1d890dd 100644 --- a/lib/slack/parse.js +++ b/lib/slack/parse.js @@ -26,4 +26,13 @@ module.exports = function(messageObject) { type: messageObject.type === 'dialog_submission' ? 'slack-dialog-confirm' : 'slack-dialog-cancel', postback: true }; + + if (messageObject && messageObject.user && (messageObject.type === 'view_submission')) + return { + sender: messageObject.user.id, + text: '', + originalRequest: messageObject, + type: 'view_submission', + postback: true + }; }; diff --git a/lib/slack/setup.js b/lib/slack/setup.js index f955f0d..9f6e04a 100644 --- a/lib/slack/setup.js +++ b/lib/slack/setup.js @@ -20,7 +20,7 @@ module.exports = function slackSetup(api, bot, logError, optionalParser, optiona || (request.post.trigger_word && request.post.token === request.env.slackWebhookToken)) return bot(parser(request.post), request) - .then(responder) + .then((botResponse) => responder(botResponse, request.env.slackToken)) .catch(logError); else return responder('unmatched token' + ' ' + request.post.token);