| 215 | |
| 216 | // Slack slash command handler |
| 217 | function slackSlashCommand(req, res, next) { |
| 218 | if (req.body.command === '/interactive-example') { |
| 219 | const type = req.body.text.split(' ')[0]; |
| 220 | if (type === 'button') { |
| 221 | res.json(interactiveButtons); |
| 222 | } else if (type === 'menu') { |
| 223 | res.json(interactiveMenu); |
| 224 | } else if (type === 'dialog') { |
| 225 | res.send(); |
| 226 | (async () => { |
| 227 | try { |
| 228 | // Open dialog |
| 229 | const response = await web.dialog.open({ |
| 230 | trigger_id: req.body.trigger_id, |
| 231 | dialog, |
| 232 | }); |
| 233 | } catch (error) { |
| 234 | axios.post(req.body.response_url, { |
| 235 | text: `An error occurred while opening the dialog: ${error.message}`, |
| 236 | }).catch(console.error); |
| 237 | } |
| 238 | })(); |
| 239 | } else { |
| 240 | res.send('Use this command followed by `button`, `menu`, or `dialog`.'); |
| 241 | } |
| 242 | } else { |
| 243 | next(); |
| 244 | } |
| 245 | } |
| 246 | |
| 247 | // Helpers |
| 248 | function formatNeighborhoodsAsOptions(neighborhoods) { |