Relay.Calling.Call
All calls in SignalWire have a common generic interface, Relay.Calling.Call. A Relay.Calling.Call is a connection between SignalWire and another device.
Properties
Methods
amd
Alias for detectAnsweringMachine.
amdAsync
Alias for detectAnsweringMachineAsync.
answer
Answer an inbound call.
Parameters
None
Returns
Promise<Relay.Calling.AnswerResult> - Promise object that will be fulfilled with a Relay.Calling.AnswerResult object.
Examples
Answer an inbound call and check if it was successful.
connect
Attempt to connect an existing call to a new outbound call and waits until one of the remote party picks the call or the connect fails.
This method involves complex nested parameters. You can connect to multiple devices in series, parallel, or any combination of both with creative use of the parameters. Series implies one device at a time, while parallel implies multiple devices at the same time.
Parameters
- Structure of a device:
Returns
Promise<Relay.Calling.ConnectResult> - Promise object that will be fulfilled with a Relay.Calling.ConnectResult object.
Examples
Try connecting by calling
+18991114444and+18991114445in series.
Combine serial and parallel calling. Call
+18991114443first and - if it doesn’t answer - try calling in parallel+18991114444and+18991114445. If none of the devices answer, continue the same process with+18991114446and+18991114447.
Try connecting by calling
+18991114444and+18991114445in series playing the US ringtone.
connectAsync
Asynchronous version of connect. It does not wait the connect to completes or fails but returns a Relay.Calling.ConnectAction you can interact with.
Parameters
See connect for the parameter list.
Returns
Promise<Relay.Calling.ConnectAction> - Promise object that will be fulfilled with a Relay.Calling.ConnectAction object.
Examples
Trying to connect a call by calling in series
+18991114444and+18991114445.
faxReceive
Prepare the call to receive an inbound fax. It waits until the fax has been received or failed.
Parameters
None
Returns
Promise<Relay.Calling.FaxResult> - Promise object that will be fulfilled with a Relay.Calling.FaxResult object.
Examples
Receiving a fax on the call and print logs for URL and number of received pages.
faxReceiveAsync
Asynchronous version of faxReceive. It does not wait the fax to be received but returns a Relay.Calling.FaxAction you can interact with.
Parameters
None
Returns
Promise<Relay.Calling.FaxAction> - Promise object that will be fulfilled with a Relay.Calling.FaxAction object.
Examples
Trying to receive a fax. Stop the attempt after 5 seconds.
faxSend
Send a Fax through the call. It waits until the fax has been sent or failed.
Parameters
Returns
Promise<Relay.Calling.FaxResult> - Promise object that will be fulfilled with a Relay.Calling.FaxResult object.
Examples
Sending a fax on the call and print logs the number of sent pages.
faxSendAsync
Asynchronous version of faxSend. It does not wait the fax to be sent but returns a Relay.Calling.FaxAction you can interact with.
Parameters
See faxSend for the parameter list.
Returns
Promise<Relay.Calling.FaxAction> - Promise object that will be fulfilled with a Relay.Calling.FaxAction object.
Examples
Trying to send a fax. Stop sending it after 5 seconds.
dial
This will start a call that was created with newCall and waits until the Call has been answered or hung up.
Parameters
None
Returns
Promise<Relay.Calling.DialResult> - Promise object that will be fulfilled with a Relay.Calling.DialResult object.
Examples
hangup
Hangup the call.
Parameters
None
Returns
Promise<Relay.Calling.HangupResult> - Promise object that will be fulfilled with a Relay.Calling.HangupResult object.
Examples
Hangup a call and check if it was successful.
play
Play one or multiple media in a Call and waits until the playing has ended.
The play method is a generic method for all types of playing, see playAudio, playSilence, playTTS or playRingtone for more specific usage.
Parameters
- To play an audio file:
- To play a text to speech string:
- To play silence:
- To play ringtone:
Returns
Promise<Relay.Calling.PlayResult> - Promise object that will be fulfilled with a Relay.Calling.PlayResult object.
Examples
Play multiple media in one request setting volume to 6dB.
playAsync
Asynchronous version of play. It does not wait the playing to completes but returns a Relay.Calling.PlayAction you can interact with.
Parameters
See play for the parameter list.
Returns
Promise<Relay.Calling.PlayAction> - Promise object that will be fulfilled with a Relay.Calling.PlayAction object.
Examples
Play multiple media elements in the call and stop them after 5 seconds.
playAudio
This is a helper function that refines the use of play. This simplifies playing an audio file.
Parameters
Returns
Promise<Relay.Calling.PlayResult> - Promise object that will be fulfilled with a Relay.Calling.PlayResult object.
Examples
Play an Mp3 file using the signature with a
stringas parameter.
Play an Mp3 file setting volume level to 4dB.
playAudioAsync
Asynchronous version of playAudio. It does not wait the playing to completes but returns a Relay.Calling.PlayAction you can interact with.
Parameters
See playAudio for the parameter list.
Returns
Promise<Relay.Calling.PlayAction> - Promise object that will be fulfilled with a Relay.Calling.PlayAction object.
Examples
Play an Mp3 file and stop it after 5 seconds.
playTTS
This is a helper function that refines the use of play. This simplifies playing TTS.
Parameters
Returns
Promise<Relay.Calling.PlayResult> - Promise object that will be fulfilled with a Relay.Calling.PlayResult object.
Examples
Play TTS.
playTTSAsync
Asynchronous version of playTTS. It does not wait the playing to completes but returns a Relay.Calling.PlayAction you can interact with.
Parameters
See playTTS for the parameter list.
Returns
Promise<Relay.Calling.PlayAction> - Promise object that will be fulfilled with a Relay.Calling.PlayAction object.
Examples
Play TTS and stop it after 5 seconds.
playSilence
This is a helper function that refines the use of play. This simplifies playing silence.
Parameters
Returns
Promise<Relay.Calling.PlayResult> - Promise object that will be fulfilled with a Relay.Calling.PlayResult object.
Examples
Play silence for 10 seconds.
playSilenceAsync
Asynchronous version of playSilence. It does not wait the playing to completes but returns a Relay.Calling.PlayAction you can interact with.
Parameters
See playSilence for the parameter list.
Returns
Promise<Relay.Calling.PlayAction> - Promise object that will be fulfilled with a Relay.Calling.PlayAction object.
Examples
Play silence for 60 seconds, if Agent is available, stop the play.
playRingtone
This is a helper function that refines the use of play. This simplifies playing ringtones.
Parameters
Returns
Promise<Relay.Calling.PlayResult> - Promise object that will be fulfilled with a Relay.Calling.PlayResult object.
Examples
Play a single US ringtone.
playRingtoneAsync
Asynchronous version of playRingtone. It does not wait the playing to completes but returns a Relay.Calling.PlayAction you can interact with.
Parameters
See playRingtone for the parameter list.
Returns
Promise<Relay.Calling.PlayAction> - Promise object that will be fulfilled with a Relay.Calling.PlayAction object.
Examples
Play US ringtone for 30 seconds and stop it after 5 seconds.
detect
Start a detector on the call and waits until it has finished or failed.
The detect method is a generic method for all types of detecting, see detectAnsweringMachine, detectDigit or detectFax for more specific usage.
Parameters
- To detect an answering machine:
- To detect digits:
- To detect a fax:
Returns
Promise<Relay.Calling.DetectResult> - Promise object that will be fulfilled with a Relay.Calling.DetectResult object.
Examples
Detect a machine with custom parameters and timeout.
Detect a Fax setting timeout only.
detectAsync
Asynchronous version of detect. It does not wait the detector ends but returns a Relay.Calling.DetectAction you can interact with.
Parameters
See detect for the parameter list.
Returns
Promise<Relay.Calling.DetectAction> - Promise object that will be fulfilled with a Relay.Calling.DetectAction object.
Examples
Detect all the digits using default parameters. Stop the action after 5 seconds.
detectAnsweringMachine
This is a helper function that refines the use of detect. The Promise will be resolved with a Relay.Calling.DetectResult object as soon as the detector decided who answered the call: MACHINE, HUMAN or UNKNOWN.
Parameters
Returns
Promise<Relay.Calling.DetectResult> - Promise object that will be fulfilled with a Relay.Calling.DetectResult object.
Examples
Perform an AMD and wait until the machine is ready.
detectAnsweringMachineAsync
Asynchronous version of detectAnsweringMachine. It does not wait the detector ends but returns a Relay.Calling.DetectAction you can interact with.
Parameters
See detectAnsweringMachine for the parameter list.
Returns
Promise<Relay.Calling.DetectAction> - Promise object that will be fulfilled with a Relay.Calling.DetectAction object.
Examples
Perform an asynchronous AMD on the call. Then stop the action if not completed yet.
detectDigit
This is a helper function that refines the use of detect. This simplifies detecting digits on a call.
Parameters
Returns
Promise<Relay.Calling.DetectResult> - Promise object that will be fulfilled with a Relay.Calling.DetectResult object.
Examples
Detect digits and then write a log with the result.
detectDigitAsync
Asynchronous version of detectDigit. It does not wait the detector ends but returns a Relay.Calling.DetectAction you can interact with.
Parameters
See detectDigit for the parameter list.
Returns
Promise<Relay.Calling.DetectAction> - Promise object that will be fulfilled with a Relay.Calling.DetectAction object.
Examples
Detect only
1-3digits. Stop the action after 5 seconds.
detectFax
This is a helper function that refines the use of detect. This simplifies detecting a fax.
Parameters
Returns
Promise<Relay.Calling.DetectResult> - Promise object that will be fulfilled with a Relay.Calling.DetectResult object.
Examples
Detect fax on the current call.
detectFaxAsync
Asynchronous version of detectFax. It does not wait the detector ends but returns a Relay.Calling.DetectAction you can interact with.
Parameters
See detectFax for the parameter list.
Returns
Promise<Relay.Calling.DetectAction> - Promise object that will be fulfilled with a Relay.Calling.DetectAction object.
Examples
Detect fax on the current call. Stop the action after 5 seconds.
prompt
Play one or multiple media while collecting user’s input from the call at the same time, such as digits and speech. It waits until the collection succeed or timeout is reached.
The prompt method is a generic method, see promptAudio, promptTTS or promptRingtone for more specific usage.
Parameters
- To collect digits:
- To collect speech:
Returns
Promise<Relay.Calling.PromptResult> - Promise object that will be fulfilled with a Relay.Calling.PromptResult object.
Examples
Ask user to enter their PIN and collect the digits.
promptAsync
Asynchronous version of prompt. It does not wait the collection to completes but returns a Relay.Calling.PromptAction you can interact with.
Parameters
See prompt for the parameter list.
Returns
Promise<Relay.Calling.PromptAction> - Promise object that will be fulfilled with a Relay.Calling.PromptAction object.
Examples
Ask user to enter their PIN and collect the digits.
promptAudio
This is a helper function that refines the use of prompt. This function simplifies playing an audio file while collecting user’s input from the call, such as digits and speech.
Parameters
You can set all the properties that prompt accepts replacing media with:
The SDK will build the media for you.
Returns
Promise<Relay.Calling.PromptResult> - Promise object that will be fulfilled with a Relay.Calling.PromptResult object.
Examples
Collect user’s digits while playing an Mp3 file.
promptAudioAsync
Asynchronous version of promptAudio. It does not wait the collection to completes but returns a Relay.Calling.PromptAction you can interact with.
Parameters
See promptAudio for the parameter list.
Returns
Promise<Relay.Calling.PromptAction> - Promise object that will be fulfilled with a Relay.Calling.PromptAction object.
Examples
Ask user to enter their PIN and collect the digits.
promptTTS
This is a helper function that refines the use of prompt. This function simplifies playing TTS while collecting user’s input from the call, such as digits and speech.
Parameters
You can set all the properties that prompt accepts replacing media with:
The SDK will build the media for you.
Returns
Promise<Relay.Calling.PromptResult> - Promise object that will be fulfilled with a Relay.Calling.PromptResult object.
Examples
Ask user to enter their PIN and collect the digits.
promptTTSAsync
Asynchronous version of promptTTS. It does not wait the collection to completes but returns a Relay.Calling.PromptAction you can interact with.
Parameters
See promptTTS for the parameter list.
Returns
Promise<Relay.Calling.PromptAction> - Promise object that will be fulfilled with a Relay.Calling.PromptAction object.
Examples
Ask user to enter their PIN and collect the digits.
detectHuman
This is a helper function that refines the use of detect. This simplifies detecting a human on the call and is the inverse of detectMachine.
Deprecated since: v2.2 - Use detectAnsweringMachine instead.
Parameters
Returns
Promise<Relay.Calling.DetectResult> - Promise object that will be fulfilled with a Relay.Calling.DetectResult object.
Examples
Detect a human on the current call.
detectHumanAsync
Asynchronous version of detectHuman. It does not wait the detector ends but returns a Relay.Calling.DetectAction you can interact with.
Deprecated since: v2.2 - Use detectAnsweringMachineAsync instead.
Parameters
See detectHuman for the parameter list.
Returns
Promise<Relay.Calling.DetectAction> - Promise object that will be fulfilled with a Relay.Calling.DetectAction object.
Examples
Detect a human on the current call. Stop the action after 5 seconds.
detectMachine
This is a helper function that refines the use of detect. This simplifies detecting a machine on the call and is the inverse of detectHuman.
Deprecated since: v2.2 - Use detectAnsweringMachine instead.
Parameters
Returns
Promise<Relay.Calling.DetectResult> - Promise object that will be fulfilled with a Relay.Calling.DetectResult object.
Examples
Detect a machine on the current call.
detectMachineAsync
Asynchronous version of detectMachine. It does not wait the detector ends but returns a Relay.Calling.DetectAction you can interact with.
Deprecated since: v2.2 - Use detectAnsweringMachineAsync instead.
Parameters
See detectMachine for the parameter list.
Returns
Promise<Relay.Calling.DetectAction> - Promise object that will be fulfilled with a Relay.Calling.DetectAction object.
Examples
Detect a machine on the current call. Stop the action after 5 seconds.
on
Attach an event handler for the event.
Parameters
Returns
Relay.Calling.Call - The call object itself.
Examples
Subscribe to the
answeredandendedevents for a given call.
off
Remove an event handler that were attached with .on(). If you don’t pass a handler, all listeners for that event will be removed.
Parameters
Returns
Relay.Calling.Call - The call object itself.
Examples
Subscribe to the call
endedstate change and then, remove the event handler.
pass
This will allow a consumer to decline incoming calls without ending the call and redirect the call to another RELAY consumer.
Parameters
None
Returns
Promise<Relay.Calling.PassResult> - Promise object that will be fulfilled with a Relay.Calling.PassResult object.
Examples
Pass the inbound call.
record
Start recording the call and waits until the recording ends or fails.
Parameters
Returns
Promise<Relay.Calling.RecordResult> - Promise object that will be fulfilled with a Relay.Calling.RecordResult object.
Examples
Start recording audio in the call for both direction in stereo mode, if successful, grab
url,durationandsizefrom the RecordResult object.
recordAsync
Asynchronous version of record. It does not wait the end of recording but returns a Relay.Calling.RecordAction you can interact with.
Parameters
See record for the parameter list.
Returns
Promise<Relay.Calling.RecordAction> - Promise object that will be fulfilled with a Relay.Calling.RecordAction object.
Examples
Start recording audio in the call for both direction in stereo mode and stop it after 5 seconds.
refer
Transfer a SIP call to an external SIP endpoint.
Parameters
Returns
Promise<Relay.Calling.ReferResult> - Promise object that will be fulfilled with a Relay.Calling.ReferResult object.
Examples
Transfer the
callto another SIP endpoint.
referAsync
Asynchronous version of refer. It does not wait the end of the REFER but returns a Relay.Calling.ReferAction you can interact with.
Parameters
See refer for the parameter list.
Returns
Promise<Relay.Calling.ReferAction> - Promise object that will be fulfilled with a Relay.Calling.ReferAction object.
Examples
Async transfer the
callto another SIP endpoint.
sendDigits
This method sends DTMF digits to the other party on the call.
Parameters
Returns
Promise<Relay.Calling.SendDigitsResult> - Promise object that will be fulfilled with a Relay.Calling.SendDigitsResult object.
Examples
Send some digits.
sendDigitsAsync
Asynchronous version of sendDigits. It does not wait for the sending event to complete, and immediately returns a Relay.Calling.SendDigitsAction object you can interact with.
Parameters
See sendDigits for the parameter list.
Returns
Promise<Relay.Calling.SendDigitsAction> - Promise object that will be fulfilled with a Relay.Calling.SendDigitsAction object.
Examples
Send some digits and then check if the operation is completed using the SendDigitsAction object.
tap
Intercept call media and stream it to the specify endpoint. It waits until the end of the call.
Parameters
- To
tapthrough RTP:
Returns
Promise<Relay.Calling.TapResult> - Promise object that will be fulfilled with a Relay.Calling.TapResult object.
Examples
Tapping audio from the call, if successful, print both source and destination devices from the
TapResultobject.
tapAsync
Asynchronous version of tap. It does not wait the end of tapping but returns a Relay.Calling.TapAction you can interact with.
Parameters
See tap for the parameter list.
Returns
Promise<Relay.Calling.TapAction> - Promise object that will be fulfilled with a Relay.Calling.TapAction object.
Examples
Tapping audio from the call and then stop it using the
TapActionobject.
promptRingtone
This is a helper function that refines the use of prompt. This function simplifies playing ringtones while collecting user’s input from the call, such as digits and speech.
Parameters
You can set all the properties that prompt accepts replacing media with:
The SDK will build the media for you.
Returns
Promise<Relay.Calling.PromptResult> - Promise object that will be fulfilled with a Relay.Calling.PromptResult object.
Examples
Play US ringtone for 30 seconds while collect digits.
promptRingtoneAsync
Asynchronous version of promptRingtone. It does not wait the collection to completes but returns a Relay.Calling.PromptAction you can interact with.
Parameters
See promptRingtone for the parameter list.
Returns
Promise<Relay.Calling.PromptAction> - Promise object that will be fulfilled with a Relay.Calling.PromptAction object.
Examples
Play US ringtone for 30 seconds while collect digits in asynchronous.
waitFor
Wait for specific events on the Call or returns false if the Call ends without getting them.
Parameters
Returns
Promise<boolean> - Promise resolved with true or false.
Examples
Wait for
endingorendedevents.
waitForAnswered
This is a helper function that refines the use of waitFor. This simplifies waiting for the answered state.
Parameters
None
Returns
Promise<boolean> - Promise resolved with true or false.
Examples
Wait for the
answeredevent.
waitForEnded
This is a helper function that refines the use of waitFor. This simplifies waiting for the ended state.
Parameters
None
Returns
Promise<boolean> - Promise resolved with true or false.
Examples
Wait for the
endedevent.
waitForEnding
This is a helper function that refines the use of waitFor. This simplifies waiting for the ending state.
Parameters
None
Returns
Promise<boolean> - Promise resolved with true or false.
Examples
Wait for the
endingevent.
waitForRinging
This is a helper function that refines the use of waitFor. This simplifies waiting for the ringing state.
Parameters
None
Returns
Promise<boolean> - Promise resolved with true or false.
Examples
Wait for the
ringingevent.
Events
All these events can be used to track the calls lifecycle and instruct SignalWire on what to do for each different state.
State Events
To track the state of a call.
Connect Events
To track the connect state of a call.
Play Events
To track a playback state.
Record Events
To track a recording state.
Refer Events
To track a REFER state.
Prompt Events
To track a prompt state.
Fax Events
To track a fax state.
Detect Events
To track a detector state.
Tap Events
To track a tapping state.
Digits Events
To track a send digits action state.
Ringtones
Here you can find all the accepted values for the ringtone to play, based on short country codes: