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
amd
Alias for detect_answering_machine.
amd_async
Alias for detect_answering_machine_async.
answer
Answer an inbound call.
Parameters
None
Returns
coroutine - Coroutine that will return 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
Returns
coroutine - Coroutine that will return a Relay.Calling.ConnectResult object.
Examples
Trying to connect a call by calling in series +18991114444 and +18991114445:
Combine serial and parallel calling. Call +18991114443 first and - if it doesn’t answer - try calling in parallel +18991114444 and +18991114445. If none of the devices answer, continue the same process with +18991114446 and +18991114447:
connect_async
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
coroutine - Coroutine that will return a Relay.Calling.ConnectAction object.
Examples
Trying to connect a call by calling in series +18991114444 and +18991114445:
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 detect_answering_machine, detect_digit or detect_fax for more specific usage.
Parameters
- To detect an answering machine:
- To detect digits:
- To detect a fax:
Returns
coroutine - Coroutine that will return a Relay.Calling.DetectResult object.
Examples
Detect a machine with custom parameters and timeout:
Detect a Fax setting timeout only:
detect_async
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
coroutine - Coroutine that will return a Relay.Calling.DetectAction object.
Examples
Detect all the digits using default parameters. Stop the action after 5 seconds:
detect_answering_machine
This is a helper function that refines the use of detect. The coroutine will return a Relay.Calling.DetectResult object as soon as the detector decided who answered the call: MACHINE, HUMAN or UNKNOWN.
Parameters
Returns
coroutine - Coroutine that will return a Relay.Calling.DetectResult object.
Examples
Perform an AMD and wait until the machine is ready:
detect_answering_machine_async
Asynchronous version of detect_answering_machine. It does not wait the detector ends but returns a Relay.Calling.DetectAction you can interact with.
Parameters
See detect_answering_machine for the parameter list.
Returns
coroutine - Coroutine that will return a Relay.Calling.DetectAction object.
Examples
Perform an asynchronous AMD on the call. Then stop the action if not completed yet:
detect_digit
This is a helper function that refines the use of detect. This simplifies detecting digits on a call.
Parameters
Returns
coroutine - Coroutine that will return a Relay.Calling.DetectResult object.
Examples
Detect digits and then write a log with the result:
detect_digit_async
Asynchronous version of detect_digit. It does not wait the detector ends but returns a Relay.Calling.DetectAction you can interact with.
Parameters
See detect_digit for the parameter list.
Returns
coroutine - Coroutine that will return a Relay.Calling.DetectAction object.
Examples
Detect only 1-3 digits. Stop the action after 5 seconds:
detect_fax
This is a helper function that refines the use of detect. This simplifies detecting a fax.
Parameters
Returns
coroutine - Coroutine that will return a Relay.Calling.DetectResult object.
Examples
Detect fax on the current call:
detect_fax_async
Asynchronous version of detect_fax. It does not wait the detector ends but returns a Relay.Calling.DetectAction you can interact with.
Parameters
See detect_fax for the parameter list.
Returns
coroutine - Coroutine that will return a Relay.Calling.DetectAction object.
Examples
Detect fax on the current call. Stop the action after 5 seconds:
dial
This will start a call that was created with new_call and waits until the Call has been answered or hung up.
Parameters
None
Returns
coroutine - Coroutine that will return a Relay.Calling.DialResult object.
Examples
fax_receive
Prepare the call to receive an inbound fax. It waits until the fax has been received or failed.
Parameters
None
Returns
coroutine - Coroutine that will return a Relay.Calling.FaxResult object.
Examples
Receiving a fax on the call and grab URL and number of received pages from the FaxResult object:
fax_receive_async
Asynchronous version of fax_receive. It does not wait the fax to be received but returns a Relay.Calling.FaxAction you can interact with.
Parameters
None
Returns
coroutine - Coroutine that will return a Relay.Calling.FaxAction object.
Examples
Trying to receive a fax. Stop the attempt after 5 seconds:
fax_send
Send a Fax through the call. It waits until the fax has been sent or failed.
Parameters
Returns
coroutine - Coroutine that will return a Relay.Calling.FaxResult object.
Examples
Sending a fax on the call and grab URL and number of received pages from the FaxResult object:
fax_send_async
Asynchronous version of fax_send. It does not wait the fax to be sent but returns a Relay.Calling.FaxAction you can interact with.
Parameters
See fax_send for the parameter list.
Returns
coroutine - Coroutine that will return a Relay.Calling.FaxAction object.
Examples
Trying to send a fax. Stop sending it after 5 seconds:
hangup
Hangup the call.
Parameters
None
Returns
coroutine - Coroutine that will return a Relay.Calling.HangupResult object.
Examples
Hangup a call and check if it was successful:
on
Attach an event handler for the event.
Parameters
Returns
Relay.Calling.Call - The call object itself.
Examples
Subscribe to the answered events for a given call:
off
Remove an event handler that were attached with .on(). If you don’t pass a callback, all listeners for that event will be removed.
Parameters
Returns
Relay.Calling.Call - The call object itself.
Examples
Subscribe to the call ended state change and then, remove the event handler:
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 play_audio, play_silence or play_tts for more specific usage.
Parameters
- To play an audio file:
- To play a text to speech string:
- To play silence:
Returns
coroutine - Coroutine that will return a Relay.Calling.PlayResult object.
Examples
Play multiple media elements in the call:
play_async
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
coroutine - Coroutine that will return a Relay.Calling.PlayAction object.
Examples
Play multiple media elements in the call and stop them after 5 seconds:
play_audio
This is a helper function that refines the use of play. This simplifies playing an audio file.
Parameters
Returns
coroutine - Coroutine that will return a Relay.Calling.PlayResult object.
Examples
Play an Mp3 file:
play_audio_async
Asynchronous version of play_audio. It does not wait the playing to completes but returns a Relay.Calling.PlayAction you can interact with.
Parameters
See play_audio for the parameter list.
Returns
coroutine - Coroutine that will return a Relay.Calling.PlayAction object.
Examples
Play an Mp3 file and stop it after 5 seconds:
play_silence
This is a helper function that refines the use of play. This simplifies playing silence.
Parameters
Returns
coroutine - Coroutine that will return a Relay.Calling.PlayResult object.
Examples
Play silence for 10 seconds:
play_silence_async
Asynchronous version of play_silence. It does not wait the playing to completes but returns a Relay.Calling.PlayAction you can interact with.
Parameters
See play_silence for the parameter list.
Returns
coroutine - Coroutine that will return a Relay.Calling.PlayAction object.
Examples
Play silence for 60 seconds then stop it after 5 seconds:
play_ringtone
This is a helper function that refines the use of play. This simplifies playing TTS.
Parameters
Returns
coroutine - Coroutine that will return a Relay.Calling.PlayResult object.
Examples
Play a single US ringtone:
play_ringtone_async
Asynchronous version of play_ringtone. It does not wait the playing to completes but returns a Relay.Calling.PlayAction you can interact with.
Parameters
See play_ringtone for the parameter list.
Returns
coroutine - Coroutine that will return a Relay.Calling.PlayAction object.
Examples
Play the US ringtone for 30 seconds but stop it after 5 seconds:
play_tts
This is a helper function that refines the use of play. This simplifies playing TTS.
Parameters
Returns
coroutine - Coroutine that will return a Relay.Calling.PlayResult object.
Examples
Play TTS:
play_tts_async
Asynchronous version of play_tts. It does not wait the playing to completes but returns a Relay.Calling.PlayAction you can interact with.
Parameters
See play_tts for the parameter list.
Returns
coroutine - Coroutine that will return a Relay.Calling.PlayAction object.
Examples
Play TTS and stop it 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 prompt_audio, prompt_tts or prompt_ringtone for more specific usage.
Parameters
- To collect digits:
- To collect speech:
Returns
coroutine - Coroutine that will return a Relay.Calling.PromptResult object.
Examples
Ask user to enter their PIN and collect the digits:
prompt_async
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
coroutine - Coroutine that will return a Relay.Calling.PromptAction object.
Examples
Ask user to enter their PIN and collect the digits:
prompt_audio
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_list with:
The SDK will build the media_list for you.
Returns
coroutine - Coroutine that will return a Relay.Calling.PromptResult object.
Examples
Collect user’s digits while playing an Mp3 file:
prompt_audio_async
Asynchronous version of prompt_audio. It does not wait the collection to completes but returns a Relay.Calling.PromptAction you can interact with.
Parameters
See prompt_audio for the parameter list.
Returns
coroutine - Coroutine that will return a Relay.Calling.PromptAction object.
Examples
Ask user to enter their PIN and collect the digits:
prompt_ringtone
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_list with:
The SDK will build the media_list for you.
Returns
coroutine - Coroutine that will return a Relay.Calling.PromptResult object.
Examples
Play US ringtone for 30 seconds while collect digits:
prompt_ringtone_async
Asynchronous version of prompt_ringtone. It does not wait the collection to completes but returns a Relay.Calling.PromptAction you can interact with.
Parameters
See prompt_ringtone for the parameter list.
Returns
coroutine - Coroutine that will return a Relay.Calling.PromptAction object.
Examples
Play US ringtone for 30 seconds while collect digits in asynchronous:
prompt_tts
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_list with:
The SDK will build the media_list for you.
Returns
coroutine - Coroutine that will return a Relay.Calling.PromptResult object.
Examples
Ask user to enter their PIN and collect the digits:
prompt_tts_async
Asynchronous version of prompt_tts. It does not wait the collection to completes but returns a Relay.Calling.PromptAction you can interact with.
Parameters
See prompt_tts for the parameter list.
Returns
coroutine - Coroutine that will return a Relay.Calling.PromptAction object.
Examples
Ask user to enter their PIN and collect the digits:
record
Start recording the call and waits until the recording ends or fails.
Parameters
Returns
coroutine - Coroutine that will return a Relay.Calling.RecordResult object.
Examples
Start recording audio in the call for both direction in stereo mode, if successful, grab url, duration and size from the RecordResult object:
record_async
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
coroutine - Coroutine that will return a Relay.Calling.RecordAction object.
Examples
Start recording audio in the call for both direction in stereo mode and stop it after 5 seconds:
send_digits
This method sends DTMF digits to the other party on the call.
Parameters
Returns
coroutine - Coroutine that will return a Relay.Calling.SendDigitsResult object.
Examples
Send some digits:
send_digits_async
Asynchronous version of send_digits. It does not wait for the sending event to complete, and immediately returns a Relay.Calling.SendDigitsAction object you can interact with.
Parameters
See send_digits for the parameter list.
Returns
coroutine - Coroutine that will return a Relay.Calling.SendDigitsAction
Examples
Send some digits and stop the operation after 3 seconds:
tap
Intercept call media and stream it to the specify endpoint. It waits until the end of the call.
Parameters
- To
tapthrough RTP:
Returns
coroutine - Coroutine that will return a Relay.Calling.TapResult object.
Examples
Tapping audio from the call, if successful, print both source and destination devices from the TapResult object:
tap_async
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
coroutine - Coroutine that will return a Relay.Calling.TapAction object.
Examples
Tapping audio from the call and then stop it using the TapAction object:
wait_for
Wait for specific events on the Call or returns false if the Call ends without getting them.
Parameters
Returns
coroutine - Coroutine object that will be resolved with true or false.
Examples
Wait for ending or ended events:
wait_for_answered
This is a helper function that refines the use of wait_for. This simplifies waiting for the answered state.
Parameters
None
Returns
coroutine - Coroutine that will return true or false.
Examples
Wait for the answered event:
wait_for_ended
This is a helper function that refines the use of wait_for. This simplifies waiting for the ended state.
Parameters
None
Returns
coroutine - Coroutine that will return true or false.
Examples
Wait for the ended event:
wait_for_ending
This is a helper function that refines the use of wait_for. This simplifies waiting for the ending state.
Parameters
None
Returns
coroutine - Coroutine that will return true or false.
Examples
Wait for the ending event:
wait_for_ringing
This is a helper function that refines the use of wait_for. This simplifies waiting for the ringing state.
Parameters
None
Returns
coroutine - Coroutine that will return true or false.
Examples
Wait for ending or ended events:
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.
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: