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
Add support for dynamic suggestions in slack dialogs. #116
Conversation
Pull Request Test Coverage Report for Build 378
💛 - Coveralls |
Hi @kkaehler, so I was catching up on dynamic selects inside of dialogs, and it turns out they're already supported inside of // Another module for building slack message json, optional
const smb = require('slack-message-builder')
const Slapp = require('slapp')
let slapp = Slapp({
// ...whatever options you need for setting up Slapp
})
// Attach it to express, will use the default of '/slack/options' for the options route
slapp.attachToExpress(httpServer)
// Listen for a DM to the bot of "dialog_dynamic_menu" and provide a button for the dialog
slapp.message('dialog_dynamic_menu', ['direct_message'], msg => {
let message = smb('Dialog w/ dynamic menu')
.attachment()
.callbackId('dialog/dynamic')
.button('dyn_menu_dialog', 'Open Dialog')
.value('my-dialog')
.end()
.end()
msg.say(message.json())
})
// Handle the button click and open the dialog
slapp.action('dialog/dynamic', 'dyn_menu_dialog', msg => {
let triggerId = msg.body.trigger_id
let dialog = {
callback_id: 'dialog/dynamic/submit',
title: 'Dynamic Dropdown',
submit_label: 'Request',
elements: [
{
label: 'Dynamic Select',
name: 'dynamic_select',
type: 'select',
data_source: 'external'
}
]
}
msg.respond()
let params = { trigger_id: triggerId, dialog, token: msg.meta.bot_token }
slapp.client.dialog.open(params, (err, result) => {
if (err) {
console.error(err, `Error opening Slack dialog`)
}
})
})
// Provide a handler for dyanmic options
slapp.options('dialog/dynamic/submit', 'dynamic_select', (msg, values) => {
let val = Array.isArray(values) ? values[0] : values
// you could use this value to filter your options returned (it's what the user type in)
console.log(val)
let options = [
{
label: '[UXD-342] The button color should be artichoke green, not jalapeño',
value: 'UXD-342'
},
{
label: '[FE-459] Remove the marquee tag',
value: 'FE-459'
},
{
label: '[FE-238] Too many shades of gray in master CSS',
value: 'FE-238'
}
]
msg.respond({ options })
})
// Handle submission of the dialog
slapp.dialog('dialog/dynamic/submit', (msg, submission) => {
let value = submission.dynamic_select
// Allows dialog to close successfully
msg.respond()
// Send a follow-up message with response
let message = smb('Got your response')
.attachment()
.field('Dynamic Select')
.value(value)
.end()
.end()
msg.say(message.json())
}) |
@selfcontained works for me! thanks for the example. |
No description provided.