Integrate an AI agent into a web application for real-time messaging.
Before you begin
-
Messaging provides web UI components only for mobile devices.
-
Develop relevant API operations on your server or deploy the provided server source code. For more information, see Deploy a project.
-
The development environment requires Node 18 or later and NPM 10 or later.
Download source code
Download link
Download the source code from the GitHub repository.
Directory structure
.
└── React
├── README.md
├── eslint.config.js
├── index.html // For PC
├── mobile.html // For mobile device
├── package.json
├── src
│ ├── Mobile // Mobile UI implementation
│ ├── PC // PC UI implementation
│ ├── common // Common business methods
│ ├── controller // Business logic interfaces and implementation
│ ├── service // Interactions with the server
│ └── vite-env.d.ts
├── tsconfig.app.json
├── tsconfig.json
└── vite.config.ts
Run the demo
-
After downloading the source code, open the React directory.
-
In the React directory, run
npm installto install dependencies. -
Open the file
src/service/interface.tsand modify the server domain name.// src/controller/service/interface.ts const APP_SERVER = 'Domain name of your app server'; -
Open the file
src/App.tsxand modify the AI agent ID.const defaultChatAgentId = 'AI agent ID'; -
Run the command
npm run devto start the local service. -
Access
http://localhost:5173/mobileto try the message conversation with AI agent.