Python helpers

set_conversation_metadata

Store a value on the current conversation so later actions, conditions and handlers can read it.

set_conversation_metadata(context: dict, key: str, value: str) -> dict

Stores a key-value pair on the conversation, and updates the value if the key already exists. Metadata is how your automations remember facts about a conversation. For example, an action can save the customer's verified account ID, so every later action uses it without asking again.


Parameters

NameTypeDescription
contextdictThe context object passed to your action
keystrThe metadata key (max 200 characters)
valuestrThe value to store (max 50,000 characters)

Returns

dict: {"success": bool, "message": str, "key": str, "value": str}

Limits

  • Maximum key length: 200 characters
  • Maximum value length: 50,000 characters
  • Maximum 200 key-value pairs per conversation

Behavior

  • If the key already exists, its value is overwritten.
  • In test/mock environments, returns a mock success response without persisting.

Key naming

Keys Octocom writes use a <source>:<camelCase> prefix, such as zendesk:ticketId or chat-widget:country. Use plain keys for your own data, such as refund_amount, so they never collide with a key Octocom writes. You can still overwrite a system key on purpose.

Search and secret keys

Agents can find a conversation by any metadata value from the Help Desk search box (values of 3 to 1,000 characters). Store IDs agents look up, such as a user ID or a ticket ID, as metadata.

If the key name contains secret, token, session, password, jwt, api_key, cookie, credential, bearer or authorization (any case), the value is a secret: it is not searchable, the dashboard sidebar shows it as hidden, macros render it empty, and MCP conversation reads return it as null. get_conversation_metadata, the REST API and custom report SQL still return it. Put secret in the key name, for example secret_loyalty_pin, to hide any other value.

Special keys

Some metadata keys have a platform meaning:

KeyEffect
email:botFooterOverrideReplaces the email configuration's bot footer for all bot-sent emails in this conversation (all email-based channels, including help desk integrations). Raw HTML is supported, so this can inject styled banners or signatures. Set an empty string to suppress the default footer entirely. Agent-sent emails are unaffected.
octocom:orderIdThe external order reference the conversation is about. Octocom sets it from a contact form orderId, and order lookups should set it once they identify the order. Order exports and macros read it.

Examples

Track a refund amount for analytics

def execute_action(context):
    # ... process refund ...
    set_conversation_metadata(context, "refund_amount", "49.99")
    set_conversation_metadata(context, "refund_reason", "damaged_product")
    return {"success": True, "amount": 49.99}
def execute_action(context):
    order = fetch_order(context["args"]["orderId"])

    # Show a promo banner only to eligible customers
    if order["type"] == "one_time" and order["payment_method"] != "klarna":
        banner = '<a href="https://example.com/offer" style="display:block;padding:16px;background:#e9f8ee;border-radius:12px;">Get 70% off your next order</a>'
        set_conversation_metadata(context, "email:botFooterOverride", banner)

    return {"success": True}

Store a computed value for later use

def execute_action(context):
    order = fetch_order(context["args"]["orderId"])
    risk_score = calculate_risk(order)

    set_conversation_metadata(context, "risk_score", str(risk_score))

    return {"riskScore": risk_score, "order": order}

On this page