Overview
Build a customer service chat bot that can handle text-based conversations through your application. Perfect for adding AI chat to websites, mobile apps, or messaging platforms. What You’ll Build:- A working chat integration that responds to user messages
- Context-aware conversations that remember previous messages
- Both one-shot and multi-turn conversation patterns
- Instant text responses without voice processing
- Maintains conversation context across multiple messages
- Compatible with existing OpenAI workflows
Prerequisites
- A CallHQ account
- An existing assistant or willingness to create one
- Basic knowledge of making API requests
Scenario
We’ll create a customer support chat for “TechFlow”, a software company that wants to handle common questions via text chat before escalating to human agents.1. Get Your API Credentials
1
Open the CallHQ Dashboard
Go to web.callhq.ai and log in to your account.
2
Navigate to API Keys
Click on your profile in the top right, then select
API Keys.3
Copy your API key
Copy your API Key. You’ll need this for all chat requests.
Keep this key secure - never expose it in client-side code.
2. Create or Select an Assistant
1
Navigate to Assistants
In your CallHQ dashboard, click
Assistants in the left sidebar.2
Create a new assistant (or use existing)
- Click
Create Assistantif you need a new one - Select
Blank Templateas your starting point - Name it
TechFlow Support - Set the first message to:
Hello! I'm here to help with TechFlow questions. What can I assist you with today?
3
Configure the system prompt
Update the system prompt to:
System Prompt
4
Copy the Assistant ID
After publishing, copy the Assistant ID from the URL or assistant details. You’ll need this for API calls.
3. Create a Chat Session
1
Create a session
First, create a chat session with your assistant:
Create Session
2
Verify the session response
You should receive a JSON response like:
Session Response
4. Send Your First Chat Message
1
Test with curl
Use the session ID from the previous step to send your first message:
First Chat Request
2
Verify the response
You should receive a JSON response like:
Chat Response
5. Build a Multi-Turn Conversation
1
Continue the conversation
Use the same session ID to maintain context across multiple messages:
Follow-up Message
2
Test context awareness
Send another message to verify the assistant remembers the conversation:
Context Test
3
View conversation history
Retrieve the full conversation history for the session:
Get Session History
6. Pass Dynamic Variables
1
Configure variables in your assistant
In your assistant’s system prompt, you can reference dynamic variables using
{{variableName}} syntax:System Prompt with Variables
2
Pass variables in your chat request
Use
assistantOverrides.variableValues to pass dynamic data:Chat Request with Variables
7. Integrate with TypeScript
1
Create a simple chat function
Here’s a TypeScript function you can use in your application:
chat.ts
2
Test your integration
Run your TypeScript code to verify the chat integration works correctly.
8. Test Your Chat Bot
1
Test various scenarios
Try these test cases to ensure your chat bot works correctly:
Test Case 1: General Question
Test Case 2: Technical Issue
2
Verify conversation memory
Send follow-up messages using the same session ID to ensure context is maintained.
3
Check conversation history
Retrieve the full conversation to verify all messages are stored:
Get Full Conversation
Limitations
Current chat functionality limitations:
- “Query” tool for knowledge-base searches is not yet supported
- Server webhook events (status updates, end-of-call reports, etc.) are not supported
Webhook Support
The chat API supports the following webhook events through server messaging:
chat.created- Triggered when a new chat conversation is initiatedchat.deleted- Triggered when a chat conversation is deleted