Send Messages | Send Interactivity Examples
LAST UPDATED: NOV 19, 2024
PRECONDITIONS
A Slack application has been configured to establish a connection with D3 vSOC. See Configuring Slack to Work with D3 SOAR and Configuring D3 SOAR to Work with Slack.
The Slack application has been added to Slack channels. See Application Integration.
Interactivity has been enabled. See Enabling Interactivity.
Send Messages
ALERT
Starting November 2024, D3 recommends using the Send Interactivity command, which automatically manages action_id. This automation addresses known API limitations, identifies finalized user actions, and notifies users on Slack when the D3 playbook task will no longer process subsequent submissions of the same interactive message. The Send Interactivity command eliminates the requirement for clients to understand and manually insert the <<D3_Identifier>>
placeholder value for the Message Blocks input parameter, thereby reducing human errors and downstream complications.
Set up the Send Messages command to send a message with checkbox and radio button elements. See step 4 of Application Integration for instructions on obtaining Channel IDs and User IDs. For this example, the Channel ID for a channel called demo is used.
The below Jinja template is used to dynamically select the appropriate JSON block for Slack based on the specified conditions.
{{ PlaybookData | jsonpath('$.["Multiple Choice JSON"].inputData.Template')
or PlaybookData | jsonpath('$.["Approve/Decline JSON"].inputData.Template')
or PlaybookData | jsonpath('$.["Text Input Box JSON"].inputData.Template') }}
{#
{% set choice = PlaybookData | jsonpath('$.["Determine Selected Slack Message Type"].outputData.Choice')%}
{% if "Multiple Choice" in choice %}
{{ PlaybookData | jsonpath('$.["Multiple Choice JSON"].inputData')}}
{% elif "Approve/Decline" in choice %}
{{ PlaybookData | jsonpath('$.["Approve/Decline JSON"].inputData')}}
{% elif "Text Input Box" in choice %}
{{ PlaybookData | jsonpath('$.["Text Input Box JSON"].inputData')}}
{% endif %}
#}
For this example, the focus will be on the JSON block for Multiple Choice JSON. The complete code for Multiple Choice JSON is as follows:
[
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": "*Your task response requires you to complete the below form and submit your choices.*"
}
},
{
"type": "divider"
},
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": "Choose one or more actions to submit:"
}
},
{
"type": "actions",
"elements": [
{
"type": "checkboxes",
"options": [
{
"text": {
"type": "mrkdwn",
"text": "*Activity Confirmed*"
},
"description": {
"type": "mrkdwn",
"text": "*Add your detailed description here for this option*"
},
"value": "value-0"
},
{
"text": {
"type": "mrkdwn",
"text": "*Add User to Watchlist*"
},
"description": {
"type": "mrkdwn",
"text": "*this is mrkdwn text*"
},
"value": "value-1"
},
{
"text": {
"type": "mrkdwn",
"text": "*Block IP Address on Firewall*"
},
"description": {
"type": "mrkdwn",
"text": "*this is mrkdwn text*"
},
"value": "value-2"
},
{
"text": {
"type": "mrkdwn",
"text": "*Lock The User's Account*"
},
"description": {
"type": "mrkdwn",
"text": "*this is mrkdwn text*"
},
"value": "value-3"
}
]
}
]
},
{
"type": "divider"
},
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": "Pick one action to submit:"
}
},
{
"type": "actions",
"elements": [
{
"type": "radio_buttons",
"options": [
{
"text": {
"type": "plain_text",
"text": "Activity Confirmed",
"emoji": true
},
"value": "value-0"
},
{
"text": {
"type": "plain_text",
"text": "Add User to Watchlist",
"emoji": true
},
"value": "value-1"
},
{
"text": {
"type": "plain_text",
"text": "Block IP Address on Firewall",
"emoji": true
},
"value": "value-2"
},
{
"text": {
"type": "plain_text",
"text": "Lock The User's Account",
"emoji": true
},
"value": "value-3"
}
]
}
]
},
{
"type": "divider"
},
{
"type": "actions",
"elements": [
{
"type": "button",
"text": {
"type": "plain_text",
"text": "Submit Your Response",
"emoji": true
},
"value": "sample",
"action_id": "<<D3_IDentifier>>"
}
]
}
]
Test run the playbook. The Send Messages command will appear in a paused state.
Observe the message in the channel.
Breakdown of the Message
a.
JSON{ "type": "section", "text": { "type": "mrkdwn", "text": "*Your task response requires you to complete the below form and submit your choices.*" } }
b.
JSON{ "type": "divider" }
c.
JSON{ "type": "section", "text": { "type": "mrkdwn", "text": "Choose one or more actions to submit:" } }
d.
JSON{ "type": "actions", "elements": [ { "type": "checkboxes", "options": [ { "text": { "type": "mrkdwn", "text": "*Activity Confirmed*" }, "description": { "type": "mrkdwn", "text": "*Add your detailed description here for this option*" }, "value": "value-0" }, { "text": { "type": "mrkdwn", "text": "*Add User to Watchlist*" }, "description": { "type": "mrkdwn", "text": "*this is mrkdwn text*" }, "value": "value-1" }, { "text": { "type": "mrkdwn", "text": "*Block IP Address on Firewall*" }, "description": { "type": "mrkdwn", "text": "*this is mrkdwn text*" }, "value": "value-2" }, { "text": { "type": "mrkdwn", "text": "*Lock The User's Account*" }, "description": { "type": "mrkdwn", "text": "*this is mrkdwn text*" }, "value": "value-3" } ] } ] }
e.
JSON{ "type": "divider" }
f.
JSON{ "type": "section", "text": { "type": "mrkdwn", "text": "Pick one action to submit:" } }
g.
JSON{ "type": "actions", "elements": [ { "type": "radio_buttons", "options": [ { "text": { "type": "plain_text", "text": "Activity Confirmed", "emoji": true }, "value": "value-0" }, { "text": { "type": "plain_text", "text": "Add User to Watchlist", "emoji": true }, "value": "value-1" }, { "text": { "type": "plain_text", "text": "Block IP Address on Firewall", "emoji": true }, "value": "value-2" }, { "text": { "type": "plain_text", "text": "Lock The User's Account", "emoji": true }, "value": "value-3" } ] } ] }
h.
JSON{ "type": "divider" }
i.
JSON{ "type": "actions", "elements": [ { "type": "button", "text": { "type": "plain_text", "text": "Submit Your Response", "emoji": true }, "value": "sample", "action_id": "<<D3_IDentifier>>" } ] }
Select checkbox options and one radio button option. For this example, choose the first and forth checkbox options, Activity Confirmed and Lock The User's Account respectively, and the second radio button option, Add User to Watchlist.
Click on the Submit Your Response button.
Click on the icon of the Send Messages playbook task.
Navigate to the Context Data tab and scroll down to the "state" field. This field contains the submitted responses from the Slack interactive components.
Observe the selected options. The Activity Confirmed and Lock The User’s Account checkbox options will be displayed.
The Add User to Watchlist radio option will also be displayed.
READER NOTE
The specific action ID value is derived from the <<D3_IDentifier>>
placeholder within the block code of the submit button. D3 is phasing out the use of this placeholder to prevent significant downstream complications. D3 recommends using the Send Interactivity command.
Send Interactivity
Set up the Send Interactivity command to send a message with checkbox and radio button elements. See step 4 of Application Integration for instructions on obtaining Channel IDs and User IDs. For this example, the Channel ID for a channel named "demo" is used.
The below Jinja template is used to dynamically select the appropriate JSON block for Slack based on the specified conditions.
{{ PlaybookData | jsonpath('$.["Multiple Choice JSON"].inputData.Template')
or PlaybookData | jsonpath('$.["Approve/Decline JSON"].inputData.Template')
or PlaybookData | jsonpath('$.["Text Input Box JSON"].inputData.Template') }}
{#
{% set choice = PlaybookData | jsonpath('$.["Determine Selected Slack Message Type"].outputData.Choice')%}
{% if "Multiple Choice" in choice %}
{{ PlaybookData | jsonpath('$.["Multiple Choice JSON"].inputData')}}
{% elif "Approve/Decline" in choice %}
{{ PlaybookData | jsonpath('$.["Approve/Decline JSON"].inputData')}}
{% elif "Text Input Box" in choice %}
{{ PlaybookData | jsonpath('$.["Text Input Box JSON"].inputData')}}
{% endif %}
#}
For this example, the focus will be on the JSON block within the Multiple Choice JSON formatter. Its content is as follows:
[
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": "*Your task response requires you to complete the below form and submit your choices.*"
}
},
{
"type": "divider"
},
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": "Choose one or more actions to submit:"
}
},
{
"type": "actions",
"elements": [
{
"type": "checkboxes",
"options": [
{
"text": {
"type": "mrkdwn",
"text": "*Activity Confirmed*"
},
"description": {
"type": "mrkdwn",
"text": "*Add your detailed description here for this option*"
},
"value": "value-0"
},
{
"text": {
"type": "mrkdwn",
"text": "*Add User to Watchlist*"
},
"description": {
"type": "mrkdwn",
"text": "*this is mrkdwn text*"
},
"value": "value-1"
},
{
"text": {
"type": "mrkdwn",
"text": "*Block IP Address on Firewall*"
},
"description": {
"type": "mrkdwn",
"text": "*this is mrkdwn text*"
},
"value": "value-2"
},
{
"text": {
"type": "mrkdwn",
"text": "*Lock The User's Account*"
},
"description": {
"type": "mrkdwn",
"text": "*this is mrkdwn text*"
},
"value": "value-3"
}
]
}
]
},
{
"type": "divider"
},
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": "Pick one action to submit:"
}
},
{
"type": "actions",
"elements": [
{
"type": "radio_buttons",
"options": [
{
"text": {
"type": "plain_text",
"text": "Activity Confirmed",
"emoji": true
},
"value": "value-0"
},
{
"text": {
"type": "plain_text",
"text": "Add User to Watchlist",
"emoji": true
},
"value": "value-1"
},
{
"text": {
"type": "plain_text",
"text": "Block IP Address on Firewall",
"emoji": true
},
"value": "value-2"
},
{
"text": {
"type": "plain_text",
"text": "Lock The User's Account",
"emoji": true
},
"value": "value-3"
}
]
}
]
}
]
Test run the playbook. The Send Messages command will appear in a paused state.
Navigate to the Slack channel.
Observe the message in the channel.
Breakdown of the Messagea.
JSON{ "type": "section", "text": { "type": "mrkdwn", "text": "*Your task response requires you to complete the below form and submit your choices.*" } }
b.
JSON{ "type": "divider" }
c.
JSON{ "type": "section", "text": { "type": "mrkdwn", "text": "Choose one or more actions to submit:" } }
d.
JSON{ "type": "actions", "elements": [ { "type": "checkboxes", "options": [ { "text": { "type": "mrkdwn", "text": "*Activity Confirmed*" }, "description": { "type": "mrkdwn", "text": "*Add your detailed description here for this option*" }, "value": "value-0" }, { "text": { "type": "mrkdwn", "text": "*Add User to Watchlist*" }, "description": { "type": "mrkdwn", "text": "*this is mrkdwn text*" }, "value": "value-1" }, { "text": { "type": "mrkdwn", "text": "*Block IP Address on Firewall*" }, "description": { "type": "mrkdwn", "text": "*this is mrkdwn text*" }, "value": "value-2" }, { "text": { "type": "mrkdwn", "text": "*Lock The User's Account*" }, "description": { "type": "mrkdwn", "text": "*this is mrkdwn text*" }, "value": "value-3" } ] } ] }
e.
JSON{ "type": "divider" }
f.
JSON{ "type": "section", "text": { "type": "mrkdwn", "text": "Pick one action to submit:" } }
g.
JSON{ "type": "actions", "elements": [ { "type": "radio_buttons", "options": [ { "text": { "type": "plain_text", "text": "Activity Confirmed", "emoji": true }, "value": "value-0" }, { "text": { "type": "plain_text", "text": "Add User to Watchlist", "emoji": true }, "value": "value-1" }, { "text": { "type": "plain_text", "text": "Block IP Address on Firewall", "emoji": true }, "value": "value-2" }, { "text": { "type": "plain_text", "text": "Lock The User's Account", "emoji": true }, "value": "value-3" } ] } ] }
h. This section is automatically generated.
Select checkbox options and one radio button option. For this example, choose the second and third checkbox options, Add User to Watchlist and Block IP Address on Firewall respectively, and the forth radio button option, Lock The User’s Account.
Click on the Submit Your Response button, then click on the Submit button in the popup.
A message will be displayed indicating the user who submitted the form, the submission time in UTC, and a notice that no further submissions for this message will be processed by D3's playbook task.
Click on the icon of the Send Interactivity playbook task.
Navigate to the Context Data tab and scroll down to the "state" field. This field contains the submitted responses from the Slack interactive components.
Observe the selected options. The Add User to Watchlist and Block IP Address on Firewall checkbox options will be displayed.
The Lock The User’s Account radio option will also be displayed.
Set up the Send Interactivity command to send a message with checkbox and radio button elements. See step 4 of Application Integration for instructions on obtaining Channel IDs and User IDs. For this example, the Channel ID for a channel named "demo" is used.
For this example, the focus will be on the JSON block within the Text Input Box JSON formatter. Its content is as follows:
JSON[ { "type": "input", "element": { "type": "plain_text_input", "multiline": true }, "label": { "type": "plain_text", "text": "Your comment", "emoji": true } } ]
Test run the playbook. The Send Interactivity command will appear in a paused state.
Navigate to the Slack channel.
Enter a message in the text area.
Click on the Submit Your Response button, then click on the Submit button in the popup.
A message will be displayed indicating the user who submitted the form, the submission time in UTC, and a notice that no further submissions for this message will be processed by D3's playbook task.
Click on the icon of the Send Interactivity playbook task.
Navigate to the Context Data tab and scroll down to the "state" field. This field contains the submitted responses from the Slack interactive components.
Set up the Send Interactivity command to send a message with checkbox and radio button elements. See step 4 of Application Integration for instructions on obtaining Channel IDs and User IDs. For this example, a User ID is used.
For this example, the focus will be on a single Send Interactivity task. Its content is as follows:
JSON[ { "type": "actions", "elements": [ { "type": "datepicker", "initial_date": "2024-11-15", "placeholder": { "type": "plain_text", "text": "Select a date", "emoji": true } }, { "type": "timepicker", "initial_time": "13:37", "placeholder": { "type": "plain_text", "text": "Select time", "emoji": true } } ] } ]
Instruct the user to navigate to the direct Slack message under the Apps accordion.
Select a date and time, then click on the Submit your response button.
A message will be displayed indicating the user who submitted the form, the submission time in UTC, and a notice that no further submissions for this message will be processed by D3's playbook task.
Click on the icon of the Send Interactivity playbook task.
Navigate to the Context Data tab and scroll down to the "state" field. This field contains the submitted responses from the Slack interactive components.
Set up the Send Interactivity command to send a message with checkbox and radio button elements. See step 4 of Application Integration for instructions on obtaining Channel IDs and User IDs. For this example, a User ID is used.
For this example, the focus will be on a single Send Interactivity task. The input for its Message Blocks parameter is as follows:
JSON{ "type": "section", "text": { "type": "mrkdwn", "text": "Select a user:" }, "accessory": { "type": "users_select", "placeholder": { "type": "plain_text", "text": "Select a user", "emoji": true } } }
Instruct the user to navigate to the direct Slack message under the Apps accordion.
Select a user (Slackbot for this example), then click on the Submit your response button.
A message will be displayed indicating the user who submitted the form, the submission time in UTC, and a notice that no further submissions for this message will be processed by D3's playbook task.
Click on the icon of the Send Interactivity playbook task.
Navigate to the Context Data tab and scroll down to the "state" field. This field contains the submitted responses from the Slack. The Slackbot user (USLACKBOT) will be recorded.