show_card
Show the customer a card with details and buttons 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) -> NoneShows a card under the bot's reply: a title, a few label and value rows, and up to three buttons. Use it from a custom action to present what the action found the way an app would, instead of leaving the bot to describe it in prose. For example, a subscription lookup can show the plan, price and next delivery date at a glance.
The card appears only in web chat with widget elements on (Chat behavior -> Show widget elements). Every other channel ignores it, so the same action works everywhere. The bot never sees the card, only what your action returns, so keep returning the facts it needs to answer.
Parameters
| Name | Type | Description |
|---|---|---|
context | dict | The context object passed to your action |
title | str | The card's heading (max 160 characters) |
fields | list | Up to 12 rows, each {"label": str, "value": str} |
subtitle | str or None | A line under the title |
image_url | str or None | An https image shown at the top of the card |
buttons | list | Up 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 subOnly 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.