AI Agent Component Spec
AI Agent Component Spec
Overview
The UI Kit provides wrapper methods around the CometChat SDK that manage internal eventing and keep UI components synchronized. Always use these methods instead of raw SDK calls when working with UI Kit components. Time estimate: 10 minutesDifficulty: Beginner
Prerequisites
- React.js integration completed
- CometChat app credentials from the dashboard
Steps
Step 1: Initialize the UI Kit
Callinit() on app startup before any other UI Kit method:
Step 2: Check for existing session
Before logging in, check if a user session already exists:Step 3: Login with Auth Key (development only)
For development and testing, use the simple Auth Key login:Step 4: Login with Auth Token (production)
For production, generate Auth Tokens on your server and pass them to the client:Step 5: Send messages programmatically
Use the wrapper methods to send messages while keeping UI components in sync:Step 6: Logout
End the user session when they sign out:Complete Example
Advanced: Create and update users
Advanced: Create and update users
Create or update users programmatically (requires Auth Key):
Common Issues
| Issue | Solution |
|---|---|
| Components not rendering | Ensure init() completes before rendering |
| Messages not appearing in UI | Use CometChatUIKit.sendTextMessage() instead of CometChat.sendMessage() |
| Session not persisting | Check browser storage settings and CORS configuration |