Skip to content

Action Types

Complete reference for all actions you can send to the AI Flow service.

Overview

Actions are JSON objects you send back to the AI Flow service in response to events. All actions require a session_id and type field.

Base Action Structure

json
{
  "session_id": "550e8400-e29b-41d4-a716-446655440000",
  "type": "speak"
}

Action Summary

Action TypeDescriptionPrimary Use Case
speakSpeak text or SSMLRespond to user with synthesized speech
audioPlay pre-recorded audioPlay hold music, pre-recorded messages
hangupEnd the callTerminate conversation
transferTransfer to another numberRoute to human agent or department
barge_inManually interrupt playbackStop current audio immediately

Quick Reference

Response Format

HTTP Webhook

Return actions as JSON with 200 OK:

http
HTTP/1.1 200 OK
Content-Type: application/json

{
  "type": "speak",
  "session_id": "550e8400-e29b-41d4-a716-446655440000",
  "text": "Hello!"
}

Or return 204 No Content if no action is needed:

http
HTTP/1.1 204 No Content

WebSocket

Send actions as JSON strings:

json
{
  "type": "speak",
  "session_id": "550e8400-e29b-41d4-a716-446655440000",
  "text": "Hello!"
}

Action Flow

Common Patterns

Simple Response

json
{
  "type": "speak",
  "session_id": "session-123",
  "text": "Hello! How can I help you?"
}

Conditional Response

python
if "goodbye" in event['text'].lower():
    return {
        "type": "hangup",
        "session_id": event['session']['id']
    }
else:
    return {
        "type": "speak",
        "session_id": event['session']['id'],
        "text": "I understand."
    }

Chaining Actions

You can only return one action per event. To chain actions, use the assistant_speak event:

python
# First response
if event['type'] == 'user_speak':
    return {
        "type": "speak",
        "session_id": event['session']['id'],
        "text": "Please listen to this message."
    }

# Follow-up after assistant speaks
if event['type'] == 'assistant_speak':
    return {
        "type": "audio",
        "session_id": event['session']['id'],
        "audio": "base64-audio-data"
    }

Next Steps