Example #1
0
def main(rqst: AnyRequest):

    # define the event trigger ID that will be used to associate the dialog
    # submit button with the callback handler on the event to process the
    # User's inputs.

    event_id = cmd.prog + ".dialog"

    rqst.app.ic.dialog.on(event_id, on_dialog_submit)

    # create the dialog wiedget using slackclient

    builder = (dialogs.DialogBuilder().title("My Cool Dialog").callback_id(
        event_id).state({
            'value': 123,
            'key': "something"
        }).text_area(name="message",
                     label="Message",
                     hint="Enter a message",
                     max_length=500).text_field(name="signature",
                                                label="Signature",
                                                optional=True,
                                                max_length=50))

    # send the dialog to the User for processsing, the `dialog_open` is a
    # method of the slackclient instance

    resp = Response(rqst)
    res = resp.client.dialog_open(dialog=builder.to_dict(),
                                  trigger_id=rqst.trigger_id)

    if not res.get('ok'):
        rqst.app.log.error(json.dumps(res))
Example #2
0
def make_dialog_for_ack(SLACK_TRIGGER_ID, ALERT_ID, SLACK_USER, ALERT_TEXT):

    ack_options = [{
        "label": "Ack for 5 mins",
        "value": "ack|300"
    }, {
        "label": "Ack for 15 mins",
        "value": "ack|900"
    }, {
        "label": "Ack for 30 mins",
        "value": "ack|1800"
    }, {
        "label": "Ack for 1 hour",
        "value": "ack|3600"
    }, {
        "label": "Ack for 2 hours",
        "value": "ack|7200"
    }, {
        "label": "Ack for 4 hours",
        "value": "ack|14400"
    }, {
        "label": "Ack for 8 hours",
        "value": "ack|28800"
    }, {
        "label": "Ack for 1 day",
        "value": "ack|86400"
    }, {
        "label": "Ack for 1 week",
        "value": "ack|604800"
    }, {
        "label": "Close alert",
        "value": "close|604800"
    }]

    builder = (dialogs.DialogBuilder().title("Ack or close the alert").state({
        'alert_id':
        ALERT_ID,
        'type':
        'ack',
        'alert_text':
        ALERT_TEXT
    }).callback_id(f"{ALERT_ID}|ack").static_selector(
        name="action",
        label="What to do?",
        placeholder="Choose an option",
        options=ack_options).text_area(name="note",
                                       label="Note",
                                       hint="Write comment to the acked alert",
                                       max_length=500))

    slack_client.dialog_open(dialog=builder.to_dict(),
                             trigger_id=SLACK_TRIGGER_ID)

    return make_response("", 200)
Example #3
0
def build_update_dialog(whatis: Whatis) -> dialogs.DialogBuilder:
    d = (
        dialogs.DialogBuilder()
        .submit_label("Add")
        .notify_on_cancel(False)
        .callback_id(constants.UPDATE_WHATIS_ID)
        .title("Update Whatis")
        .state({"id": whatis.id})
        .text_field(
            label="Terminology",
            name=TERMINOLOGY_KEY,
            optional=False,
            hint="what are you defining",
            min_length=2,
            value=whatis.terminology,
        )
        .text_field(
            label="Definition",
            name=DEFINITION_KEY,
            optional=False,
            hint="What does it mean",
            min_length=8,
            value=whatis.definition,
        )
        .text_area(
            label="Notes",
            name=NOTES_KEY,
            optional=True,
            hint="Other notes",
            min_length=8,
            value=whatis.notes,
        )
        .text_area(
            label="Relevant Links",
            name=LINKS_KEY,
            optional=True,
            hint="Comma separated links to documentation",
            min_length=8,
            value=whatis.links,
        )
        .conversation_selector(
            label="Point of Contact",
            name=POINT_OF_CONTACT_KEY,
            optional=True,
            value=whatis.point_of_contact,
            placeholder=whatis.added_by,
        )
    )
    return d
Example #4
0
def build_create_new_dialog(
    state: typing.Union[dict, str] = ""
) -> dialogs.DialogBuilder:
    d = (
        dialogs.DialogBuilder()
        .submit_label("Add")
        .notify_on_cancel(False)
        .callback_id(constants.CREATE_NEW_WHATIS_ID)
        .title("Create a new Whatis")
        .state(state)
        .text_field(
            label="Terminology",
            name=TERMINOLOGY_KEY,
            optional=False,
            hint="what are you defining",
            min_length=2,
        )
        .text_field(
            label="Definition",
            name=DEFINITION_KEY,
            optional=False,
            hint="What does it mean",
            min_length=8,
        )
        .text_area(
            label="Notes",
            name=NOTES_KEY,
            optional=True,
            hint="Other notes",
            placeholder="Is there anything else you think your teammates should know about this terminology?",
            min_length=8,
        )
        .text_area(
            label="Relevant Links",
            name=LINKS_KEY,
            optional=True,
            hint="Comma separated links to documentation",
            placeholder="Did you know that you can create hyperlinks by <www.thingtolinkto.com | "
            "writing it like this>! Useful for long links",
            min_length=8,
        )
        .conversation_selector(
            label="Point of Contact",
            name=POINT_OF_CONTACT_KEY,
            optional=True,
            placeholder="Where is the best place to ask about this",
        )
    )
    return d
Example #5
0
def make_dialog_for_comment(SLACK_TRIGGER_ID, ALERT_ID, SLACK_USER,
                            ALERT_TEXT):

    builder = (dialogs.DialogBuilder().title("Add a note to the alert").state({
        'alert_id':
        ALERT_ID,
        'type':
        'comment',
        'alert_text':
        ALERT_TEXT
    }).callback_id(f"{ALERT_ID}|comment").text_area(
        name="note",
        label="Note",
        hint="Write something useful",
        max_length=500))

    slack_client.dialog_open(dialog=builder.to_dict(),
                             trigger_id=SLACK_TRIGGER_ID)

    return make_response("", 200)
    def nyc_report():
        # options for when the report runs.
        report_grain = [{
            "label": "Week",
            "value": "WEEK"
        }, {
            "label": "Month",
            "value": "MONTH"
        }, {
            "label": "Quarter",
            "value": "QUARTER"
        }, {
            "label": "Year",
            "value": "YEAR"
        }]

        builder = (dialogs.DialogBuilder().title(
            "NYC Taxi Report").callback_id("NycTaxiReport").static_selector(
                name="report", label="Select a report", options=report_grain))

        trigger_id = request.form.get('trigger_id')
        client.dialog_open(dialog=builder.to_dict(), trigger_id=trigger_id)

        return make_response("", 200)