
Security News
Attackers Are Hunting High-Impact Node.js Maintainers in a Coordinated Social Engineering Campaign
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.
chatwoot-react-ui
Advanced tools
一个可复用的 React 聊天 UI 组件库,支持 Chatwoot 集成。该组件库提供了完整的聊天界面,包括会话列表、消息显示、用户管理等功能。
npm install chatwoot-react-ui
# 或
yarn add chatwoot-react-ui
# 或
pnpm add chatwoot-react-ui
import React, { useState } from 'react';
import { SimpleChatUI, User, Dialog, Message } from 'chatwoot-react-ui';
const App = () => {
const [selectedDialog, setSelectedDialog] = useState<Dialog | null>(null);
const [messages, setMessages] = useState<Record<string, Message[]>>({});
const handleSelectDialog = (dialog: Dialog) => {
setSelectedDialog(dialog);
};
const handleSendMessage = (text: string) => {
if (!selectedDialog) return;
const newMessage: Message = {
_id: Date.now().toString(),
chat_dialog_id: selectedDialog._id,
sender_id: 1,
message: text,
date_sent: Date.now(),
read: 0,
};
setMessages(prev => ({
...prev,
[selectedDialog._id]: [...(prev[selectedDialog._id] || []), newMessage],
}));
};
return (
<div style={{ width: '100vw', height: '100vh' }}>
<SimpleChatUI
dialogs={dialogs}
messages={messages}
users={users}
selectedDialog={selectedDialog}
currentUserId={1}
onSelectDialog={handleSelectDialog}
onSendMessage={handleSendMessage}
/>
</div>
);
};
import React, { useState, useCallback } from 'react';
import { ChatUI, User, Dialog, Message } from 'chatwoot-react-ui';
const App = () => {
const [dialogs, setDialogs] = useState<Dialog[]>([]);
const [messages, setMessages] = useState<Record<string, Message[]>>({});
const [users, setUsers] = useState<Record<number, User>>({});
const [selectedDialog, setSelectedDialog] = useState<Dialog | null>(null);
const handleSelectDialog = useCallback((dialog: Dialog) => {
setSelectedDialog(dialog);
// 加载消息逻辑
}, []);
const handleSendMessage = useCallback((text: string) => {
// 发送消息逻辑
}, [selectedDialog]);
const handleSendMessageWithAttachment = useCallback((file: File) => {
// 发送附件逻辑
}, []);
const handleSendTypingStatus = useCallback((isTyping: boolean) => {
// 打字状态逻辑
}, []);
const handleReadMessage = useCallback((messageId: string, senderId: number, dialogId: string) => {
// 已读状态逻辑
}, []);
const handleSearchUsers = useCallback(async (term: string): Promise<User[]> => {
// 用户搜索逻辑
return [];
}, []);
const handleCreateChat = useCallback(async (opponentId: number): Promise<Dialog> => {
// 创建私聊逻辑
return {} as Dialog;
}, []);
const handleCreateGroupChat = useCallback(async (userIds: number[], name: string): Promise<Dialog> => {
// 创建群聊逻辑
return {} as Dialog;
}, []);
const handleAddUsersToGroupChat = useCallback(async (userIds: number[]) => {
// 添加用户到群聊逻辑
}, []);
return (
<div style={{ width: '100vw', height: '100vh' }}>
<ChatUI
dialogs={dialogs}
messages={messages}
users={users}
selectedDialog={selectedDialog}
currentUserId={1}
onSelectDialog={handleSelectDialog}
onSendMessage={handleSendMessage}
onSendMessageWithAttachment={handleSendMessageWithAttachment}
onSendTypingStatus={handleSendTypingStatus}
onReadMessage={handleReadMessage}
onSearchUsers={handleSearchUsers}
onCreateChat={handleCreateChat}
onCreateGroupChat={handleCreateGroupChat}
onAddUsersToGroupChat={handleAddUsersToGroupChat}
showUsersTab={true}
className="border border-gray-300 rounded-lg"
style={{ maxWidth: '1200px', margin: '0 auto' }}
/>
</div>
);
};
| 属性 | 类型 | 必需 | 描述 |
|---|---|---|---|
| dialogs | Dialog[] | ✅ | 会话列表 |
| messages | Record<string, Message[]> | ✅ | 消息数据 |
| users | Record<number, User> | ✅ | 用户数据 |
| selectedDialog | Dialog | null | ✅ | 当前选中的会话 |
| currentUserId | number | ✅ | 当前用户ID |
| onSelectDialog | (dialog: Dialog) => void | ✅ | 选择会话回调 |
| onSendMessage | (text: string) => void | ✅ | 发送消息回调 |
| showUsersTab | boolean | ❌ | 是否显示用户标签页 |
| className | string | ❌ | 自定义CSS类名 |
| style | React.CSSProperties | ❌ | 自定义样式 |
包含 SimpleChatUI 的所有属性,另外还有:
| 属性 | 类型 | 必需 | 描述 |
|---|---|---|---|
| onSendMessageWithAttachment | (file: File) => void | ❌ | 发送附件回调 |
| onSendTypingStatus | (isTyping: boolean) => void | ❌ | 打字状态回调 |
| onReadMessage | (messageId: string, senderId: number, dialogId: string) => void | ❌ | 已读消息回调 |
| onSearchUsers | (term: string) => Promise<User[]> | ❌ | 搜索用户回调 |
| onCreateChat | (opponentId: number) => Promise | ❌ | 创建私聊回调 |
| onCreateGroupChat | (userIds: number[], name: string) => Promise | ❌ | 创建群聊回调 |
| onAddUsersToGroupChat | (userIds: number[]) => Promise | ❌ | 添加用户到群聊回调 |
| lastMessageSentTimeString | (dialog: Dialog) => string | ❌ | 最后消息时间格式化函数 |
| messageSentTimeString | (msg: Message) => string | ❌ | 消息时间格式化函数 |
interface User {
id: number;
full_name?: string;
login?: string;
avatar?: string;
}
interface Dialog {
_id: string;
name: string;
photo?: string;
type: number; // 2: group, 3: private
last_message?: string;
last_message_user_id?: number;
unread_messages_count: number;
last_message_date_sent?: number;
created_at?: number;
occupants_ids: number[];
}
interface Message {
_id: string;
chat_dialog_id: string;
sender_id: number;
message: string;
date_sent: number;
read: number;
attachments?: Array<{ url: string }>;
}
组件使用 Tailwind CSS 构建,你可以通过以下方式定制样式:
# 安装依赖
npm install
# 启动开发服务器
npm run dev
# 构建组件库
npm run build:lib
# 类型检查
npm run typecheck
# 代码检查
npm run lint
MIT License
欢迎提交 Issue 和 Pull Request!
FAQs
A reusable React chat UI component library for Chatwoot integration
We found that chatwoot-react-ui demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.

Security News
Axios compromise traced to social engineering, showing how attacks on maintainers can bypass controls and expose the broader software supply chain.

Security News
Node.js has paused its bug bounty program after funding ended, removing payouts for vulnerability reports but keeping its security process unchanged.