Skip to navigation

Send call results to n8n

Summary

This recipe sends the summary of each finished call from Rasen to an n8n workflow through a signed call.analyzed webhook. The workflow verifies the signature, answers 2xx at once, drops duplicates and reads the summary from the API when the event does not carry it. It does not cover what you do with the summary after that, for example writing it to a sheet or a CRM.

Facts

ItemValue
ResultOne n8n item for each analyzed call, with call_id, summary_state and summary
Rasen operationscreateWebhookEndpoint, sendWebhookTestEvent, getCall, getCallSummary, listWebhookDeliveries
Rasen pathsPOST /webhook-endpoints, POST /webhook-endpoints/{endpoint_id}/test, GET /calls/{call_id}, GET /calls/{call_id}/summary, GET /webhook-endpoints/{endpoint_id}/deliveries
Capabilitywebhooks.manage for the endpoint operations; calls.read for getCall and getCallSummary
Required headersAuthorization on every request; Idempotency-Key on create and test
Eventcall.analyzed: once for each call that got call.completed, when the transcript, recording state and extraction are final, or 6 hours after the call ended
Summary in the eventdata.summary is what getCallSummary returns when Rasen builds the event, or null. The event does not wait for the summary
Reduced eventA body over 1 MiB carries only data.call_id and data.truncated: true
Attempt timeout10 seconds for each attempt. Any 2xx answer is a success; a 3xx answer or a timeout fails the attempt
AttemptsUp to 8. Waits between attempts: 5 seconds, 5 minutes, 30 minutes, 2 hours, 5 hours, 10 hours, 10 hours, each ±10%
Call event windowRasen creates a call’s end event only within 24 hours of the call end
DeliveryAt least once, with the same webhook-id and body on every attempt and resend. No ordering guarantee
Signaturewebhook-signature holds one or two v1,<base64 HMAC-SHA256> values over {webhook-id}.{webhook-timestamp}.{body}. The key is the base64-decoded part of the secret after whsec_
Timestamp windowRefuse a webhook-timestamp more than 5 minutes from your clock
Endpoint urlhttps, with a host that resolves only to public addresses. Redirects are never followed
n8n versionn8n 2.x, self-hosted or n8n Cloud
n8n nodesWebhook, Code, If, Respond to Webhook, Remove Duplicates, HTTP Request
n8n Webhook nodeProduction URL registers when you publish the workflow. Respond: Using 'Respond to Webhook' Node. Option Raw Body puts the exact request bytes in the binary property data
n8n Code nodeJavaScript, mode Run Once for All Items. this.helpers.getBinaryDataBuffer(0, 'data') reads the raw body. n8n Cloud allows require('crypto'); self-hosted n8n needs NODE_FUNCTION_ALLOW_BUILTIN=crypto
Where the signing secret goesSelf-hosted n8n, any edition: an environment variable of the n8n server, read as $env.RASEN_WEBHOOK_SECRET. n8n 2.x blocks $env in nodes unless the server sets N8N_BLOCK_ENV_ACCESS_IN_NODE=false. n8n Cloud Pro and Enterprise, and self-hosted Business and Enterprise: a custom variable, read as $vars.RASEN_WEBHOOK_SECRET
n8n Remove Duplicates nodeRemove Items Processed in Previous Executions keeps a history of 10,000 items by default
Environment for the samplesRASEN_API_BASE (the base URL, ending in /v1), RASEN_API_KEY, N8N_WEBHOOK_URL, ENDPOINT_ID, CALL_ID
Python3.10 or later, with the httpx package
TypeScriptNode.js 22 or later (built-in fetch)

Steps

1. Create the n8n Webhook node

  1. In n8n, create a workflow and add a Webhook node.
  2. Set HTTP Method to POST and Path to call-results.
  3. Set Authentication to None. The signature check in step 3 authenticates each request.
  4. Set Respond to Using 'Respond to Webhook' Node.
  5. Under Options, add Raw Body and turn it on.
  6. Publish the workflow, then copy the Production URL of the node.

The Production URL has the form https://<your n8n host>/webhook/call-results. Set N8N_WEBHOOK_URL to it. The Test URL listens for 120 seconds only, so do not register it with Rasen.

2. Register a Rasen webhook endpoint for call.analyzed

