Generating Start Messages

Generate AI-powered opening messages for new conversations. This is useful for having bots initiate conversations with personalized greetings.

Why Use Dynamic Generation?

Unlike static prewritten message pools, dynamically generated start messages are personalized based on the specific user and bot. The AI analyzes contextual information to create relevant, engaging opening messages that feel natural and tailored to the conversation.

The generation takes into account:

  • User's public photos - Visual context about the user's appearance and style
  • Bot's public photos - Visual context about the bot's appearance and personality
  • Bot's bio and personality description - The bot's freeform description and attributes
  • User's bio and profile - Information about the user's interests, background, and preferences
  • Other available context - Any additional information that helps personalize the message

This results in opening messages that are contextually appropriate and engaging, rather than generic one-size-fits-all greetings from a static pool.

How It Works

The workflow has three steps:

  1. Create an empty conversation
  2. Call /generate-response to generate an opening message
  3. Send the generated message to the conversation

Important: The /generate-response endpoint does NOT automatically add messages to the conversation history. It only generates a new message without modifying the history. You must manually send the generated message using the messages endpoint.

Step-by-Step Guide

Step 1: Create an Empty Conversation

First, create a conversation without any initial messages. This gives you a blank slate for the bot to generate an opening message.

response = requests.post(
    f"{BASE_URL}/api/conversations",
    headers=headers,
    json={
        "bot_id": bot_id,
        "user_id": "user_123",
        "create_user_if_not_exists": True
    }
)

conversation_id = response.json()['conversation']['id']

Step 2: Generate a Start Message

Call the /generate-response endpoint on the empty conversation. The AI will generate an appropriate opening message based on the bot's personality.

response = requests.post(
    f"{BASE_URL}/api/conversations/{conversation_id}/generate-response",
    headers=headers,
    json={}
)

# Extract the generated message text
generated_message = response.json()['candidates'][0]['messages'][0]
message_text = generated_message['text']
# Example: "Hey! How's your day going? 😊"

Step 3: Send the Generated Message

The generated message is not yet in the conversation history. You must manually send it using the messages endpoint.

response = requests.post(
    f"{BASE_URL}/api/conversations/{conversation_id}/messages",
    headers=headers,
    json={
        "message": {
            "text": message_text,
            "from_bot": True
        }
    }
)

Now the start message is in the conversation history and the conversation has begun!

Response Structure

The /generate-response endpoint returns a generated message. It does NOT modify the conversation history.

{
  "candidates": [
    {
      "messages": [
        {
          "text": "Hey! How's your day going? 😊",
          "from_bot": true
        }
      ]
    }
  ]
}

The first candidate's first message is typically what you want to use as the start message.

Full Example

Here's the complete code with all three steps:

import requests

API_KEY = "sk_your_api_key_here"
BASE_URL = "https://api.prioros.com/v3"

headers = {
    "Authorization": f"Bearer {API_KEY}",
    "Content-Type": "application/json"
}

bot_id = "your_bot_id_here"

# Step 1: Create an empty conversation
response = requests.post(
    f"{BASE_URL}/api/conversations",
    headers=headers,
    json={
        "bot_id": bot_id,
        "user_id": "user_123",
        "create_user_if_not_exists": True
    }
)

conversation_id = response.json()['conversation']['id']
print(f"Created conversation: {conversation_id}")

# Step 2: Generate a start message
response = requests.post(
    f"{BASE_URL}/api/conversations/{conversation_id}/generate-response",
    headers=headers,
    json={}
)

# Extract the generated message
generated_message = response.json()['candidates'][0]['messages'][0]
message_text = generated_message['text']
print(f"Generated message: {message_text}")

# Step 3: Send the generated message to the conversation
response = requests.post(
    f"{BASE_URL}/api/conversations/{conversation_id}/messages",
    headers=headers,
    json={
        "message": {
            "text": message_text,
            "from_bot": True
        }
    }
)

print("Start message sent!")