Skip to navigation

onCallEnd

View as MarkdownOpen in Claude

Register a handler that runs when the call ends, with the transcript. Handlers run in registration order.

The SDK registers the platform’s reserved hangup_hook function for you. It fires on hangup and is never offered to the model, so it can’t be called early or skipped. Registering the first handler also turns on the swaig_post_conversation parameter. Without it the hook still fires but carries no transcript, and the handler would receive an empty list with nothing to say why. If you have explicitly set that parameter to false, the SDK leaves it alone and logs a warning.

A handler’s return value is ignored, since the call is over. An exception is logged, not raised, so a failing handler doesn’t stop the others. For the post-prompt summary, see onSummary(); for the start of the call, see onCallStart().

Parameters

handler
(callLog: Record<string, unknown>[], rawData: SwaigRequest) => void | Promise<void>Required

Called as handler(callLog, rawData). May be async.

  • callLog — the conversation as the platform recorded it.
  • rawData — the complete SWAIG request, including global_data and call_id.

Returns

The handler, unchanged.

Example

import { AgentBase } from '@signalwire/sdk';
const agent = new AgentBase({ name: 'dispatch', route: '/dispatch' });
agent.setPromptText('You are Ada, the dispatcher for Bayview Taxi.');
agent.onCallEnd((callLog, rawData) => {
const conversationId = rawData.global_data?.['conversation_id'];
// Write the transcript to your system of record.
console.log(conversationId, callLog.length, 'turns');
});
await agent.serve();

To handle voice and chat transcripts with one shape, pass rawData through normalizePostPrompt().