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.
Parameters
None
Returns
Relay::Calling::AnswerResult - The result object to interact with.
Examples
Answer an inbound call and check if it was successful.
connect
Attempts 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.
You can connect to multiple devices in series, parallel, or any combination of both. Series means one device is dialed at a time, while parallel implies multiple devices ring at the same time.
Parameters
To dial a phone number:
Returns
Relay::Calling::ConnectResult - The result object to interact with.
Examples
Trying to connect a call by calling +18991114444 and +18991115555 in series.
Trying to connect a call by calling +18991114444 and +18991115555 in series, playing the US ringtone.
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!
Asynchronous version of connect. It does not wait for the connect to complete or fail, and it immediately returns a ConnectAction object you can interact with.
Parameters
See connect for the parameter list.
Returns
Relay::Calling::ConnectAction - The action object to interact with.
Examples
Trying to connect a call by calling in series +18991114444 and +18991114445.
detect
Starts 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_digit, detect_fax, detect_human or detect_machine for more specific usage.
Parameters
When type is machine:
When type is fax:
When type is digits:
Returns
Relay::Calling::DetectResult - The result object to interact with.
Examples
Detect with custom parameters and timeout.
Detect a Fax setting timeout only.
detect!
Asynchronous version of detect. It does not wait for the detector to stop, and returns a DetectAction object you can interact with.
Parameters
See detect for the parameter list.
Returns
Relay::Calling::DetectAction - The action object to interact with.
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. It is used to detect a machine, and is intended to replace the deprecated methods.
Parameters
Returns
Relay::Calling::DetectResult - The result object to interact with.
Examples
Detect a machine and log the result.
detect_answering_machine!
Asynchronous version of detect_answering_machine. It does not wait the detector ends but returns a DetectAction object you can interact with.
Parameters
See detect_answering_machine for the parameter list.
Returns
Relay::Calling::DetectAction - The action object to interact with.
Examples
Detect a machine. Stop the action after 5 seconds.
amd
Alias of detect_answering_machine.
Parameters
See detect_answering_machine for the parameter list.
Returns
Relay::Calling::DetectResult - The result object to interact with.
amd!
Alias of the asynchronous detect_answering_machine! method.
Parameters
See detect_answering_machine for the parameter list.
Returns
Relay::Calling::DetectAction - The action object to interact with.
detect_digit
This is a helper function that refines the use of detect. This simplifies detecting digits on a call.
Parameters
Returns
Relay::Calling::DetectResult - The result object to interact with.
Examples
Detect digits and then write a log with the result.
detect_digit!
Asynchronous version of detect_digit. It does not wait the detector ends but returns a DetectAction object you can interact with.
Parameters
See detect_digit for the parameter list.
Returns
Relay::Calling::DetectAction - The action object to interact with.
Examples
Detect 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
Relay::Calling::DetectResult - The result object to interact with.
Examples
Detect fax on the current call.
detect_fax!
Asynchronous version of detect_fax. It does not wait for the detector to end, and returns a DetectAction object you can interact with.
Parameters
See detect_fax for the parameter list.
Returns
Relay::Calling::DetectAction - The action object to interact with.
Examples
Detect fax on the current call. Stop the action after 5 seconds.
detect_human
This is a helper function that refines the use of detect. This simplifies detecting a human on the call and is the inverse of detect_machine.
This method is DEPRECATED and will be removed in version 3.0
Parameters
Returns
Relay::Calling::DetectResult - The result object to interact with.
Examples
Detect a human on the current call.
detect_human!
Asynchronous version of detect_human. It does not wait for the detector to end, and returns a DetectAction object you can interact with.
This method is DEPRECATED and will be removed in version 3.0
Parameters
See detect_human for the parameter list.
Returns
Relay::Calling::DetectAction - The action object to interact with.
Examples
Detect a human on the current call. Stop the action after 5 seconds.
detect_machine
This is a helper function that refines the use of detect. This simplifies detecting a machine on the call and is the inverse of detect_human.
This method is DEPRECATED and will be removed in version 3.0
Parameters
Returns
Relay::Calling::DetectResult - The result object to interact with.
Examples
Detect a machine on the current call.
detect_machine!
Asynchronous version of detect_machine. It does not wait for the detector, and returns a DetectAction object you can interact with.
This method is DEPRECATED and will be removed in version 3.0
Parameters
See detect_machine for the parameter list.
Returns
Relay::Calling::DetectAction - The action object to interact with.
Examples
Detect a machine on the current call. Stop the action after 5 seconds.
dial
This will start a call that was created with new_call and wait until the call has been answered or hung up.
Parameters
None
Returns
Relay::Calling::DialResult - The result object to interact with.
Examples
fax_receive
Prepare the call to receive an inbound Fax. It waits until the fax has been received or failed.
Parameters
None
Returns
Relay::Calling::FaxResult - The result object to interact with.
Examples
Receiving a fax on the call and print logs for URL and number of received pages.
fax_receive!
Asynchronous version of fax_receive. It does not block until the fax is received, it immediately returns a FaxAction object you can interact with.
Parameters
None
Returns
Relay::Calling::FaxAction - The action object to interact with.
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
Relay::Calling::FaxResult - The result object to interact with.
Examples
Sending a fax on the call and print logs the number of sent pages.
fax_send!
Asynchronous version of fax_send. It does not block until the fax is finished sending, it immediately returns a FaxAction object you can interact with.
Parameters
See fax_send for the parameter list.
Returns
Relay.Calling.FaxAction - The action object to interact with.
Examples
Trying to send a fax. Stop sending it after 5 seconds.
hangup
Hangup the call.
Parameters
None
Returns
Relay::Calling::HangupResult - The result object to interact with.
Examples
Hangup a call and check if it was successful.
on
Attach an event handler for various events.
Parameters
Returns
Relay::Calling::Call - The call object itself.
Examples
Subscribe to the answered and ended events for a given call.
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, play_tts or play_ringtone for more specific usage.
Parameters
To play an audio file:
To play a text to speech string:
To play silence:
To play a ringtone:
Returns
Relay::Calling::PlayResult - The result object to interact with.
Examples
Play multiple media elements in the call.
play!
Asynchronous version of play. It does not wait for the playing event to complete, it immediately returns a PlayAction object you can interact with.
Parameters
See play for the parameter list.
Returns
Relay::Calling::PlayAction - The action object to interact with.
Examples
Play multiple media elements in the call and stop them after 2 seconds.
play_audio
This is a helper function that refines the use of play. This simplifies playing an audio file.
Parameters
Returns
Relay::Calling::PlayResult - The result object to interact with.
Examples
Play an MP3 file.
play_audio!
Asynchronous version of play_audio. It does not wait for the playing event to complete, and immediately returns a PlayAction object you can interact with.
Parameters
See play_audio for the parameter list.
Returns
Relay::Calling::PlayAction - The action object to interact with.
Examples
Play an MP3 file and stop it after 2 seconds.
play_ringtone
This is a helper function that refines the use of play. This simplifies playing a ringtone.
Parameters
Returns
Relay::Calling::PlayResult - The result object to interact with.
Examples
Play a single US ringtone.
play_ringtone!
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
Relay::Calling::PlayAction - The action object to interact with.
Examples
Play US ringtone for 30 seconds 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
Relay::Calling::PlayResult - The result object to interact with.
Examples
Play silence for 10 seconds.
play_silence!
Asynchronous version of play_silence. It does not wait for the playing event to complete, it immediately returns a PlayAction object you can interact with.
Parameters
See play_silence for the parameter list.
Returns
Relay::Calling::PlayAction - The action object to interact with.
Examples
Play silence for 60 seconds, if Agent becomes available, stop the play.
play_tts
This is a helper function that refines the use of play. This simplifies playing text to speech strings.
Parameters
Returns
Relay::Calling::PlayResult - The result object to interact with.
Examples
Play text to string.
play_tts!
Asynchronous version of play_tts. It does not wait for the playing event to complete, it immediately returns a PlayAction object you can interact with.
Parameters
See play_tts for the parameter list.
Returns
Relay::Calling::PlayAction - The action object to interact with.
Examples
Play TTS and stop it after 2 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 succeeds or a timeout is reached.
The prompt method is a generic method, see prompt_audio or prompt_tts for more specific usage.
Passing any of the digits_ or speech_ arguments will activate the respective detector.
Parameters
Returns
Relay::Calling::PromptResult - The result object to interact with.
Examples
Ask user to enter their PIN and collect the digits.
prompt!
Asynchronous version of prompt. It does not wait for the collect action to complete, it immediately returns a PromptAction object you can interact with.
Parameters
See prompt for the parameter list.
Returns
Relay::Calling::PromptAction - The action object to interact with.
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
See prompt for the parameter list, plus:
Returns
Relay::Calling::PromptResult - The result object to interact with.
Examples
Collect user’s digits while playing an MP3 file, setting its volume to 20.
prompt_audio!
Asynchronous version of prompt_audio. It does not wait for the collect action to complete, it immediately returns a PromptAction object you can interact with.
Parameters
See prompt_audio for the parameter list.
Returns
Relay::Calling::PromptAction - The action object to interact with.
Examples
Ask user to enter their PIN and collect the digits.
prompt_silence
This is a helper function that refines the use of prompt. This function simplifies collecting user’s input from the call, such as digits and speech, while not playing any audio.
Parameters
See prompt for the parameter list, plus:
Returns
Relay::Calling::PromptResult - The result object to interact with.
Examples
Collect user’s digits while playing 5 seconds of silence.
prompt_silence!
Asynchronous version of prompt_silence. It does not wait for the collect action to complete, it immediately returns a PromptAction object you can interact with.
Parameters
See prompt_silence for the parameter list.
Returns
Relay::Calling::PromptAction - The action object to interact with.
Examples
Collect user’s digits while playing 5 seconds of silence.
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
See prompt for the parameter list, plus:
Returns
Relay::Calling::PromptResult - The result object to interact with.
Examples
Play US ringtone for 30 seconds while collecting digits.
prompt_ringtone!
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
Relay::Calling::PromptAction - The action object to interact with.
Examples
Play US ringtone for 30 seconds while collecting digits in asynchronous mode.
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
See prompt for the parameter list, plus:
Returns
Relay::Calling::PromptResult - The result object to interact with.
Examples
Ask user to enter their PIN and collect the digits.
prompt_tts!
Asynchronous version of prompt_tts. It does not wait for the collection event to complete, it immediately returns a PromptAction object you can interact with.
Parameters
See prompt_tts for the parameter list.
Returns
Relay::Calling::PromptAction - The action object to interact with.
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
Relay::Calling::RecordResult - The result object to interact with.
Examples
Start recording audio in the call for both direction in stereo mode, if successful, print the url from the RecordResult object.
record!
Asynchronous version of record. It does not wait for the end of the recording, it immediately returns a RecordAction object you can interact with.
Parameters
See record for the parameter list.
Returns
Relay::Calling::RecordAction - The action object to interact with.
Examples
Start recording audio in the call for both direction in stereo mode and stop it after 2 seconds.
send_digits
This method sends DTMF digits to the other party on the call.
Parameters
Returns
Relay::Calling::SendDigitsResult - The result object to interact with.
Examples
Send some digits.
send_digits!
Asynchronous version of send_digits. It does not wait for the sending event to complete, and immediately returns a SendDigitsAction object you can interact with.
Parameters
See send_digits for the parameter list.
Returns
Relay::Calling::SendDigitsAction - The action object to interact with.
Examples
Send some digits.
tap_media
Intercept call media and stream it to the specified endpoint. It waits until the end of the call.
This method is named tap_media instead of tap in the Ruby SDK because of a reserved method.
Parameters
Returns
Relay::Calling::TapResult - The result object to interact with.
Examples
Tapping audio from the call, if successful, print both source and destination devices from the TapResult object.
Tapping audio into a WSS endpoint, if successful, print both source and destination devices from the TapResult object.
tap_media!
Asynchronous version of tap_media. It does not wait the end of tapping but returns a TapAction object you can interact with.
Parameters
See tap_media for the parameter list.
Returns
Relay::Calling::TapAction - The action object to interact with.
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 one.
Parameters
Returns
Boolean - true/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
Boolean - true/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
Boolean - true/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
Boolean - true/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
Boolean - true/false.
Examples
Wait for the ringing event.
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.
Ringtones
Here you can find all the accepted values for playing a ringtone, based on short country codes: