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) -> NoneShows 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
| Name | Type | Description |
|---|---|---|
context | dict | The context object passed to your action |
title | str | What will happen, e.g. "Cancel order #1042?" |
confirm_label | str | Confirm button text, e.g. "Yes, cancel it" |
cancel_label | str | Cancel button text, e.g. "No, keep it" |
description | str or None | Details or consequences, e.g. the refund amount |
destructive | bool | Draw the confirm button in red when it can't be undone |
confirm_message | str or None | Sent as the customer's reply instead of confirm_label |
cancel_message | str or None | Sent 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.