For AI agents: a documentation index is available at the root level at /llms.txt and /llms-full.txt. Append /llms.txt to any URL for a page-level index, or .md for the markdown version of any page.
Log inSign up
Support
GuidesReference
GuidesReference
    • Core
      • Overview
    • Agents
      • Overview
      • AgentBase
      • AgentServer
      • Configuration
      • ContextBuilder
      • DataMap
      • FunctionResult
      • Helper Functions & Utilities
      • LiveWire
      • PomBuilder
      • Prefabs
      • SkillBase
      • SkillManager
      • SkillRegistry
      • Skills
      • SwaigFunction
      • SwmlBuilder
      • SWMLService
    • RELAY
      • Overview
      • Actions
      • Call
      • Constants
      • Events
      • Message
      • RelayClient
        • connect
        • dial
        • disconnect
        • execute
        • onCall
        • onMessage
        • receive
        • run
        • sendMessage
        • unreceive
      • RelayError
    • REST Client
      • Overview
      • Addresses
      • Calling
      • ChatResource
      • Compat
      • Datasphere
      • Fabric
      • ImportedNumbersResource
      • Logs
      • LookupResource
      • MFA
      • Number Groups
      • Phone Numbers
      • Project
      • PubSubResource
      • Queues
      • Recordings
      • Registry
      • RestClient
      • RestError
      • Short Codes
      • SIP Profile
      • Verified Callers
      • Video
LogoLogoSignalWire Docs
Log inSign up
Support
On this page
  • Parameters
  • Returns
  • Example
RELAYRelayClient

onCall

|View as Markdown|Open in Claude|
Was this page helpful?
Edit this page
Previous

onMessage

Next
Built with

Register the inbound call handler. The provided function is called once for each calling.call.receive event on the subscribed contexts. The function receives a Call object with all call properties and control methods.

Only one call handler can be active at a time. Calling onCall() again replaces the previous handler.

Parameters

handler
CallHandlerRequired

An async function that receives a Call object. Signature: (call: Call) => void | Promise<void>.

Returns

CallHandler — the same handler, returned to support decorator-style usage (e.g., TypeScript 5 decorators or manual composition).

Example

1import { RelayClient } from '@signalwire/sdk';
2
3const client = new RelayClient({
4 project: process.env.SIGNALWIRE_PROJECT_ID!,
5 token: process.env.SIGNALWIRE_API_TOKEN!,
6 contexts: ['default']
7});
8
9client.onCall(async (call) => {
10 console.log(`Received call: ${call.callId}`);
11 await call.answer();
12 const action = await call.play([{ type: 'tts', text: 'Hello!' }]);
13 await action.wait();
14 await call.hangup();
15});
16
17await client.run();