Skip to content
8 changes: 7 additions & 1 deletion lib/slack/format-dialog.js
Original file line number Diff line number Diff line change
@@ -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');

Expand All @@ -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,
Expand All @@ -31,6 +34,9 @@ class SlackDialog {
}
};

if (state)
this.template.dialog.state = state

if (submitLabel)
this.template.dialog.submit_label = submitLabel;

Expand Down
8 changes: 7 additions & 1 deletion lib/slack/format-message.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');

Expand Down Expand Up @@ -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;

Expand Down
9 changes: 9 additions & 0 deletions lib/slack/parse.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
};
};
2 changes: 1 addition & 1 deletion lib/slack/setup.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down