Ai knowledge and logicHelpers

get_conversation_metadata

Read a metadata value from the current conversation.

get_conversation_metadata(context: dict, key: str) -> str | None

Retrieves a metadata value previously stored on the conversation. Returns None if the key doesn't exist.


Parameters

NameTypeDescription
contextdictThe context object passed to your action
keystrThe metadata key to retrieve

Returns

str | None — The stored value, or None if the key is not found.

Behavior


Examples

Read a user ID from chat custom data

def execute_action(context):
    user_id = get_conversation_metadata(context, "chat-widget:user_id")
    if not user_id:
        return {"error": "No user ID found. The customer may not be logged in."}

    response = requests.get(
        "https://api.example.com/users",
        params={"id": user_id},
        headers={"Authorization": "Bearer API_KEY"},
        timeout=30,
    )
    response.raise_for_status()
    return response.json()

Check if a previous action already ran

def execute_action(context):
    already_refunded = get_conversation_metadata(context, "refund_processed")
    if already_refunded:
        return {"error": "A refund has already been processed in this conversation."}

    # ... process refund ...
    set_conversation_metadata(context, "refund_processed", "true")
    return {"success": True}

On this page