Skip to content

AI Provider

Config

This section defines how to configure the AI Provider connection, including media parameters and WebSocket connection details.

Fields

  • name (string): Display name of the AI Provider.
  • media (object): Specifies the audio encoding and sample rate.
  • websocket (object): Defines the WebSocket endpoint and optional headers used for authentication or custom configuration.

media object

  • audioFormat (string): Supported formats are:
  • "pcm16" — sample rate 24000 Hz
  • "g711_ulaw" — sample rate 8000 Hz
  • "opus" — sample rate 48000 Hz
  • sampleRate (number): Must match the selected audio format.

websocket object

  • url (string): Secure WebSocket URL used to connect to the AI Provider. Example: wss://cad.fonouc.com:9443/ws/v1/echo
  • headers (object, optional): Key–value pairs of headers to include in the connection request. Commonly used for authorization tokens or custom metadata.

Events API

This section defines the event types exchanged over the WebSocket connection between the AI Provider and the backend. Each message is a JSON object containing an "event" field that specifies its type.


Event: start

Sent once at the beginning of the WebSocket session to initialize the call context.

Fields

  • event (string): Must be "start".
  • start (object): Contains call initialization data.

start object

  • callId (string): Unique identifier of the call.
  • otherLegCallId (string): Unique identifier of the other leg of the call.
  • callerIdNumber (string): E.164-formatted phone number of the caller.
  • calleeIdNumber (string): E.164-formatted phone number of the callee.
  • accountId (string): Account associated with the call.
  • mediaFormat (object): Defines the audio encoding and sample rate used for the call.

mediaFormat object

  • encoding (string): Audio encoding format. Supported values are:
  • "pcm16" — sample rate 24000 Hz
  • "g711_ulaw" — sample rate 8000 Hz
  • "opus" — sample rate 48000 Hz
  • sampleRate (number): Must match the selected encoding (24000 for pcm16, 8000 for g711_ulaw, 48000 for opus).

Example

{
  "event": "start",
  "start": {
    "callId": "call_12345",
    "otherLegCallId": "call_67890",
    "callerIdNumber": "+1234567890",
    "calleeIdNumber": "+1234567891",
    "accountId": "acc_abc123",
    "mediaFormat": {
      "encoding": "pcm16",
      "sampleRate": 24000
    }
  }
}

Event: media

Carries audio data between the backend and the AI Provider. Multiple messages of this type are exchanged during the call.

Fields

  • event (string): Must be "media".
  • media (object): Contains the encoded audio payload.

media object

  • payload (string): Base64-encoded audio data.

Example

{
  "event": "media",
  "media": {
    "payload": "GkXfo59ChoEBQveBAULygQRC84EIQoKEd2VibUKHgQCh..."
  }
}

Event: dtmf

Sent when the caller presses a key on their phone keypad during the call. DTMF (Dual-Tone Multi-Frequency) tones are used for interactive voice response (IVR) navigation, entering PIN codes, or other user input scenarios.

Fields

  • event (string): Must be "dtmf".
  • dtmf (object): Contains the DTMF digit information.

dtmf object

  • callId (string): Unique identifier of the call.
  • otherLegCallId (string): Unique identifier of the other leg of the call.
  • digit (string): The DTMF digit pressed. Valid values are:
  • "0" through "9" — numeric digits
  • "*" — asterisk/star key
  • "#" — pound/hash key
  • "A", "B", "C", "D" — extended DTMF tones (less common)
  • duration (number, optional): Duration of the key press in milliseconds.

Example

{
  "event": "dtmf",
  "dtmf": {
    "callId": "call_12345",
    "otherLegCallId": "call_67890",
    "digit": "5",
    "duration": 100
  }
}

Use Cases

  • IVR Navigation: The AI Provider can use DTMF events to navigate menu options (e.g., "Press 1 for sales, Press 2 for support").
  • PIN Entry: Capture secure numeric input from the caller.
  • Call Transfer: Use specific key combinations to trigger call transfers or other actions.
  • Interruption Handling: Detect when a caller wants to interrupt the AI agent by pressing a key.

Collecting a number: dtmf_collect and dtmf_collected

By default each key press arrives as its own dtmf event. To read a number (an account, a PIN, a date) as one value, the AI Provider sends dtmf_collect. The platform then holds the digits back, ends the entry by terminator key, length or timeout, and sends a single dtmf_collected. After that the call goes back to one dtmf event per key.

This works like a Collect DTMF step in a callflow, requested by the AI Provider whenever it needs one. Providers that never send dtmf_collect see no change.

sequenceDiagram
    autonumber
    participant C as Caller
    participant S as QVOICE Platform
    participant P as AI Provider

    P->>C: "Key in your account number, then press #35;" (audio)
    P->>S: dtmf_collect (totalTimeoutMs 10000, interdigitTimeoutMs 2000, terminator "#35;")
    Note over S: Entry starts, 10 s total timer running
    C->>S: Presses 4 4 7 1 2 0 3
    Note over S: Digits held back. The 2 s timer restarts on every key
    C->>S: Presses #35;
    S->>P: dtmf_collected (digits "4471203", reason "terminator")
    Note over S: Back to one dtmf event per key
    C->>S: Presses 9
    S->>P: dtmf (digit "9")

    alt Caller stops typing for 2 s
        S->>P: dtmf_collected (digits so far, reason "interdigit_timeout")
    else 10 s pass since dtmf_collect
        S->>P: dtmf_collected (digits so far, may be empty, reason "total_timeout")
    else maxDigits digits typed
        S->>P: dtmf_collected (digits, reason "max_digits")
    else AI Provider sends dtmf_collect_cancel
        S->>P: dtmf_collected (digits so far, reason "cancelled")
    else AI Provider sends a new dtmf_collect
        S->>P: dtmf_collected (digits so far, reason "replaced")
    else Call ends
        S->>P: hangup (no dtmf_collected)
    end

