Note: this page describes how to build applications using websockets. If you prefer to use the webhooks API, please visit this page.
TLDR;
npx create-jambonz-ws-app to scaffold a webhook applicationThe websocket API is functionally equivalent to the Webhook API; it is simply an alternative way for an application to interact with and drive jambonz call and message processing. We recommend using the websocket API for highly asynchronous applications.
When you create a jambonz application in the jambonz portal and you want to use the websocket API, simply provide a ws(s) URL for the calling webhook instead of an http(s) URL. The call status webhook can be the same ws(s) URL, in which case your application will get the call status notifications over the same websocket connections.
You can also have call status notifications sent to a completely separate http(s) webhook URL if you prefer.
The impact of specifying a ws(s) URL as the application calling webhook is that this causes jambonz to establish a websocket connection to that URL when an incoming call (or outbound call) is routed to the jambonz application, and then communicate with your application over that websocket connection.
In the documentation below, we refer to the websocket server as the “application”.
The websocket connection will be established by jambonz to the specified websocket URL, The websocket subprotocol used shall be “ws.jambonz.org”. If jambonz fails to connect to the provided URL, there will be no retry and the call shall be rejected.
Once connected, jambonz will send an initial JSON text message to the your application with the same parameters as are provided in the webhook call. The full message set is described below, but for now we can simply say that:
The websocket should generally be closed only from the jambonz side, which happens when the call is ended. If the your application closes the socket, jambonz will attempt to reconnect, up to a configurable number of reconnection attempts. Upon reconnecting, jambonz will send an initial reconnect message containing only the callSid of the session. It is up to the your application to maintain the state of the application between reconnections for the same call.
As mentioned above, all messages will be JSON payloads sent as text frames. The following top-level properties will be commonly included:
session:new, session:reconnect, verb:hook, call:status, error].ack, command].ack) must include the msgId that they are acknowledging.Note that not all messages sent by jambonz need to be acknowledged. The message types which must be acknowledged are the session:new, and verb:hook messages.
In the sections that follow, we will describe each of the message types in detail. The tables below provides summary information for:
The following messages are sent by jambonz to your application
The following messages can be sent from your application back to jambonz