Skip to main content

Relay.Calling

This represents the API interface for the Calling Relay Service. This object is used to make requests related to managing end to end calls.

Methods

dial

Make an outbound Call and waits until it has been answered or hung up.

Parameters

ParameterTypeDefaultDescription
typestringrequiredThe type of call. Only phone and sip are currently supported
fromstringrequiredThe party the call is coming from. Must be a SignalWire number or SIP endpoint that you own
tostringrequiredThe party you are attempting to call
timeoutnumberoptionalThe time, in seconds, the call will ring before going to voicemail
from_namestringoptionalSIP only. The caller ID name to display
headersHeader[]optionalSIP only. Array of Header objects like: { name: string, value: string }. Must be X- headers only, see example below
codecsstringoptionalSIP only. Optional array of desired codecs in order of preference. Supported values are PCMU, PCMA, OPUS, G729, G722, VP8, H264. Default is parent leg codec(s)
webrtc_mediabooleanoptionalSIP only. If true, WebRTC media is negotiated. Default is parent leg setting

Returns

Promise<Relay.Calling.DialResult> - Promise that will be fulfilled with a Relay.Calling.DialResult object.

Examples

Make an outbound Call and grab the call object if it was answered.

async function main() {
const dialResult = await client.calling.dial({
type: 'phone',
from: '+1XXXXXXXXXX',
to: '+1YYYYYYYYYY',
timeout: 30
})

if (dialResult.successful) {
const { call } = dialResult
}
}

main().catch(console.error)

Make an outbound Call to a SIP endpoint.

async function main() {
const dialResult = await client.calling.dial({
type: 'sip',
from: 'sip:XXXX@XXXXX.XXX',
to: 'sip:YYYY@YYYYY.YYY',
timeout: 30
})

if (dialResult.successful) {
const { call } = dialResult
}
}

main().catch(console.error)

Dial a SIP endpoint with custom headers.

client.calling.dial({
type: 'sip',
from: 'sip:XXXX@XXXXX.XXX',
to: 'sip:YYYY@YYYYY.YYY',
timeout: 30,
headers: [{
"name": "X-Relay-Call-ID",
"value": "697a4e98-f452-416f-b11e-63c19112f542"
}, {
"name": "X-CID",
"value": "124077399_129412436@206.117.11.72"
}, {
"name": "X-Target-Type",
"value": "classic"
}]
})

newCall

Create a new Call object. The call has not started yet allowing you to attach event listeners on it.

Parameters

See dial for the parameter list.

Returns

Call - A new Relay.Calling.Call object.

Example

const call = client.calling.newCall({
type: 'phone',
from: '+1XXXXXXXXXX',
to: '+1YYYYYYYYYY',
timeout: 30
})

// Use the call object...