Ai knowledge and logicHelpers

ask_confirmation

Ask the customer to confirm with two buttons before the bot acts.

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 under the bot's reply with two buttons. The button the customer taps is sent as their reply (the button's label, or confirm_message / cancel_message), so the bot reads the answer on its next turn like any other message.

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 is only drawn by the new web chat widget ("New chat experience"). On other channels the bot asks in text. The bot also has a built-in askForConfirmation tool on the new widget, 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