Python helpers

add_conversation_tag

Tag the current conversation from Python, so it shows up in the right views, filters and reports.

add_conversation_tag(context: dict, tag: str) -> dict

Adds a tag to the conversation, and creates the tag if your organization doesn't have it yet. Tags drive views, filters and reports, so tagging from code lets you measure what your automations do. For example, a refund action can tag every conversation where it issued a refund.


Parameters

NameTypeDescription
contextdictThe context object passed to your action
tagstrThe tag text to add (max 100 characters)

Returns

dict: {"success": bool, "message": str, "tagId": str}

Behavior

  • If the tag name doesn't exist yet, it is created automatically for your organization.
  • If the tag is already on the conversation, the operation succeeds without changes.
  • Does not fire the tag_modified event, so a handler that tags on tag_modified cannot re-trigger itself.
  • Skipped in test/mock environments.

Examples

Tag after a refund

def execute_action(context):
    # ... process refund ...
    add_conversation_tag(context, "refunded")
    return {"success": True}

Tag based on order value

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

    if total > 500:
        add_conversation_tag(context, "high-value-order")

    return order

Tag for routing analytics

def execute_action(context):
    add_conversation_tag(context, "cancel-requested")
    add_conversation_tag(context, f"cancel-reason:{context['args']['reason']}")
    # ... handle cancellation ...

On this page