| page_type | languages | products | |||
|---|---|---|---|---|---|
sample |
|
|
This application demonstrates a complete customer service chat experience with an AI-powered assistant that can automatically handle customer inquiries and seamlessly hand off to a human agent when needed.
- Dual Interface: Customer-facing chat widget and agent portal in a single demo
- AI Assistant: Automatic handling of customer inquiries using Azure OpenAI
- Handoff Capability: Smooth transition from AI to human agent when needed
- Real-time Chat: Powered by Azure Communication Services
- System Messages: Clear indicators when the AI or agent joins the conversation
- Conversation Summary: Agents can generate AI-powered summaries of the conversation
- Visual Status Indicators: Online status and AI handling notifications
The application consists of:
- Customer Interface: A clean, modern chat widget for customers to communicate with support
- Agent Portal: A comprehensive interface for agents to monitor conversations and take over when needed
- Bot Service: An AI-powered service using Azure OpenAI to provide automated responses
- Summary Service: AI service that can generate conversation summaries for agents
- Token Server: A minimal Express backend that issues ACS user tokens dynamically
- An Azure account with an active subscription. Create an account for free.
- Node.js (LTS version recommended)
- An active Azure Communication Services resource. For details, see Create an Azure Communication Resource.
- Azure OpenAI Resource and Deployed Model. See instructions.
❗ IMPORTANT: You must set up your environment variables correctly before the app will run.
-
Copy
.env.exampleto.env:cp .env.example .env -
Fill in your actual values in the
.envfile:# Azure Communication Services Configuration ACS_CONNECTION_STRING=your_acs_connection_string ACS_ENDPOINT_URL=your_acs_endpoint_url # Azure OpenAI Configuration AZURE_OPENAI_ENDPOINT=your_azure_openai_endpoint AZURE_OPENAI_KEY=your_azure_openai_key AZURE_OPENAI_DEPLOYMENT_NAME=your_azure_openai_deployment_name AZURE_OPENAI_API_VERSION=your_api_version -
Obtaining Credentials:
- Azure Communication Services:
- Get your connection string and endpoint URL from your ACS resource in the Azure portal
- The app will dynamically generate user access tokens using the backend token server
- Azure OpenAI:
- Create and deploy an Azure OpenAI in Azure AI Foundry Models resource Tutorial
- AZURE_OPENAI_ENDPOINT: This value can be found in the Keys and Endpoint section when examining your resource from the Azure portal.
- AZURE_OPENAI_DEPLOYMENT_NAME: This value will correspond to the custom name you chose for your deployment when you deployed a model. This value can be found under Resource Management > Model Deployments in the Azure portal.
- AZURE_OPENAI_API_VERSION: Learn more about API Versions.
- Azure Communication Services:
-
Important Security Notes:
- Never commit your
.envfile to version control - The
.envfile is included in.gitignoreto prevent accidental commits - For production deployments, use a secure way to manage secrets such as Azure Key Vault
- Never commit your
The application will use these environment variables to connect to Azure services. The config.js module loads these values and provides them to the application.
This demo uses real Azure services, so minimal usage-based costs may apply. We've designed it to be lightweight, but extended use will incur charges. The following services may involve charges:
-
Azure Communication Services
- Billed by usage: number of messages sent/received. See the Azure Communication Services Pricing page for details.
-
Azure OpenAI
- Costs depend on the model used (e.g., GPT-4) and token volume. See the Azure OpenAI Pricing page for details.
Note: Be sure to monitor your Azure usage to avoid unexpected charges. You can set up Azure Cost Management to track and control your spending.
-
Clone the repository:
git clone <repository-url> cd Simple-bot-handoff-sample -
Install dependencies:
npm install -
Set up your
.envfile as described in the Configuration section above -
Start the backend ACS token server:
node server.jsThis will start the Express server on port 3001 (or the port you specify in your
.env). -
Start the frontend development server:
npm startThis will start the Parcel dev server (typically on http://localhost:1234).
-
Open your browser and navigate to the URL displayed in your terminal (typically http://localhost:1234)
- Type messages in the bottom input field and press Send
- Initially, the AI Assistant will respond to inquiries
- System messages will indicate when an agent takes over
- Monitor incoming customer conversations in the Messages panel
- Click "Take Over" in the banner when you want to handle the conversation personally
- Use the "Summarize" button to generate an AI-powered summary of the conversation
- After taking over, type in the input box to respond directly to the customer
If you encounter a "JSON syntax error" when running the application, check your .env file:
- Make sure your
ACS_CONNECTION_STRINGandACS_ENDPOINT_URLare correct. - Ensure you haven't added quotes around any of the values.
- Check if all required environment variables are set.
If you see "Error: Chat Initialization failed" in the app and a 401 (Unauthorized) error in the browser console, your ACS credentials may be incorrect or expired. Double-check your .env values and restart both the backend and frontend servers.
This project is licensed under the MIT License - see the LICENSE file for details.
