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
  • Examples
  • Add contexts at runtime
  • With inbound call handler
RELAYRelayClient

receive

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

run

Next
Built with

Subscribe to additional contexts for inbound call and message events. Sends a signalwire.receive request to start receiving events on the specified contexts without reconnecting.

Use this to dynamically expand the set of contexts after the initial connection. Contexts passed to the RelayClient constructor are subscribed automatically at connect time — this method is for adding more at runtime.

Contexts are strings that act as routing labels. A phone number configured in your SignalWire dashboard sends calls to a specific context. Subscribe to that context to receive those calls.

Parameters

contexts
string[]Required

List of context names to subscribe to. If the list is empty, the method returns immediately without sending a request.

Returns

Promise<void>

Examples

Add contexts at runtime

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: ['sales']
7});
8
9await client.connect();
10
11// Dynamically subscribe to additional contexts after connecting
12await client.receive(['support', 'billing']);
13console.log('Now receiving calls on sales, support, and billing');
14
15await client.disconnect();

With inbound call handler

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: ['sales']
7});
8
9client.onCall(async (call) => {
10 console.log(`Call on context: ${call.context}`);
11 await call.answer();
12 await call.hangup();
13});
14
15await client.connect();
16await client.receive(['support', 'billing']);
17console.log('Now also receiving on support and billing');