Skip to content

Selected options is message menu #129

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 12 commits into
base: master
Choose a base branch
from
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