SwitchX v0.1.8 SwitchX View Source

Link to this section Summary

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).

sendevent <event-name>
<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)

Link to this section Functions

Link to this function api(conn, args) View Source
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"}
}
Link to this function auth(conn, password) View Source
auth(conn :: Pid, password :: String) :: {:ok, term()} | {:error, term()}

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"}
Link to this function bg_api(conn, args) View Source
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.

Link to this function close(conn) View Source
close(conn :: Pid) :: :ok | {:error, term()}

Closes the connection (conn) and stop the socket

Link to this function execute(conn, uuid, application, args) View Source
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")
Link to this function execute(conn, uuid, application, arg, event) View Source
execute(
  conn :: Pid,
  uuid :: String,
  application :: String,
  args :: String,
  event :: SwitchX.Event
) :: event :: SwitchX.Event
Link to this function exit(conn) View Source
exit(conn :: Pid) :: :ok | {:error, term()}

Closes the socket connection.

Link to this function hangup(conn, hangup_cause) View Source
hangup(conn :: Pid, cause :: String) :: :ok | {:error, term()}

Hang up the call with a hangup_cause.

Link to this function hangup(conn, uuid, hangup_cause) View Source
hangup(conn :: Pid, uuid :: String, cause :: String) :: :ok | {:error, term()}
Link to this function linger(conn) View Source
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"}
Link to this function listen_event(conn, event_name) View Source
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
Link to this function multiset(conn, variables) View Source
Link to this function my_events(conn) View Source
my_events(conn :: Pid) :: :ok | {:error, term()}

The ‘myevents’ subscription allows your socket to receive all related events from a outbound socket session

Link to this function my_events(conn, uuid) View Source
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

Link to this function originate(conn, args, bleg) View Source
Link to this function originate(conn, aleg, bleg, atom) View Source
Link to this function playback(conn, file, uuid) View Source
Link to this function playback_async(conn, file) View Source
Link to this function playback_async(conn, file, uuid) View Source
Link to this function send_event(conn, event_name, event) View Source
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}
Link to this function send_event(conn, event_name, event, event_uuid) View Source
send_event(
  conn :: Pid,
  event_name :: String,
  event :: SwitchX.Event,
  event_uuid :: String
) :: :ok | :error
Link to this function send_message(conn, event) View Source
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}
Link to this function send_message(conn, uuid, event) View Source
send_message(conn :: Pid, uuid :: String, event :: SwitchX.Event) ::
  {:ok, term()}