Overview
The web chat interface lets you simulate customer interactions in real-time through a browser-based conversation. You play the role of the business (as an operator or IVR system), while the AI agent behaves as a customer trying to complete a specific task. This mode is perfect for:- Rapid prototyping of conversation flows
- Testing different business scenarios without placing real calls
- Debugging customer interactions before phone deployment
- Training on how customers might approach your business
How It Works
The web chat system uses a three-part architecture:- OpenAI GPT-4o-mini generates conversational responses based on your business description and scenario
- ElevenLabs TTS converts agent text responses into natural-sounding speech
- Flask session management maintains conversation context across messages
Technical Flow
Starting a Conversation
Provide Business Context
Navigate to the home page at
http://localhost:5000 and describe the business you want to test.Example business descriptions:- “A dental clinic with online booking, insurance verification, and reminder calls”
- “A pizza delivery service that takes orders, provides ETA, and handles complaints”
- “A bank’s customer service line for balance inquiries, fraud reports, and card activation”
Define the Scenario (Optional)
Specify what the caller wants to accomplish. If left blank, the system uses the default scenario:Custom scenario examples:
- “check appointment availability for next Tuesday”
- “order a large pepperoni pizza for delivery”
- “report a fraudulent charge on my credit card”
The conversation doesn’t begin until you send your first message. The agent waits for you to initiate, simulating how a real phone system would answer a call.
Message Flow
Once the conversation is active, you interact with the agent through a turn-based chat interface.Sending Messages
Type your response as if you are the business answering the phone. Common examples:- “Thank you for calling ABC Dental. How can I help you today?”
- “What size pizza would you like to order?”
- “I can help with that. Can you provide your account number?”
Backend Processing
When you send a message, the/api/chat endpoint processes it:
System Prompt Construction
The agent receives a carefully crafted prompt that defines its behavior:OpenAI API Integration
The backend calls OpenAI’s Chat Completions API:Audio Playback
Every agent response is automatically converted to speech using ElevenLabs TTS.Text-to-Speech Conversion
The backend generates audio using thetext_to_speech_audio function:
Text is truncated to 1500 characters to stay within ElevenLabs limits and ensure fast response times.
Response Format
The/api/chat endpoint returns both text and audio:
Frontend Audio Rendering
The web interface receives the response and plays the audio automatically:Audio plays automatically when received, but you can replay any message using the embedded controls in the message bubble.
Conversation UI Elements
The chat interface displays messages in a turn-based format:Message Display
- User (You as the business): Blue background, left-aligned
- Agent (AI customer): Green background, right-aligned
Message Structure
Each message shows the role and content:Error Handling
The backend includes graceful fallbacks:Common Errors
| Error Message | Cause | Solution |
|---|---|---|
Set a business description first (use /api/context) | Attempting to chat without initializing context | Click “Start conversation” first |
No message provided | Sent empty message | Type a message before sending |
Request failed | Network or server error | Check console logs and server status |
API Reference
POST /api/context
Initializes a new conversation session.
Request body:
POST /api/chat
Sends a message and receives the agent’s response.
Request body:
Best Practices
Start with Clear Context
Provide detailed business descriptions including:
- What the business does
- Available services or products
- Common customer requests
- Any special policies or procedures
Use Realistic Scenarios
Test scenarios that match real customer behaviors:
- Simple information requests
- Transaction completions
- Problem resolution
- Edge cases and difficult customers
Play the Role Authentically
Respond as your actual business would:
- Use your real greeting scripts
- Follow your standard procedures
- Apply your actual policies
- Use industry-appropriate language
Session Management
Conversation state is stored in Flask sessions:Next Steps
After testing conversation flows in the web chat:- Move to real phone call testing to validate the same scenarios over actual phone lines
- Use the same business description and scenario for consistent testing across both modes
- Compare agent behavior between text chat and voice calls