def default_notification()

in src/dispatch/plugins/dispatch_slack/messaging.py [0:0]


def default_notification(items: list):
    """Creates blocks for a default notification."""
    blocks = [Divider()]
    for item in items:
        if isinstance(item, list):  # handle case where we are passing multiple grouped items
            blocks += default_notification(item)

        if item.get("title_link") == "None":  # avoid adding blocks with no data
            continue

        if item.get("type"):
            if item["type"] == "context":
                blocks.append(Context(elements=[MarkdownText(text=format_default_text(item))]))
            else:
                blocks.append(Section(text=format_default_text(item)))
        else:
            blocks.append(Section(text=format_default_text(item)))

        if item.get("buttons"):
            elements = []
            for button in item["buttons"]:
                if button.get("button_text") and button.get("button_value"):
                    if button.get("button_url"):
                        element = Button(
                            action_id=button["button_action"],
                            text=button["button_text"],
                            value=button["button_value"],
                            url=button["button_url"],
                        )
                    else:
                        element = Button(
                            action_id=button["button_action"],
                            text=button["button_text"],
                            value=button["button_value"],
                        )

                    elements.append(element)
            blocks.append(Actions(elements=elements))

        if select := item.get("select"):
            options = []
            for option in select["options"]:
                element = PlainOption(text=option["option_text"], value=option["option_value"])
                options.append(element)

            static_select = []
            if select.get("placeholder"):
                static_select.append(
                    StaticSelect(
                        placeholder=select["placeholder"],
                        options=options,
                        action_id=select["select_action"],
                    )
                )
            else:
                static_select.append(
                    StaticSelect(options=options, action_id=select["select_action"])
                )
            blocks.append(Actions(elements=static_select))

    return blocks