Methods overview
Methods in SWML control the program flow and execute functions. This includes setting and unsetting variables, conditional statements, making calls, and sending faxes etc.
The AI
method
The ai
method is an incredibly powerful tool to instantiate an AI agent
that holds a natural conversation with the caller, and perform actions based on their input.
Control-flow methods
execute
and return
The execute
method is similar to a function call in most languages. It can be sent parameters,
and it can return values using the return
object. The SWML function to be executed can
exist as a subsection in the same SWML document, but it can also be a separate SWML document hosted on
an internet-accessible web-server.
transfer
The transfer
statement transfers the execution to a different section or
a different SWML document. Unlike the execute
statement, the transfer
statement doesn't return
back to the calling section.
goto
and label
The goto
statement can jump to a specified label
either depending on a
given condition or unconditionally, and repeatedly for a specified number of repetitions.
cond
and switch
The cond
statement is a general purpose conditional branching statement that
executes SWML code based on the evaluation of a JavaScript expression.
The switch
statement allows switch-case like conditional execution depending on whether a certain variable is
a certain value.
Call related methods
answer
and hangup
Use these methods to decide when to answer
the call
and when to hangup
. Some other methods (like play
)
will automatically answer calls, but you can use these methods to be more
specific about when it happens.
denoise
and stop_denoise
The denoise
method starts the noise reduction filter and the
stop_denoise
method stops it.
live_transcribe
The live_transcribe
method starts a live transcription of the call.
live_translate
The live_translate
method starts a live translation of the call.
play
and prompt
The play
method can be used to send TTS speech, play audio files, send different rings etc.
The prompt
method also plays TTS or URLs like play
but it can receive
keypad or speech input in response.
connect
Use the connect
method to connect the caller to other phone or SIP calls.
You can set it up to dial multiple numbers in series, parallel or a combination of the two.
join_room
The join_room
method seamlessly connects your call to a
video room, enabling participants to
join from various sources, including mobile apps, web browsers, or phone calls.
receive_fax
The receive_fax
method will interpret the call as a fax and process it.
record
, record_call
and stop_record_call
The record
and the record_call
methods will record
the call. The record
method, however, waits for the recording to terminate before continuing
execution. The record_call
method starts a call recording in the
background, and it stops recording when you call stop_record_call
.
tap
and stop_tap
The tap
method starts streaming the call to an RTP or a web socket sink.
The stop_tap
method stops it.
sip_refer
The sip_refer
method transfer a SIP call by sending a SIP REFER
message.
send_sms
Use send_sms
to send an SMS to a phone number.
send_digits
Use send_digits
to send digits as DTMF tones.