Steps 1 to 7 are the usual path. The alt block lists the other ways an entry can end. Each one sends exactly one dtmf_collected, except when the call ends.

Event: dtmf_collect (AI Provider → server)

  • event (string): Must be "dtmf_collect".
  • dtmfCollect (object, optional): Every field is optional.
dtmfCollect object
  • requestId (string, optional): Returned unchanged in dtmf_collected, to match the answer to the question.
  • totalTimeoutMs (number, optional): Time allowed for the whole entry, counted from when the server receives dtmf_collect. Default 5000, maximum 300000.
  • interdigitTimeoutMs (number, optional): Time allowed between two key presses. It starts at the first key, so a caller who has not started typing is only bound by totalTimeoutMs. Default 2000, maximum 60000.
  • maxDigits (number, optional): The entry ends as soon as this many digits are collected. Default and maximum 128.
  • terminator (string, optional): Keys that end the entry, for example "#" or "#*". The terminator is not included in the digits. Default "#"; send "" to have no terminator.

A dtmf_collect received while another one is running ends the running one with reason replaced and starts the new one.

{
  "event": "dtmf_collect",
  "dtmfCollect": {
    "requestId": "account-number",
    "totalTimeoutMs": 10000,
    "interdigitTimeoutMs": 2000,
    "maxDigits": 10,
    "terminator": "#"
  }
}

Event: dtmf_collect_cancel (AI Provider → server)

Ends the running entry early. The server answers with dtmf_collected carrying what was typed so far and reason cancelled. Ignored when no entry is running.

{ "event": "dtmf_collect_cancel" }

Event: dtmf_collected (server → AI Provider)

  • event (string): "dtmf_collected".
  • dtmfCollected (object):
    • callId (string): Unique identifier of the call.
    • otherLegCallId (string): Unique identifier of the other leg of the call.
    • requestId (string, optional): The requestId of the dtmf_collect.
    • digits (string): The digits typed, without the terminator. May be empty.
    • reason (string): Why the entry ended:
      • "terminator": a terminator key was pressed
      • "max_digits": maxDigits digits were collected
      • "interdigit_timeout": the caller stopped typing for interdigitTimeoutMs
      • "total_timeout": totalTimeoutMs elapsed
      • "cancelled": the AI Provider sent dtmf_collect_cancel
      • "replaced": the AI Provider sent a new dtmf_collect
{
  "event": "dtmf_collected",
  "dtmfCollected": {
    "callId": "call_12345",
    "otherLegCallId": "call_67890",
    "requestId": "account-number",
    "digits": "4471203",
    "reason": "terminator"
  }
}

Note

No dtmf events are sent for the keys of a running entry. If the call ends during an entry, the server sends hangup and no dtmf_collected.

Example: reading an account number

  1. The bot says "Please key in your account number, then press hash" and sends dtmf_collect with terminator "#" and totalTimeoutMs 10000.
  2. The caller types 4, 4, 7, 1, 2, 0, 3, #. The bot receives nothing yet.
  3. On # the bot receives dtmf_collected with digits "4471203" and reason "terminator".
  4. Any key pressed after that arrives as a normal dtmf event.

Event: hangup

Sent when the call ends to notify the AI Provider that the session is terminating. This event is sent immediately before the WebSocket connection is closed.

Fields

  • event (string): Must be "hangup".
  • hangup (object): Contains hangup information.

hangup object

  • callId (string): Unique identifier of the call.
  • otherLegCallId (string): Unique identifier of the other leg of the call.
  • reason (string, optional): The reason for the hangup. Common values include:
  • "NORMAL_CLEARING" — Normal call termination
  • "USER_BUSY" — Called party is busy
  • "NO_ANSWER" — No answer from called party
  • "CALL_REJECTED" — Call was rejected
  • "ORIGINATOR_CANCEL" — Caller hung up before answer

Example

{
  "event": "hangup",
  "hangup": {
    "callId": "call_12345",
    "otherLegCallId": "call_67890",
    "reason": "NORMAL_CLEARING"
  }
}

Use Cases

  • Session Cleanup: The AI Provider can use this event to clean up resources, save conversation logs, or trigger post-call processing.
  • Analytics: Track call duration and termination reasons for reporting purposes.
  • State Management: Gracefully terminate any ongoing AI processing or speech synthesis.

Message Flow Overview

  1. Server → AI Provider: Sends a single start event to begin the session.
  2. Server ↔ AI Provider: Exchanges continuous media events containing audio frames.
  3. Server → AI Provider: Sends dtmf events when the caller presses keypad digits. While a dtmf_collect requested by the AI Provider is running, the digits are held back and sent once as dtmf_collected.
  4. Server → AI Provider: Sends a hangup event when the call ends.
  5. Connection Close: Server closes the WebSocket connection after sending the hangup event.