FreeSWITCH Event Socket (ESL) Guide: Inbound vs Outbound Mode
The Event Socket Library (ESL) lets your own application connect to FreeSWITCH over TCP to receive call events and issue commands, which is how most custom call-control logic is built. It turns FreeSWITCH into a programmable media engine controlled from Python, Node.js, Go, or any language that can speak the protocol.
Two Modes
Inbound mode. Your application connects to FreeSWITCH (default port 8021, with a password). You subscribe to events and send API or sendmsg commands, typically for originating calls and monitoring everything on the system. Good for dialers, dashboards, and click-to-call.
Outbound mode. The dial plan uses the socket application to connect to your server for a specific call. Your application then controls that one channel from start to finish. Good for IVRs, per-call logic, and AI voice agent bridges.
| Inbound | Outbound | |
|---|---|---|
| Connection | App connects to FreeSWITCH | FreeSWITCH connects to app for each call |
| Scope | System-wide events and commands | One call at a time |
| Typical use | Originate calls, monitor events | IVR flow, per-call application |
| Scaling | One long-lived connection per node | One connection per active call |
Common Commands
originateto create a calluuid_bridge,uuid_transfer,uuid_killto manipulate existing channelsplayback,record,say,play_and_get_digitsthrough dial plan applicationsevent plain ALLor specific events to subscribe to
Useful Events
CHANNEL_CREATE, CHANNEL_ANSWER, CHANNEL_HANGUP_COMPLETE (with variables that feed CDRs, see CDR explained), DTMF, CUSTOM sofia::register for registration tracking, and HEARTBEAT for node health.
Design Patterns That Hold Up
- Never block the event loop. Do database and HTTP work asynchronously or on workers.
- Reconnect automatically and resubscribe. Connections will drop.
- Handle every channel's full lifecycle, including unexpected hangups mid-operation.
- Correlate with a UUID or custom variable so logs, CDRs, and signaling traces tell one story.
- Limit blast radius. One bad call handler must not crash the node's controller.
- Secure port 8021. Bind to localhost or a private network, with a strong password (see FreeSWITCH hardening).
Where It Fits
- Dialers: originate through ESL with pacing (see predictive dialer architecture)
- Contact centers and queues (see mod_callcenter)
- AI voice agents: stream audio out and drive the call from a bot (see LLM function calling for phone agents)
- Provisioning plus dynamic config (see mod_xml_curl)
Choosing ESL vs Scripts
Embedded scripts (Lua) avoid network hops and suit simple, high-volume logic. ESL suits complex applications with their own state, deployment, and language preferences.
Need custom call-control applications on FreeSWITCH? Our FreeSWITCH development team builds ESL-based services for IVR, dialing, and voice AI.
Related Services
FreeSWITCH Development
Carrier-grade media servers, IVR, and call center logic built on FreeSWITCH.
Call Center SIP Engineering
High-concurrency SIP trunking, queues, dialers, and contact center infrastructure.
AI Voice Agent Development
Low-latency voice agents connected to real telephony and your business systems.
Keep Reading
Discussion
0Join the conversation
Sign in with your preferred account to comment, reply, and keep the discussion useful for other engineers.
Takes a few seconds. No separate password required.
Controva LLC
Engineering Team
We build digital empires that scale. Specializing in high-performance web architecture, AI automation, and headless commerce.
Work with us