From d8acdd2cf6a19be5c43a6f34ce8c9aedd28fa116 Mon Sep 17 00:00:00 2001 From: Ryan Sydnor Date: Mon, 7 Oct 2019 21:47:06 -0400 Subject: [PATCH] Add support for modals https://api.slack.com/block-kit/surfaces/modals --- lib/Slack_web_api.js | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/lib/Slack_web_api.js b/lib/Slack_web_api.js index e8b0fb461..b58ea70d6 100755 --- a/lib/Slack_web_api.js +++ b/lib/Slack_web_api.js @@ -147,7 +147,10 @@ module.exports = function(bot, config) { 'users.lookupByEmail', 'users.setPhoto', 'users.profile.get', - 'users.profile.set' + 'users.profile.set', + 'views.open', + 'views.update', + 'views.push' ]; /** @@ -224,6 +227,21 @@ module.exports = function(bot, config) { slack_api.callAPI('chat.update', options, cb); }; + slack_api.views.open = function(options, cb) { + sanitizeOptions(options); + slack_api.callAPI('views.open', options, cb); + }; + + slack_api.views.update = function(options, cb) { + sanitizeOptions(options); + slack_api.callAPI('views.update', options, cb); + }; + + slack_api.views.push = function(options, cb) { + sanitizeOptions(options); + slack_api.callAPI('views.push', options, cb); + }; + // specify that files get uploaded using multipart slack_api.files.upload = function(options, cb) { slack_api.callAPI('files.upload', options, cb, !!options.file); @@ -246,6 +264,14 @@ module.exports = function(bot, config) { bot.log.error('Could not parse blocks', err); } } + if (options.view && typeof(options.view) != 'string') { + try { + options.view = JSON.stringify(options.view); + } catch (err) { + delete options.view; + bot.log.error('Could not parse view', err); + } + } }