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) -> dictAdds 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
| Name | Type | Description |
|---|---|---|
context | dict | The context object passed to your action |
tag | str | The 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_modifiedevent, so a handler that tags ontag_modifiedcannot 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 orderTag 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 ...