set_data_collection_result
Record a fact about the conversation, such as a cancellation reason, so you can measure it.
set_data_collection_result(context: dict, key: str, value: str) -> dictStores a collected data result on the conversation, in the same store the AI data collection feature writes to. For example, a cancellation action can record the customer's reason, so you can compare reasons across conversations. Results appear in the conversation sidebar, in the Custom data tab of Metrics, and in the Collected data view filter. If the key already exists, its value is replaced.
Use this for facts you want to measure across conversations, such as outcomes, reasons and feedback categories. For values your own flows read back later, use set_conversation_metadata instead.
Parameters
| Name | Type | Description |
|---|---|---|
context | dict | The context object passed to your action or event handler |
key | str | The result key (max 200 characters), e.g. "cancel_reason" |
value | str | The value to store (max 2,000 characters), e.g. "price" |
Returns
dict: {"success": bool, "message": str, "key": str, "value": str}
Limits
- Maximum key length: 200 characters
- Maximum value length: 2,000 characters
- Maximum 50 keys per conversation
Behavior
- One value per key: writing an existing key replaces its value.
- Values are strings; store booleans as
"true"/"false". - On phone campaign calls, the
successkey ("true"/"false") drives the campaign's success-rate KPI. - Results sync to your connected help desk (Zendesk or Help Scout) as
octocom:key:valuetags, same as AI-collected results. - In test/mock environments, returns a mock success response without persisting.
Examples
Record a campaign call outcome from an event handler
def handle_event(context):
# ... inspect context["conversation"]["messages"] ...
set_data_collection_result(context, "success", "true")
set_data_collection_result(context, "cancel_reason", "price")
return {"recorded": True}Record structured feedback from a mid-call action
def execute_action(context):
feedback = context["args"]["feedback_category"]
set_data_collection_result(context, "product_feedback", feedback)
return {"success": True}