curl -sS -X POST "$RASEN_API_BASE/webhook-endpoints" \
-H "Authorization: Bearer $RASEN_API_KEY" \
-H "Idempotency-Key: $(uuidgen)" \
-H "Content-Type: application/json" \
-d "{\"url\": \"$N8N_WEBHOOK_URL\", \"description\": \"n8n call results\", \"events\": [\"call.analyzed\"]}"

The answer is 201 with the endpoint and its signing secret. No other answer returns the secret, so store it at once. Set ENDPOINT_ID to the id of the endpoint.

Store the secret where your n8n edition can read it:

  • Self-hosted n8n: add these lines to the environment of the n8n server, then restart n8n.

    RASEN_WEBHOOK_SECRET=<the secret from this answer>
    NODE_FUNCTION_ALLOW_BUILTIN=crypto
    N8N_BLOCK_ENV_ACCESS_IN_NODE=false

    N8N_BLOCK_ENV_ACCESS_IN_NODE=false lets every workflow read every environment variable of the server. Give edit access to workflows only to people who may read the secret.

  • n8n Cloud, or a licensed self-hosted edition: create a custom variable named RASEN_WEBHOOK_SECRET with the secret as its value. In step 3, read $vars.RASEN_WEBHOOK_SECRET instead of $env.RASEN_WEBHOOK_SECRET.

The endpoint receives only events that Rasen creates after the endpoint’s created_at.

3. Verify the signature and answer in n8n

Add a Code node after the Webhook node. Name it Verify signature, set Language to JavaScript and Mode to Run Once for All Items, and paste this code:

const crypto = require('crypto');
const TOLERANCE_SECONDS = 5 * 60;
const secret = $env.RASEN_WEBHOOK_SECRET; // n8n Cloud or a licensed edition: $vars.RASEN_WEBHOOK_SECRET
const headers = $input.first().json.headers;
const body = await this.helpers.getBinaryDataBuffer(0, 'data');
function verify() {
const webhookId = headers['webhook-id'];
const timestamp = headers['webhook-timestamp'];
const signatures = headers['webhook-signature'];
if (!secret || !webhookId || !timestamp || !/^[0-9]{1,12}$/.test(timestamp) || !signatures) return false;
if (Math.abs(Date.now() / 1000 - Number(timestamp)) > TOLERANCE_SECONDS) return false;
const key = Buffer.from(secret.replace(/^whsec_/, ''), 'base64');
const expected = crypto.createHmac('sha256', key).update(`${webhookId}.${timestamp}.`).update(body).digest();
return signatures.split(' ').some((value) => {
const [version, signature] = value.split(',', 2);
if (version !== 'v1' || !signature) return false;
const given = Buffer.from(signature, 'base64');
return given.length === expected.length && crypto.timingSafeEqual(given, expected);
});
}
const valid = verify();
return [{ json: { valid, event: valid ? JSON.parse(body.toString('utf8')) : null } }];

The code checks the exact request bytes before it parses the JSON. Then add these nodes:

NodeNameSettings
IfSignature valid?Condition: {{ $json.valid }} is true
Respond to Webhook, on the false outputRejectRespond With: No Data. Option Response Code: 401
Respond to Webhook, on the true outputAcceptRespond With: No Data. Option Response Code: 200
Remove Duplicates, after AcceptDrop repeatsOperation: Remove Items Processed in Previous Executions. Keep Items Where: Value Is New. Value to Dedupe On: {{ $json.event.id }}
If, after Drop repeatsIs call.analyzed?Condition: {{ $json.event.type }} is equal to call.analyzed
Code, on the true outputPick summaryThe code below

Accept answers Rasen before any slow node runs. The workflow then goes on with the event. A webhook.test event passes the signature check, gets 200, and stops at Is call.analyzed?.

Paste this code into Pick summary, with Mode set to Run Once for All Items:

const event = $input.first().json.event;
const data = event.data;
const callId = data.truncated ? data.call_id : data.call.id;
const summary = data.truncated ? null : data.summary;
return [{
json: {
event_id: event.id,
call_id: callId,
summary_state: summary ? summary.state : null,
summary: summary && summary.state === 'ready' ? summary.summary : null,
end_reason: data.truncated ? null : data.call.end_reason,
},
}];

4. Read the summary when the event does not carry it

Add an If node named Summary ready? after Pick summary, with the condition {{ $json.summary_state }} is equal to ready. On its false output, add an HTTP Request node named Read summary:

