POST /chat/outbound

/chat/outbound enables you to send an outbound chat message through a predefined flow. The API requires providing text, a user ID, a flow ID, and optional metadata.

Parameters

  • text (string): The message text to be sent. The message will be displayed as an AI message to the receiving user.
  • user_id (string): The unique identifier of the user receiving the message.
  • flow_id (string): The unique identifier of the flow to route the message through.
  • metadata (json): Additional metadata related to the conversation.

Example Request

{
    "text": "Hello! How can I assist you today?",
    "user_id": "user_123",
    "flow_id": "flow_456",
    "metadata": {
        "user_type": "VIP",
        "priority": "high"
    }
}

Example Response

  • Status Code 200 (OK): The chat message was successfully sent.
{
    "status_code": 200
}
  • Status Code 400 (Bad Request): Indicates an invalid data was provided.
{
    "error": "Invalid flow_id"
}

Usage Example


import requests

# Set up constants
API_KEY = "YOUR_API_KEY"
ENDPOINT = "https://api.decagon.ai/chat/outbound"
HEADERS = {
    "Authorization": f"Bearer {API_KEY}",
    "Content-Type": "application/json"
}

# Prepare request data
params = {
    "text": "Hello! How can I assist you today?",
    "user_id": "user_123",
    "flow_id": "flow_456",
    "metadata": {
        "user_type": "VIP",
        "priority": "high"
    }
}

# Make request and handle response
response = requests.post(ENDPOINT, headers=HEADERS, json=params)
response.raise_for_status()
print(response.json())