Build a complex hence powerful FreeSWITCH IVR in Erlang

FreeSWITCH is powerful, which has cool and awesome applications built in that allows you do almost anything you want. We had built our call center using a combination of dialplan and event_socket. As the logic goes more complex, we decided to re-implement in Erlang.

What is Erlang?

Why Erlang?

Erlang is cocurrent, Erlang is functional, and more important, Erlang is designed to program telecom applications.

Erlang has otp, it is very easy to program Finite State Machine with gen_fsm.

How?

We are running our PBX server in office while it need to fetch data from a very far remote server(could be in a remote datacenter or even in another country) to decide where an incoming call should be distributed to.

FreeSWITCH has mod_http and mod_curl built in, but we think Erlang is more robust when a remote server stops responding which will definitely happen on the world wide Internet. And we can get other advantage from Erlang. We spawn a new process to fetch data from a remote HTTP server immediately when a call comes in without even touching the call flow, and when we need the data for decision, the data already there, therefore no delay for customers.

In addition, we also post call related data to remote servers. We have time conditions stored in local mysql DB, and regular time conditions built in.

We use outbound mode in mod_erlang_event, whenever a call comes in, we send to a Erlang node imediately from dialplan:

Other discussion

1) Erlang is completely async, so you have to wait for the channel_execute_complete event to decide if an application(for example playback and bridge) is done before you send other messages which is not as convenient as in dialplan or Lua and other languages. Or you could do a timer:sleep() treak on playback if you know the length of the recording.

2) We transfer to XML dialplan as soon as we don't need erlang features, edit XML is easier in some sense.

3) mod_fifo doesn't work well in Erlang unless you transfer to orbit extensions since the channel is parked(controlled in erlang) and when fifo bridge to an extension their are no sound, I didn't find a way to unpark a channel, let me know if I'm wrong.

4) Code is kind of clear, however, it would be nicer to make a gen_fs_fsm behavior to wrap all the FreeSWITCH message processes :).