Ai knowledge and logicHelpers

show_card

Show the customer a card under the bot's reply in web chat.

show_card(context: dict, title: str, fields: list = None, subtitle: str = None, image_url: str = None, buttons: list = None) -> None

Shows a card under the bot's reply: a title, a few label/value rows and up to three buttons. Use it from a custom action to present what the action found — a subscription, a booking, a loyalty balance — the way an app would, instead of leaving the bot to describe it in prose.

The card is only drawn by the new web chat widget ("New chat experience" in the web chat deployment settings). Other channels and the classic widget ignore it. The bot never sees the card, only what your action returns, so keep returning the facts it needs to answer.


Parameters

NameTypeDescription
contextdictThe context object passed to your action
titlestrThe card's heading (max 160 characters)
fieldslistUp to 12 rows, each {"label": str, "value": str}
subtitlestr or NoneA line under the title
image_urlstr or NoneAn https image shown at the top of the card
buttonslistUp to 3. {"label": str, "url": str} opens a link; {"label": str, "message": str} sends message as the customer's reply when tapped

Example

def execute_action(context):
    sub = fetch_subscription(context["customer"]["email"])

    show_card(
        context,
        title=sub["plan_name"],
        subtitle="Active subscription",
        fields=[
            {"label": "Next delivery", "value": sub["next_date"]},
            {"label": "Price", "value": f"{sub['price']} {sub['currency']}"},
        ],
        buttons=[
            {"label": "Manage", "url": sub["portal_url"]},
            {"label": "Skip next", "message": "Skip my next delivery"},
        ],
    )
    return sub

Only callable from bot actions. A card that doesn't fit the limits above is dropped rather than failing the action.

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