# Send a call report to a webhook

import { CodePreview } from "../../src/CodePreview";

Build an automation that judges each completed conversation of one Assistant and posts the report to your endpoint. You create a Process with two steps, a Trigger on `exchange.completed`, and then read the Run that a conversation produces.

## Prerequisites

- A project-scoped [API key](/docs/authentication).
- The ID of an Assistant in that Project. The [Quickstart](/docs/quickstart) creates one.
- An HTTPS endpoint that accepts `POST` requests with a JSON body. For a first test, a request inspection service works. The endpoint must have a public address: a Process cannot reach private or internal addresses.

## Step 1: Create the Process

The Process has two steps:

1. An [Agent step](/docs/agent) reads the transcript and returns a structured report. Its `output` name, `report`, makes the result available to the next step.
2. A [Request step](/docs/request) posts the report to your endpoint with the Exchange ID and duration.

<CodePreview>

```bash title="Create the Process"
curl https://data.reecall.io/automation/processes \
  --header 'Content-Type: application/json' \
  --header 'Authorization: Bearer sk_YOUR_API_KEY' \
  --data '{
    "name": "Call report",
    "description": "Judge a completed conversation and post the report",
    "steps": [
      {
        "type": "agent",
        "output": "report",
        "timeout": 60000,
        "config": {
          "provider": "openai",
          "model": "gpt-6-luna",
          "systemPrompt": "You review customer support calls. Judge whether the caller got what they asked for.",
          "input": "Transcript:\n{{ event.data.messages | json }}",
          "outputSchema": {
            "type": "object",
            "properties": {
              "summary": { "type": "string" },
              "resolved": { "type": "boolean" },
              "sentiment": { "type": "string", "enum": ["positive", "neutral", "negative"] },
              "followUp": { "type": "boolean" }
            },
            "required": ["summary", "resolved", "sentiment", "followUp"]
          }
        }
      },
      {
        "type": "request",
        "config": {
          "url": "https://example.com/reecall/call-reports",
          "method": "POST",
          "data": {
            "exchangeId": "{{ event.refId }}",
            "assistantId": "{{ event.data.assistantId }}",
            "duration": "{{ event.data.duration }}",
            "report": "{{ report.output }}"
          }
        }
      }
    ]
  }'
```

</CodePreview>

Replace the `url` with your endpoint. `gpt-6-luna` is a reasoning model: it ignores `temperature` and can take longer than the default 30-second step timeout, so the step sets `timeout` to 60 seconds, the Agent step's own limit.

The Process reads the conversation from the [`exchange.completed` System event](/docs/system-events#exchangecompleted):

- `event.data.messages` is the transcript. The `json` helper turns it into text for the Agent step.
- `event.refId` is the Exchange ID.
- `report.output` is the object the Agent step returned. A field holding only one template keeps the value's type, so the report is sent as an object. See [Templating language](/docs/templating-language).

Copy the `id` of the response for the next step.

## Step 2: Create the Trigger

Link the Process to `exchange.completed`, and limit it to your Assistant with a condition:

```bash title="Create the Trigger"
curl https://data.reecall.io/automation/triggers \
  --header 'Content-Type: application/json' \
  --header 'Authorization: Bearer sk_YOUR_API_KEY' \
  --data '{
    "name": "Call report",
    "eventType": "exchange.completed",
    "processId": "<your-process-id>",
    "conditions": {
      "operator": "AND",
      "conditions": [
        { "source": "event.data.assistantId", "filter": "EQUALS", "value": "<your-assistant-id>" }
      ]
    }
  }'
```

Copy the `id` of the response. The Trigger starts the Process for every conversation of this Assistant that ends from now on.

## Step 3: Hold a conversation

Talk to the Assistant and end the conversation, for example with a browser call from the dashboard. When the Exchange is complete, Reecall announces `exchange.completed` and the Trigger creates a Run.

## Step 4: Read the Run

List the Runs of the Trigger:

```bash title="List the Runs of the Trigger"
curl 'https://workflows.reecall.io/v2/runs?triggerId=<your-trigger-id>' \
  --header 'Authorization: Bearer sk_YOUR_API_KEY'
```

The newest Run comes first. Its `refId` is the ID of the Exchange. Read it to see each step:

```bash title="Read the Run"
curl https://workflows.reecall.io/v2/runs/<run-id> \
  --header 'Authorization: Bearer sk_YOUR_API_KEY'
```

A Run that worked has `status: "succeeded"`, and its two step records are `succeeded`. The request step's record shows the status code your endpoint answered in `params.status`. See [Read a Run](/docs/runs#read-a-run) for every field.

## Result

Your endpoint receives one request per completed conversation:

```json title="Request body"
{
  "exchangeId": "72770d5a-5b25-4118-ba88-786972b29de7",
  "assistantId": "8f9c2b1e-4d3a-4c7b-9e6f-1a2b3c4d5e6f",
  "duration": 73,
  "report": {
    "summary": "The caller could not connect this morning. The Assistant checked the system status and logged a ticket.",
    "resolved": false,
    "sentiment": "neutral",
    "followUp": true
  }
}
```

The request carries an `Idempotency-Key` header. Store it to ignore a request you already received.

## Troubleshooting

| Symptom | Check |
| --- | --- |
| No Run after the conversation | The Trigger's `enabled` field, the Assistant ID in the condition, and the filter name. A misspelled filter never matches. |
| `status: "failed"` with `REQUEST_ERROR` | Your endpoint answered an error or could not be reached. `errorMessage` gives the status code, such as `Request failed with status code 503 (Service Unavailable)`. |
| `REQUEST_BLOCKED` | The URL points to a private or internal address. Use a public HTTPS endpoint. |
| `AGENT_ERROR` or `AGENT_VALIDATION_ERROR` | The Agent step failed or its configuration is invalid. Read `errorMessage`, then compare the step with the [Agent step](/docs/agent#error-handling) reference. |
| `TEMPLATE_ERROR` | A template could not be rendered. `errorMessage` names the field and the expression. See [Templating language](/docs/templating-language). |

## Next steps

- Turn on [retries](/docs/triggers#retry-policy) so a `503` from your endpoint does not lose a report. The Agent step runs again on each retry.
- Keep an endpoint token in a secret [Variable](/docs/variables) and send it with `{{ variables.KEY }}` in the request headers. See [Processes](/docs/processes#variables).
- Read [Runs](/docs/runs) for statuses, limits, and data retention.