SettingValue
MethodGET
URL<RASEN_API_BASE>/calls/{{ $json.call_id }}/summary, with your API base URL ending in /v1
AuthenticationGeneric Credential Type, then Header Auth, with Name Authorization and Value Bearer <your API key>

These requests show what Read summary sends, with getCall for the call fields of a reduced event. Set CALL_ID to the call_id of the item.

curl -sS "$RASEN_API_BASE/calls/$CALL_ID" \
-H "Authorization: Bearer $RASEN_API_KEY"
curl -sS "$RASEN_API_BASE/calls/$CALL_ID/summary" \
-H "Authorization: Bearer $RASEN_API_KEY"

getCallSummary answers the summary with its state. summary holds text only when state is ready. While state is pending, wait poll_after_seconds (an n8n Wait node, Resume After Time Interval) and read it again. not_requested, failed and unavailable do not change into ready on their own: store the item with summary null.

5. Send a test event

curl -sS -X POST "$RASEN_API_BASE/webhook-endpoints/$ENDPOINT_ID/test" \
-H "Authorization: Bearer $RASEN_API_KEY" \
-H "Idempotency-Key: $(uuidgen)"

The answer is 201 with the queued delivery of one webhook.test event, signed like every other event. In n8n, open the Executions tab of the workflow. The execution passes Verify signature with valid: true and ends at Is call.analyzed?.

Rules

  • MUST register the Production URL, and MUST publish the workflow before Rasen sends events.
  • MUST verify the signature over the raw body bytes before you parse or use the event.
  • MUST answer 2xx within 10 seconds. Put Accept before every slow node.
  • MUST answer 401 or another status that is not 2xx when the signature check fails.
  • MUST drop repeats by the event id, which equals the webhook-id header. Rasen delivers at least once.
  • MUST read the call with getCall and getCallSummary when data.truncated is true.
  • MUST answer 2xx to an event type that you do not know, and ignore it.
  • MUST NOT store the signing secret in a node parameter that people who edit the workflow can read in plain text. Use a server environment variable (self-hosted), a custom variable (licensed editions) or your secret store.
  • After Accept answers 2xx, Rasen does not send the event again. If a later node fails, resend the delivery with resendWebhookDelivery, or read the call with getCall.

Verify

curl -sS -G "$RASEN_API_BASE/webhook-endpoints/$ENDPOINT_ID/deliveries" \
-H "Authorization: Bearer $RASEN_API_KEY" \
--data-urlencode "event_type=webhook.test" \
--data-urlencode "state=succeeded"

Expected output: at least one item with "state": "succeeded" and "last_status_code": 200.

{"items": [{"id": "wdl_01j00000000000000000000000", "event_type": "webhook.test", "call_id": null, "state": "succeeded", "attempt_count": 1, "max_attempts": 8, "last_status_code": 200, "last_error_class": null}], "next_cursor": null}

Errors

CodeCauseFix
outbound_destination_refusedThe n8n URL is not https, or its host does not resolve only to public addressesExpose n8n on a public https host, then register its Production URL
invalid_requestThe url has user information or a fragment, or events repeats a valueFix the field in details.field and send the request with a new Idempotency-Key
conflict (details.reason: endpoint_limit_reached)The workspace has 10 endpoints that are not deletedDelete an endpoint, or add call.analyzed to an existing endpoint with replaceWebhookEndpoint
conflict (details.reason: endpoint_disabled)The test event targets an endpoint in state: disabled or disabled_failingEnable the endpoint with replaceWebhookEndpoint and "enabled": true
forbiddenThe key lacks webhooks.manage or calls.readUse a key with the capability in details.required_capabilities
not_foundThe endpoint or call does not exist in this workspaceCheck ENDPOINT_ID with listWebhookEndpoints, or CALL_ID with listCalls
last_error_class: http_status on a deliveryn8n answered a status that is not 2xx: the workflow is not published, or the signature check failedPublish the workflow, and check RASEN_WEBHOOK_SECRET against the endpoint’s secret_hint
access to env vars denied in the n8n executionn8n 2.x blocks $env in nodesSet N8N_BLOCK_ENV_ACCESS_IN_NODE=false on the n8n server, and restart n8n
last_error_class: timeout on a deliveryn8n did not answer within 10 secondsMove Accept directly after Signature valid?