Slack Bolt Integration

This flow create examples for the https://flows.nodered.org/node/@headless-architecture/node-red-contrib-slack-bolt

  • simple text messages
  • block elements
  • listen for bot mentions send action events
[{"id":"1fd29692524d1ecb","type":"tab","label":"Slack Bolt","disabled":false,"info":"","env":[]},{"id":"9abaac9bbddc9bce","type":"group","z":"1fd29692524d1ecb","name":"","style":{"fill":"#bfc7d7","label":true},"nodes":["66d82a9b2adba28f","a1af82db52869929","2c5427b594cdc27d","b4ccc9f550d6192e","96f668735a340977","0be1a3a745d4345b","a8f863a194453f25","3701e2672d1605c0","ada60a61dc4363ca","abd1fa9196265fd6","e1bae9dec89865d5","222f70122d1d13d3","85f483cbc0729943","9326c16c34564ce9","509fc660e5a7454f","b9b5a6a13cde4552"],"x":134,"y":199,"w":1372,"h":682},{"id":"a1af82db52869929","type":"function","z":"1fd29692524d1ecb","g":"9abaac9bbddc9bce","name":"Events","func":"msg.SlackBolt = {\n    actions: [],\n    commands: [],\n    events: [],\n    shortcuts: [],\n    options: [],\n    messages: []\n};\nmsg.SlackBolt.actions.push(\n    {\n        'id': 'button_click',\n        'callback':\n            async ({ body, ack, say }) => {\n                // Acknowledge the action\n                await ack();\n                return await say(`<@${body.user.id}> clicked the button2x`);\n\n            }\n    }\n);\n\n\n\nmsg.SlackBolt.commands.push(\n    {\n        'id': '/node-red',\n        'callback':\n            async ({ command, ack, respond }) => {\n                // Acknowledge command request\n                await ack();\n\n                await respond(`${command.text}`);\n            }\n    }\n);\n\n\n\nmsg.SlackBolt.shortcuts.push({\n    'id': 'need_drink',\n    'callback':\n        async ({ shortcut, ack, client, logger }) => {\n            // Acknowledge shortcut request\n            await ack();\n\n            // Call the views.open method using one of the built-in WebClients\n            const result = await client.views.open({\n                trigger_id: shortcut.trigger_id,\n                view: {\n                    type: \"modal\",\n                    title: {\n                        type: \"plain_text\",\n                        text: \"My Node-Red Demo App\"\n                    },\n                    blocks: [\n                        {\n                            \"type\": \"section\",\n                            \"text\": {\n                                \"type\": \"mrkdwn\",\n                                \"text\": \"You have a new request:\\n*<fakeLink.toEmployeeProfile.com|Fred Enriquez - New device request>*\"\n                            }\n                        },\n                        {\n                            \"type\": \"section\",\n                            \"fields\": [\n                                {\n                                    \"type\": \"mrkdwn\",\n                                    \"text\": \"*Type:*\\nComputer (laptop)\"\n                                },\n                                {\n                                    \"type\": \"mrkdwn\",\n                                    \"text\": \"*When:*\\nSubmitted Aut 10\"\n                                },\n                                {\n                                    \"type\": \"mrkdwn\",\n                                    \"text\": \"*Last Update:*\\nMar 10, 2015 (3 years, 5 months)\"\n                                },\n                                {\n                                    \"type\": \"mrkdwn\",\n                                    \"text\": \"*Reason:*\\nAll vowel keys aren't working.\"\n                                },\n                                {\n                                    \"type\": \"mrkdwn\",\n                                    \"text\": \"*Specs:*\\n\\\"Cheetah Pro 15\\\" - Fast, really fast\\\"\"\n                                }\n                            ]\n                        },\n                        {\n                            \"type\": \"actions\",\n                            \"elements\": [\n                                {\n                                    \"type\": \"button\",\n                                    \"text\": {\n                                        \"type\": \"plain_text\",\n                                        \"emoji\": true,\n                                        \"text\": \"Approve\"\n                                    },\n                                    \"style\": \"primary\",\n                                    \"value\": \"drink_approve\"\n                                },\n                                {\n                                    \"type\": \"button\",\n                                    \"text\": {\n                                        \"type\": \"plain_text\",\n                                        \"emoji\": true,\n                                        \"text\": \"Deny\"\n                                    },\n                                    \"style\": \"danger\",\n                                    \"value\": \"drink_deny\"\n                                }\n                            ]\n                        }\n                    ]\n                }\n            });\n\n        }\n\n})\n\nmsg.SlackBolt.shortcuts.push({\n    'id': 'open_modal',\n    'callback':\n        async ({ shortcut, ack, client, logger }) => {\n            // Acknowledge shortcut request\n            await ack();\n\n            // Call the views.open method using one of the built-in WebClients\n            const result = await client.views.open({\n                trigger_id: shortcut.trigger_id,\n                view: {\n                    type: \"modal\",\n                    title: {\n                        type: \"plain_text\",\n                        text: \"My Node-Red Demo App\"\n                    },\n                    close: {\n                        type: \"plain_text\",\n                        text: \"Close\"\n                    },\n                    blocks: [\n                        {\n                            type: \"section\",\n                            text: {\n                                type: \"mrkdwn\",\n                                text: \"About the simplest modal you could conceive of :smile:\\n\\nMaybe <https://api.slack.com/reference/block-kit/interactive-components|*make the modal interactive*> or <https://api.slack.com/surfaces/modals/using#modifying|*learn more advanced modal use cases*>.\"\n                            }\n                        },\n                        {\n                            type: \"context\",\n                            elements: [\n                                {\n                                    type: \"mrkdwn\",\n                                    text: \"Psssst this modal was designed using <https://api.slack.com/tools/block-kit-builder|*Block Kit Builder*>\"\n                                }\n                            ]\n                        }\n                    ]\n                }\n            });\n\n        }\n\n})\n\n\nreturn msg;","outputs":1,"timeout":0,"noerr":0,"initialize":"","finalize":"","libs":[],"x":610,"y":620,"wires":[["a8f863a194453f25"]]},{"id":"66d82a9b2adba28f","type":"inject","z":"1fd29692524d1ecb","g":"9abaac9bbddc9bce","name":"Register Slack Actions and Events (once)","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":true,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":340,"y":620,"wires":[["a1af82db52869929"]]},{"id":"2c5427b594cdc27d","type":"debug","z":"1fd29692524d1ecb","g":"9abaac9bbddc9bce","name":"debug 3","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":1400,"y":600,"wires":[]},{"id":"b4ccc9f550d6192e","type":"switch","z":"1fd29692524d1ecb","g":"9abaac9bbddc9bce","name":"listener","property":"topic","propertyType":"msg","rules":[{"t":"eq","v":"button_click","vt":"str"},{"t":"else"}],"checkall":"true","repair":false,"outputs":2,"x":1160,"y":700,"wires":[["2c5427b594cdc27d"],["96f668735a340977"]]},{"id":"96f668735a340977","type":"debug","z":"1fd29692524d1ecb","g":"9abaac9bbddc9bce","name":"debug 4","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":1400,"y":780,"wires":[]},{"id":"0be1a3a745d4345b","type":"slack-bolt-registry","z":"1fd29692524d1ecb","g":"9abaac9bbddc9bce","name":"Slack Registration","client":"","x":810,"y":700,"wires":[["b4ccc9f550d6192e"]]},{"id":"a8f863a194453f25","type":"function","z":"1fd29692524d1ecb","g":"9abaac9bbddc9bce","name":"Events","func":"\n\nmsg.SlackBolt.events.push(\n    {\n        'id': 'app_mention',\n        'callback':\n            async ({ event, context, client, say }) => {\n                try {\n                    const response = await say({\n                        blocks: [\n                            {\n                                type: 'section',\n                                text: {\n                                    type: 'mrkdwn',\n                                    text: `Thanks for the mention <@${event.user}>! Here's a button`,\n                                },\n                                accessory: {\n                                    type: 'button',\n                                    text: {\n                                        type: 'plain_text',\n                                        text: 'Approve me',\n                                        emoji: true,\n                                    },\n                                    value: 'button_click',\n                                    action_id: 'button_click',\n                                },\n                            },\n                        ],\n                    });\n                } catch (error) {\n                    console.error(error);\n                }\n            }\n    }\n);\n\n\n\nmsg.SlackBolt.actions.push(\n    {\n        'id': 'button_click',\n        'callback':\n            async ({ body, ack, say }) => {\n                // Acknowledge the action\n                await ack();\n                return await say(`<@${body.user.id}> clicked the button`);\n\n            }\n    }\n);\n\n\n\n\nreturn msg;","outputs":1,"timeout":0,"noerr":0,"initialize":"","finalize":"","libs":[],"x":610,"y":700,"wires":[["0be1a3a745d4345b"]]},{"id":"3701e2672d1605c0","type":"inject","z":"1fd29692524d1ecb","g":"9abaac9bbddc9bce","name":"Text via payload","props":[{"p":"payload"},{"p":"topic","vt":"str"},{"p":"xxxx","v":" test23","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"Hello World!12","payloadType":"str","x":340,"y":400,"wires":[["9326c16c34564ce9"]]},{"id":"ada60a61dc4363ca","type":"debug","z":"1fd29692524d1ecb","g":"9abaac9bbddc9bce","name":"debug 1","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":1160,"y":440,"wires":[]},{"id":"abd1fa9196265fd6","type":"inject","z":"1fd29692524d1ecb","g":"9abaac9bbddc9bce","name":"Block Message","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"blocks","payload":"[{\"type\":\"section\",\"text\":{\"type\":\"mrkdwn\",\"text\":\"Pick a date for me to remind you\"},\"accessory\":{\"type\":\"datepicker\",\"action_id\":\"datepicker_remind\",\"initial_date\":\"2019-04-28\",\"placeholder\":{\"type\":\"plain_text\",\"text\":\"Select a date\"}}}]","payloadType":"json","x":340,"y":500,"wires":[["9326c16c34564ce9"]]},{"id":"e1bae9dec89865d5","type":"inject","z":"1fd29692524d1ecb","g":"9abaac9bbddc9bce","name":"load via context","props":[{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","x":340,"y":300,"wires":[["222f70122d1d13d3"]]},{"id":"222f70122d1d13d3","type":"change","z":"1fd29692524d1ecb","g":"9abaac9bbddc9bce","name":"","rules":[{"t":"set","p":"slackFlowMessage","pt":"flow","to":"send a good flow message","tot":"str"},{"t":"set","p":"slackGlobalMessage","pt":"global","to":"send a good global message","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":680,"y":300,"wires":[["9326c16c34564ce9"]]},{"id":"85f483cbc0729943","type":"comment","z":"1fd29692524d1ecb","g":"9abaac9bbddc9bce","name":"flow.slackFlowMessage and global.slackGlobalMessage","info":"","x":830,"y":240,"wires":[]},{"id":"9326c16c34564ce9","type":"slack-bolt-message","z":"1fd29692524d1ecb","g":"9abaac9bbddc9bce","name":"","client":"","channel":"#main","blocks":"","property":"payload","propertyType":"msg","propertySendType":"text","text":"","attachments":"","x":840,"y":460,"wires":[["ada60a61dc4363ca"]]},{"id":"509fc660e5a7454f","type":"catch","z":"1fd29692524d1ecb","g":"9abaac9bbddc9bce","name":"","scope":"group","uncaught":false,"x":270,"y":840,"wires":[["b9b5a6a13cde4552"]]},{"id":"b9b5a6a13cde4552","type":"debug","z":"1fd29692524d1ecb","g":"9abaac9bbddc9bce","name":"Group Error - Slack Bolt","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":530,"y":840,"wires":[]}]

Flow Info

Created 5 months ago
Rating: not yet rated

Owner

Actions

Rate:

Node Types

Core
  • catch (x1)
  • change (x1)
  • comment (x1)
  • debug (x4)
  • function (x2)
  • inject (x4)
  • switch (x1)
Other

Tags

  • slack
  • slack-bolt
Copy this flow JSON to your clipboard and then import into Node-RED using the Import From > Clipboard (Ctrl-I) menu option