Home ›Support ›Knowledge-Base ›VocRT WebSocket Forwarding Guide

Forward a Local Number to a VocRT Voice Application

Connect an inbound DID to your voice application — such as an AI voice assistant — over a secure WebSocket (WSS). Each call opens its own WebSocket session carrying the call’s events and two-way audio.

Part 1: Set Up Forwarding

Point your number at your WebSocket endpoint.

1

Prepare your destination

Your application accepts one WebSocket connection per call. Set up a publicly reachable WSS endpoint with a valid TLS certificate. In your application, assign a destination ID to the assistant or workflow that should answer.

wss://voice.example.com/vocrt?destinationId=appointments

Replace the host and path with your own. Use destinationId exactly as shown, with a non-empty value such as appointments, and use it as the only query parameter. The address must start with wss://.

2

Set forwarding in the portal

Go to Inbound → Local Numbers and click the blue Call Forward arrow next to the DID. Under Call Type, select WebSocket, paste the full WSS URL into the destination field, and click Save. The rule applies to incoming calls to this DID.

3

Alternatively, configure the DID through the API

Open DID Forward Setting in the PBXme Postman collection. Keep the authentication and other fields from that request, and set the forwarding fields as shown below, substituting your own DID ID and endpoint.

{
  "action": "forward",
  "did_id": "1234",
  "call_type": "17",
  "call_type_value":
    "wss://voice.example.com/vocrt?destinationId=appointments"
}

did_id identifies the purchased number in PBXme. destinationId identifies the answering destination in your application. A successful API response confirms that the setting was saved. Place a test call to verify the connection.

Full request reference: PBXme API reference (Postman)

Part 2: Handle the WebSocket Session

Each connection carries the events and audio for one call.

4

Accept the connection and identify the call

Accept the WebSocket upgrade. Once the connection opens, PBXme sends the start event below. Read its customParameters to identify the destination and caller.

{
  "event": "start",
  "start": {
    "streamSid": "stream-example",
    "callSid": "call-example",
    "customParameters": {
      "destinationId": "appointments",
      "callerId": "+12025550124",
      "clientType": "external",
      "audioFormat": "pcm_8000"
    }
  }
}

Use callSid to correlate the phone call with your logs and streamSid to track its media. Select the assistant using destinationId. Treat callerId as optional and accept both local and international numbers.

5

Receive speech and send a reply

Exchange JSON text messages. Decode media.payload from Base64 to raw audio. In the pcm_8000 profile shown above, audio is signed 16-bit little-endian PCM, mono, at 8,000 Hz. A 20 ms frame contains 160 samples, or 320 bytes before Base64 — 50 frames per second. Match the returned audio to the announced profile.

The caller’s audio arrives on the inbound track. Send the assistant’s audio on the outbound track. The placeholders below represent Base64-encoded PCM samples.

{"event":"media","media":{"track":"inbound","payload":"<base64-pcm>"}}
{"event":"media","media":{"track":"outbound","payload":"<base64-pcm>"}}
6

Interrupt playback or end the call

To discard queued reply audio, stop sending the current reply and send clear. Audio already sent to the phone may still be heard.

{"event":"clear"}

When the caller hangs up, PBXme closes the WebSocket without a close reason (close code 1005). Treat any closure as the end of the call and release the session. Closing the socket from your application ends the call. VocRT doesn’t send DTMF (keypad) events, and this version defines no transfer command.

Part 3: Test an Incoming Call

Verify routing, audio in both directions and session cleanup.

7

Call the DID and listen in both directions

Log the incoming URL path, destinationId and callSid. Call from a phone, say a short phrase and confirm that your application receives the caller’s audio. Have the assistant answer and listen for its reply on the same phone. A simple check is to echo the inbound audio back on the outbound track: you should hear your own voice.

Troubleshooting

No connection reaches the server. Check call type 17, the full wss:// path, the certificate, and the spelling and value of destinationId. Confirm that your proxy forwards WebSocket upgrade requests.

The wrong assistant answers. Compare destinationId in the URL and in the start event with the mapping in your application.

Silence or distorted speech. Check the track direction, the sample rate and the raw PCM format after Base64 decoding. Send audio samples without a WAV header.

For assistance, send the DID, the time and time zone of the test, and the callSid if available.

Contact us at support@pbxme.com or WhatsApp +972 55-966-4944.

Sales, click to chat