SwitchX (SwitchX v1.0.1)
View SourceSummary
Functions
Send a FreeSWITCH API command.
Reply the auth/request package from FreeSWITCH.
Send a FreeSWITCH API command, non-blocking mode. This will let you execute a job in the background, and the result will be sent as an BACKGROUND_JOB event with an indicated UUID to match the reply to the command.
Closes the connection (conn) and stop the socket
execute is used to invoke dialplan applications,
Closes the socket connection.
Hang up the call with a hangup_cause.
Tells FreeSWITCH not to close the socket connection when a channel hangs up. Instead, it keeps the socket connection open until the last event related to the channel has been received by the socket client.
Enable or disable events by class or all.
The 'myevents' subscription allows your socket to receive all related events from a outbound socket session
The 'myevents' subscription allows your inbound socket connection to behave like an outbound socket connect. It will "lock on" to the events for a particular uuid and will ignore all other events
Send an event into the event system (multi line input for headers).
sendmsg is used to control the behavior of FreeSWITCH. UUID is mandatory when conn is inbound mode, and it refers to a specific call (i.e., a channel or call leg or session).
Functions
@spec api(conn :: Pid, args :: String) :: {:ok, term()}
Send a FreeSWITCH API command.
Returns
{:ok, term}
Examples
iex> SwitchX.api(
conn,
"uuid_getvar a1024ff5-a5b3-4c0a-abd3-fd4a89508b5b current_application"
)
%SwitchX.Event{
body: "park",
headers: %{"Content-Length" => "4", "Content-Type" => "api/response"}
}
Reply the auth/request package from FreeSWITCH.
Returns
{:ok, "Accepted"} | {:error, "Denied"}
Examples
iex> SwitchX.auth(conn, "ClueCon")
{:ok, "Accepted"}
iex> SwitchX.auth(conn, "Incorrect")
{:error, "Denied"}
@spec bg_api(conn :: Pid, args :: String.Chars) :: {:ok, event :: SwitchX.Event}
Send a FreeSWITCH API command, non-blocking mode. This will let you execute a job in the background, and the result will be sent as an BACKGROUND_JOB event with an indicated UUID to match the reply to the command.
@spec close(conn :: Pid) :: :ok | {:error, term()}
Closes the connection (conn) and stop the socket
@spec execute(conn :: Pid, uuid :: String, application :: String, args :: String) ::
event :: SwitchX.Event
execute is used to invoke dialplan applications,
Examples
iex> SwitchX.execute(conn, uuid, "playback", "ivr/ivr-welcome_to_freeswitch.wav")
@spec execute(
conn :: Pid,
uuid :: String,
application :: String,
args :: String,
event :: SwitchX.Event
) :: event :: SwitchX.Event
@spec exit(conn :: Pid) :: :ok | {:error, term()}
Closes the socket connection.
@spec hangup(conn :: Pid, cause :: String) :: :ok | {:error, term()}
Hang up the call with a hangup_cause.
@spec hangup(conn :: Pid, uuid :: String, cause :: String) :: :ok | {:error, term()}
@spec linger(conn :: Pid) :: term()
Tells FreeSWITCH not to close the socket connection when a channel hangs up. Instead, it keeps the socket connection open until the last event related to the channel has been received by the socket client.
Returns
{:ok, "Lingering"}
Examples
iex> SwitchX.linger(context.conn)
{:ok, "Lingering"}
@spec linger(conn :: Pid, linger_time :: Integer) :: term()
@spec listen_event(conn :: Pid, event_name :: String) :: :ok
Enable or disable events by class or all.
Returns
:ok
Examples
iex> SwitchX.listen_event(conn, "BACKGROUND_JOB")
:ok
@spec my_events(conn :: Pid) :: :ok | {:error, term()}
The 'myevents' subscription allows your socket to receive all related events from a outbound socket session
@spec my_events(conn :: Pid, uuid :: String) :: :ok | {:error, term()}
The 'myevents' subscription allows your inbound socket connection to behave like an outbound socket connect. It will "lock on" to the events for a particular uuid and will ignore all other events
@spec send_event(conn :: Pid, event_name :: String, event :: SwitchX.Event) :: {:ok, term()}
Send an event into the event system (multi line input for headers).
sendevent <event-name>
<headers>
<body>
Returns
{:ok, term}
Examples
iex> event_headers =
SwitchX.Event.Headers.new(%{
"profile": "external",
})
event = SwitchX.Event.new(event_headers, "")
SwitchX.send_event(conn, "SEND_INFO", event)
{:ok, response}
@spec send_event(
conn :: Pid,
event_name :: String,
event :: SwitchX.Event,
event_uuid :: String
) :: :ok | :error
@spec send_message(conn :: Pid, event :: SwitchX.Event) :: {:ok, term()}
sendmsg is used to control the behavior of FreeSWITCH. UUID is mandatory when conn is inbound mode, and it refers to a specific call (i.e., a channel or call leg or session).
Returns a payload with an command/reply event
Examples
iex> message = SwitchX.Event.Headers.new(%{
"call-command": "hangup",
"hangup-cause": "NORMAL_CLEARING",
}) |> SwitchX.Event.new()
SwitchX.send_message(conn, uuid, message)
{:ok, event}
@spec send_message(conn :: Pid, uuid :: String, event :: SwitchX.Event) :: {:ok, term()}