SwitchX (SwitchX v1.0.1)

View Source

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

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

api(conn, args)

@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"}
}

auth(conn, password)

@spec 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"}

bg_api(conn, args)

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

close(conn)

@spec close(conn :: Pid) :: :ok | {:error, term()}

Closes the connection (conn) and stop the socket

execute(conn, uuid, application, args)

@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")

execute(conn, uuid, application, arg, event)

@spec execute(
  conn :: Pid,
  uuid :: String,
  application :: String,
  args :: String,
  event :: SwitchX.Event
) :: event :: SwitchX.Event

exit(conn)

@spec exit(conn :: Pid) :: :ok | {:error, term()}

Closes the socket connection.

hangup(conn, hangup_cause)

@spec hangup(conn :: Pid, cause :: String) :: :ok | {:error, term()}

Hang up the call with a hangup_cause.

hangup(conn, uuid, hangup_cause)

@spec hangup(conn :: Pid, uuid :: String, cause :: String) :: :ok | {:error, term()}

linger(conn)

@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"}

linger(conn, linger_time)

@spec linger(conn :: Pid, linger_time :: Integer) :: term()

listen_event(conn, event_name)

@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

multiset(conn, variables)

my_events(conn)

@spec my_events(conn :: Pid) :: :ok | {:error, term()}

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

my_events(conn, uuid)

@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

originate(conn, args)

originate(conn, args, bleg)

originate(conn, aleg, bleg, atom)

playback(conn, file)

playback(conn, file, uuid)

playback_async(conn, file)

playback_async(conn, file, uuid)

send_event(conn, event_name, event)

@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}

send_event(conn, event_name, event, event_uuid)

@spec send_event(
  conn :: Pid,
  event_name :: String,
  event :: SwitchX.Event,
  event_uuid :: String
) :: :ok | :error

send_message(conn, event)

@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}

send_message(conn, uuid, event)

@spec send_message(conn :: Pid, uuid :: String, event :: SwitchX.Event) ::
  {:ok, term()}