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) -> NoneShows 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
| 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.