Relay.Calling.Call
Relay.Calling.Call
All calls in SignalWire have a common generic interface, Call. A Call is a connection between SignalWire and another device.
Properties
Methods
Answer
Answer an inbound call.
Returns
*signalwire.AnswerResult - The result of the answer operation.
Examples
Answer an inbound call and check if it was successful:
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.
Returns
*signalwire.DetectResult - The result of the detect operation.
DetectMachineAsync, DetectFaxAsync, DetectDigitAsync
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
pointer to DetectAction, error
Examples
Detect digits using default parameters.
Detect digits using filter.
detectMachine
Detect whether the call was answered by a human or an answering machine.
Parameters
DetectMachineParams Properties
Returns
*signalwire.DetectResult - The result of the machine detection.
Examples
Perform an AMD and wait until the machine is ready:
detectMachineAsync
Asynchronous version of detectMachine. It does not wait for the detector to end but returns a DetectAction you can interact with.
Parameters
See detectMachine for the parameter list.
Returns
*signalwire.DetectAction, error - The detect action and any error.
Examples
Perform an asynchronous AMD on the call. Then stop the action if not completed yet:
detectDigit
Detect DTMF digits on the call.
Parameters
DetectDigitParams Properties
Returns
*signalwire.DetectResult - The result of the digit detection.
Examples
Detect digits and then write a log with the result:
detectDigitAsync
Asynchronous version of detectDigit.
Returns
*signalwire.DetectAction, error - The detect action and any error.
Examples
Detect only 1-3 digits asynchronously:
detectFax
Detect fax tones on the call.
Parameters
DetectFaxParams Properties
Returns
*signalwire.DetectResult - The result of the fax detection.
Examples
Detect fax on the current call.
detectFaxAsync
Asynchronous version of detectFax.
Returns
*signalwire.DetectAction, error - The detect action and any error.
Examples
Detect fax on the current call. Stop the action immediately.
hangup
Hangup the call.
Returns
*signalwire.HangupResult - The result of the hangup operation.
Examples
Hangup the current call:
playAudio
Play an audio file on the call.
Parameters
Returns
*signalwire.PlayResult, error - The result of the play operation and any error.
Examples
Play an MP3 file:
playAudioAsync
Asynchronous version of playAudio.
Returns
*signalwire.PlayAction, error - The play action and any error.
Examples
Play an Mp3 file and stop it after 5 seconds.
playTTS
Play text-to-speech on the call.
Parameters
Returns
*signalwire.PlayResult, error - The result of the play operation and any error.
Examples
Play TTS:
playTTSAsync
Asynchronous version of playTTS.
Returns
*signalwire.PlayAction, error - The play action and any error.
Examples
Play TTS and stop it after 1 second.
record
Start recording the call and wait until the recording ends or fails.
Parameters
RecordParams Properties
Returns
*signalwire.RecordResult, error - The result of the record operation and any error.
Examples
Start recording audio in the call for both direction in stereo mode, if successful, grab url, duration and size from the RecordResult object:
recordAsync
Asynchronous version of record.
Returns
*signalwire.RecordAction, error - The record action and any error.
Examples
Start recording audio in the call for both direction in stereo mode and then stop it using the RecordAction object:
sendFax
Send a fax through the call.
Parameters
Returns
*signalwire.FaxResult, error - The result of the fax operation and any error.
Examples
Sending a fax on the call:
sendFaxAsync
Asynchronous version of sendFax.
Returns
*signalwire.FaxAction, error - The fax action and any error.
Examples
Trying to send a fax and then stop it:
receiveFax
Prepare the call to receive an inbound fax.
Returns
*signalwire.FaxResult, error - The result of the fax operation and any error.
Examples
Receiving a fax on the call and print logs for URL and number of received pages:
receiveFaxAsync
Asynchronous version of receiveFax.
Returns
*signalwire.FaxAction, error - The fax action and any error.
Examples
Trying to receive a fax and then stop it:
dial
This will start a call that was created with NewCall and waits until the Call has been answered or hung up.
Returns
*signalwire.DialResult - The result of the dial operation.
Examples
play
Play one or multiple media in a call and wait until the playing has ended.
The Play method is a generic method for all types of playing, see playAudio, playSilence or playTTS for more specific usage.
Parameters
- To play an audio file use the PlayAudio type to set the URL for the audio file:
- To play text to speech use the PlayTTS type to set the TTS params:
- To play silence use the PlaySilence type to set the Duration:
Returns
[]*signalwire.PlayResult - Array of PlayResult.
Examples
Play multiple media elements in the call:
playAsync
Asynchronous version of play. It does not wait the playing to complete but returns a PlayAction you can interact with. This will run all Play actions in parallel.
Parameters
See play for the parameter list.
Returns
[]*signalwire.PlayAction - Array of pointers to PlayAction.
Examples
Play multiple media elements in the call and then stop it:
playSilence
This is a helper function that refines the use of play. This simplifies playing silence.
Parameters
Returns
*signalwire.PlayResult, error - The result of the play operation and any error.
Examples
Play silence for 3 seconds:
playSilenceAsync
Asynchronous version of playSilence. It does not wait the playing to completes but returns a PlayAction you can interact with.
Parameters
See playSilence for the parameter list.
Returns
*signalwire.PlayAction, error - The play action and any error.
Examples
Play silence for 3 seconds (async):
prompt
Play one or more 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. This is a general method for all types of playing, see promptAudio or promptTTS for more specific usage.
Parameters
Returns
*signalwire.PromptResult - The result object to interact with.
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 PromptAction you can interact with.
Parameters
See prompt for the parameter list.
Returns
*signalwire.PromptAction, error - The prompt action and any error.
Examples
Ask user to enter their PIN and collect the digits.
sendDigits
This method sends DTMF digits to the other party on the call. Allowed digits are 1234567890*#ABCD and wW for short and long waits. If any invalid characters are present, the entire operation is rejected.
Parameters
Returns
*signalwire.SendDigitsResult, error - The result of the send digits operation and any error.
Examples
Send some digits:
sendDigitsAsync
Asynchronous version of sendDigits. It does not wait for the sending event to complete, and immediately returns a SendDigitsAction object you can interact with.
Parameters
See sendDigits for the parameter list.
Returns
*signalwire.SendDigitsAction, error - The send digits action and any error.
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. SignalWire will send RTP or Websocket audio to the endpoint.
Parameters
TapDevice Properties
- To
tapthrough RTP:
- To
tapthrough WS (Websocket audio -wsorwssURI):
Returns
*signalwire.TapResult, error - The result of the tap operation and any error.
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 TapAction you can interact with.
Parameters
See tap for the parameter list.
Returns
*signalwire.TapAction, error - The tap action and any error.
Examples
Tapping audio from the call and then stop it using the TapAction object:
waitFor
Wait for specific events on the Call or returns false if the Call ends without getting them.
Parameters
Returns
bool - Whether the event was received before timeout.
Examples
Wait for ending event:
waitForAnswered
This is a helper function that refines the use of waitFor. This simplifies waiting for the answered state.
Parameters
Returns
bool - Whether the call was answered before timeout.
Examples
Wait for the answered event:
waitForEnded
This is a helper function that refines the use of waitFor. This simplifies waiting for the ended state.
Parameters
Returns
bool - Whether the call ended before timeout.
Examples
Wait for the ended event:
waitForEnding
This is a helper function that refines the use of waitFor. This simplifies waiting for the ending state.
Parameters
Returns
bool - Whether the call started ending before timeout.
Examples
Wait for the ending event:
waitForRinging
This is a helper function that refines the use of waitFor. This simplifies waiting for the ringing state.
Parameters
Returns
bool - Whether the call started ringing before timeout.
Examples
Wait for the ringing event:
Callbacks
All these callbacks can be used to track the calls lifecycle and instruct SignalWire on what to do for each different state.
State Callbacks
To track the state of a call.
Play Callbacks
To track a playback state.
Record Callbacks
To track a recording state.
Fax Callbacks
To track a fax state.
Detect Callbacks
To track a detector state.
Send Digits Events
To receive a message when the digits are finished sending.
Tap Events
To track an active tap.
Prompt Events
To track a prompt state.