Python helpers

ask_confirmation

Ask the customer to confirm with two buttons in web chat before your action changes anything.

ask_confirmation(context: dict, title: str, confirm_label: str, cancel_label: str, description: str = None, destructive: bool = False, confirm_message: str = None, cancel_message: str = None) -> None

Shows a confirmation such as "Cancel order #1042?" under the bot's reply, with two buttons: Yes, cancel it and No, keep it. The button the customer taps is sent as their reply, so the bot reads the answer on its next turn like any other message. That reply is the button's label, or confirm_message or cancel_message when you set them.

Showing it changes nothing by itself. The usual setup is two actions: one that looks things up and asks, and one that makes the change once the customer has confirmed.

The confirmation appears only in web chat with widget elements on (Chat behavior -> Show widget elements). Elsewhere the bot asks in text. When widget elements are on, the bot also has a built-in askForConfirmation tool, so you only need this helper when your own action decides what to ask.


Parameters

NameTypeDescription
contextdictThe context object passed to your action
titlestrWhat will happen, e.g. "Cancel order #1042?"
confirm_labelstrConfirm button text, e.g. "Yes, cancel it"
cancel_labelstrCancel button text, e.g. "No, keep it"
descriptionstr or NoneDetails or consequences, e.g. the refund amount
destructiveboolDraw the confirm button in red when it can't be undone
confirm_messagestr or NoneSent as the customer's reply instead of confirm_label
cancel_messagestr or NoneSent as the customer's reply instead of cancel_label

Example

def execute_action(context):
    order = fetch_order(context["args"]["orderId"])

    ask_confirmation(
        context,
        title=f"Cancel order {order['name']}?",
        description=f"You'll be refunded {order['total']} within 5 business days.",
        confirm_label="Yes, cancel it",
        cancel_label="No, keep it",
        destructive=True,
    )
    return {"order": order, "awaitingConfirmation": True}

Only callable from bot actions.

The helper adds the same item as returning it under octocom_ui. See Chat UI from actions for every field and limit.

On this page