ZoomAsk

Sends a message (question) to either user (in a direct message) or to a channel. The message includes predefined reply options. The response can also close a task (might be conditional) in a playbook.

python · Zoom

Details

IDZoomAsk
Languagepython
From Version5.0.0
Docker Imagedemisto/fastapi:0.125.0.10158186
Tagszoom

README

Sends a message (question) to either a user (in a direct message) or to a channel. The message includes predefined reply options. The response can also close a task (might be conditional) in a playbook.

Script Data


Name Description
Script Type python3
Tags Zoom
Version 5.5.0

Use Case


This automation allows you to ask users in Zoom (including users who are external to Cortex XSOAR) questions, have them respond and
reflect the answer back to Cortex XSOAR.

Dependencies


Requires an instance of the Zoom integration with Long Running instance checked.

This script uses the following commands and scripts.
send-notification

Inputs


Argument Name Description
user The Zoom user to whom to send the message. Can be either an email address or a Zoom user_id.
channel_id The Zoom channel_id to which to send the message.
message The message to send to the user or channel.
option1 The first reply option. The default is “Yes” with a blue button. To change the color of the button, add the pound sign (#) followed by the name of the new color (blue, red, or black). The default color is “Blue”. For example, “Yes#blue”. Options cannot contain whitespaces.
option2 The second reply option. The default is “No” with a red button. To change the button color, add the pound sign (#) followed by the name of the new color (green, red, or black). The default color is “red”. For example, “No#red”. Options cannot contain whitespaces.
task The task to close with the reply. If empty, then no playbook tasks will be closed.
persistent Indicates whether to use one-time entitlement or persistent entitlement.
responseType How the user should respond to the question.
additionalOptions A comma-separated list of additional options in the format of “option#color”, for example, “maybe#red”. The default color is “black”. Options cannot contain whitespaces.
reply The reply to send to the user. Use the templates {user} and {response} to incorporate these in the reply. (i.e., “Thank you {user}. You have answered {response}.”)
lifetime Time until the question expires. For example - 1 day. When it expires, a default response is sent.
defaultResponse Default response in case the question expires.

Outputs


There are no outputs for this script.

Guide


The automation is most useful in a playbook to determine the outcome of a conditional task - which will be one of the provided options.
It uses a mechanism that allows external users to respond in Cortex XSOAR (per investigation) with entitlement strings embedded within the message contents.
ZoomAsk

The automation can utilize the interactive capabilities of Zoom to send a form with buttons.
This requires the external endpoint for interactive responses to be available for connection. (See the Zoom integration documentation).
You can also utilize a dropdown list instead, by specifying the responseType argument.

To use ZoomAsk via playbook:

  1. Add the ZoomAsk script to a playbook as a task.
  2. In the message argument, specify the message to be sent.
  3. Configure the response options by filling out the option1 and option2 arguments (default values are ‘Yes’ and ‘No’).
  4. Either a user or a channel_id or channel_name must be specified.
  5. In the ZoomAsk task, pass a tag value to the task argument.

All other inputs are optional.
At some point at the playbook, after running ZoomAsk, add a manual conditional task, which holds up the playbook execution until the response is received from Zoom.
The condition names must match the response options you passed in to ZoomAsk.
In order to tie the conditional task back to ZoomAsk, add the same tag from the fifth step to the conditional task (under the “Details” tab of the task). The conditional task will be marked as completed when a user responds to the ZoomAsk form.

Notes


  • ZoomAsk will not work when run in the playbook debugger. This is because the debugger does not generate entitlements, since they must be tied to an investigation. Entitlements are needed to track the response.
  • Whitespaces are not supported in custom options and will not work. (i.e. setting a button to I Agree)
import datetime

import dateparser
import demistomock as demisto
from CommonServerPython import entryTypes
from ZoomAsk import generate_json, main


def test_generate_json_button():
    text = "Test Text"
    options = ["Option1#blue", "Option2#red"]
    response_type = "button"
    result = generate_json(text, options, response_type)

    expected_result = {
        "head": {"type": "message", "text": text},
        "body": [
            {
                "type": "actions",
                "items": [
                    {"value": "Option1", "style": "Primary", "text": "Option1"},
                    {"value": "Option2", "style": "Danger", "text": "Option2"},
                ],
            }
        ],
    }

    assert result == expected_result


def test_generate_json_dropdown():
    text = "Test Text"
    options = ["Option1#blue", "Option2#red"]
    response_type = "dropdown"
    result = generate_json(text, options, response_type)

    expected_result = {
        "body": [
            {
                "select_items": [{"value": "Option1", "text": "Option1"}, {"value": "Option2", "text": "Option2"}],
                "text": text,
                "selected_item": {"value": "Option1"},
                "type": "select",
            }
        ]
    }

    assert result == expected_result


def execute_command(command, args):
    if command == "addEntitlement":
        return [{"Type": entryTypes["note"], "Contents": "4404dae8-2d45-46bd-85fa-64779c12abe8"}]

    return []


def test_main(mocker):
    mocker.patch.object(demisto, "executeCommand", side_effect=execute_command)
    mocker.patch.object(demisto, "investigation", return_value={"id": "22"})
    mocker.patch.object(
        demisto,
        "args",
        return_value={
            "persistent": "true",
            "option1": "Option1",
            "option2": "Option2",
            "additionalOptions": "",
            "reply": "Test Reply",
            "responseType": "button",
            "lifetime": "1 day",
            "defaultResponse": "Default Response",
            "user": "test@example.com",
            "message": "Test Message",
            "channel_name": None,
            "channel_id": None,
            "task": None,
        },
    )
    mocker.patch.object(demisto, "results")
    mocker.patch.object(dateparser, "parse", return_value=datetime.datetime(2019, 9, 26, 18, 38, 25))

    # Call the main function
    main()

    call_args = demisto.executeCommand.call_args[0]
    expected_args = {
        "ignoreAddURL": "true",
        "message": '{"blocks": "{\\"head\\": {\\"type\\": \\"message\\", \\"text\\": \\"Test Message\\"}, \\"body\\": [{\\"type\\": \\"actions\\", \\"items\\": [{\\"value\\": \\"Option1\\", \\"style\\": \\"Default\\", \\"text\\": \\"Option1\\"}, {\\"value\\": \\"Option2\\", \\"style\\": \\"Default\\", \\"text\\": \\"Option2\\"}]}]}", "entitlement": "4404dae8-2d45-46bd-85fa-64779c12abe8@22", "reply": "Test Reply", "expiry": "2019-09-26 18:38:25", "default_response": "Default Response"}',  # noqa: E501
        "to": "test@example.com",
        "zoom_ask": "true",
        "using-brand": "Zoom",
    }

    assert call_args[1] == expected_args