Skip to content

Event Types

Complete reference for all events sent by the AI Flow service.

Overview

Events are JSON objects sent from the AI Flow service to your application. All events include a type field and session information.

Base Event Structure

All events include session information:

json
{
  "session": {
    "id": "550e8400-e29b-41d4-a716-446655440000",
    "account_id": "account-123",
    "phone_number": "1234567890",
    "direction": "inbound",
    "from_phone_number": "9876543210",
    "to_phone_number": "1234567890"
  }
}

The direction field indicates whether the call was initiated by the caller ("inbound") or by the AI flow via the outbound call API ("outbound"). Use it in your session_start handler to tailor the greeting accordingly.

Event Types

Event TypeTransportDescriptionWhen Triggered
session_startHTTP + WebSocketCall session beginsWhen a new call is initiated
user_speech_startedWebSocket onlySpeech onset detectedWhen VAD detects the user starting to speak (before full transcript)
user_speakHTTP + WebSocketUser speech detectedAfter speech-to-text completes (includes barged_in flag if user interrupted)
dtmf_receivedHTTP + WebSocketDTMF digit pressedWhen the user presses a key on their phone keypad
assistant_speakHTTP + WebSocketAssistant finished speakingAfter TTS playback completes
assistant_speech_endedHTTP + WebSocketAssistant finished speakingAfter speech playback ends
user_input_timeoutHTTP + WebSocketUser input timeout reachedWhen no speech detected after timeout
session_endHTTP + WebSocketCall session endsWhen the call terminates
sms_failedHTTP + WebSocketSMS delivery failedAfter a send_sms action fails — includes reason so the agent can react

Quick Reference

SMS Failed

Emitted to your webhook / WebSocket when a send_sms action fails. The call continues normally — handle this event to react conversationally (e.g. apologize, retry with a corrected number).

json
{
  "type": "sms_failed",
  "session": { "id": "550e8400-...", "account_id": "...", "phone_number": "...",
                "from_phone_number": "...", "to_phone_number": "..." },
  "recipient": "4915112345678",
  "reason": "sender_not_allowed",
  "message": "SMSC returned faultCode 403"
}
FieldTypeDescription
typestringAlways "sms_failed"
sessionobjectStandard session info
recipientstringPhone number that failed (the phone_number from your send_sms action)
reasonstringOne of: sender_not_allowed, insufficient_balance, no_sms_extension, smsc_unavailable, unknown
messagestringOptional human-readable detail (safe to log, may contain technical error text)

See Send SMS Action for details on each failure reason.

Event Flow

Handling Events

HTTP Webhook

python
@app.route('/webhook', methods=['POST'])
def webhook():
    event = request.json
    event_type = event['type']

    if event_type == 'session_start':
        # Handle session start
        pass
    elif event_type == 'user_speak':
        # Handle user speech
        pass
    # ... handle other events

WebSocket

javascript
ws.on('message', (data) => {
  const event = JSON.parse(data.toString());

  switch (event.type) {
    case 'session_start':
      // Handle session start
      break;
    case 'user_speak':
      // Handle user speech
      break;
    // ... handle other events
  }
});

Response Requirements

All events (except session_end) accept a single action, an array of actions (executed in sequence), or 204 No Content:

  • session_start: Can return action(s) or 204 No Content
  • user_speak: Can return action(s) or 204 No Content (check barged_in flag for interruptions)
  • dtmf_received: Can return action(s) or 204 No Content
  • assistant_speak: Can return action(s) or 204 No Content
  • assistant_speech_ended: Can return action(s) or 204 No Content
  • user_input_timeout: Can return action(s) or 204 No Content
  • session_end: No action allowed, cleanup only

Next Steps