An intelligent chat message processing agent built with Spring Boot, Spring AI, Harness, and LangSmith.
English | 中文
- Features
- Tech Stack
- Quick Start
- Configuration
- API Documentation
- Usage Examples
- Supported Platforms
- Multi-Model Support
- Contributing
- License
- Multi-Platform Chat Integration: Connect to WeChat Work, DingTalk, Telegram, WhatsApp, and Teammors
- Message Filtering: Filter chat messages by keywords, time range, sender, etc.
- AI-Powered Summarization: Use LLMs like OpenAI, DeepSeek, Doubao for message summarization
- Message Forwarding: Forward messages to specified users or groups
- Email Notifications: Send messages via email
- Redis Integration: Store forwarded messages in Redis for caching
- LangSmith Integration: Track and trace LLM interactions
- Harness Integration: Orchestrate workflows with Harness
- Java: 21
- Spring Boot: 3.2.x
- Spring AI: 1.0.0-SNAPSHOT
- Spring Data JPA: For database operations
- Spring Data Redis: For caching
- MySQL: Primary database
- Redis: Cache and message queue
- OpenAI/DeepSeek/Doubao: LLM providers
- LangSmith: LLM tracing
- Harness: Workflow orchestration
- Java 21 or higher
- Maven 3.8+
- MySQL 8.0+
- Redis 7.0+
- API keys for LLM providers (OpenAI, DeepSeek, Doubao)
- Clone the repository
git clone https://github.com/yourusername/xmessage-chat-agent.git
cd xmessage-chat-agent- Configure environment variables
Create a .env file in the root directory:
# Database Configuration
SPRING_DATASOURCE_URL=jdbc:mysql://localhost:3306/xteam_videos?useUnicode=true&characterEncoding=utf8&serverTimezone=Asia/Shanghai
SPRING_DATASOURCE_USERNAME=your_username
SPRING_DATASOURCE_PASSWORD=your_password
# Redis Configuration
SPRING_DATA_REDIS_HOST=localhost
SPRING_DATA_REDIS_PORT=6379
SPRING_DATA_REDIS_PASSWORD=your_redis_password
# LLM Configuration
OPENAI_API_KEY=your_openai_api_key
DEEPSEEK_API_KEY=your_deepseek_api_key
DOUBAO_API_KEY=your_doubao_api_key
# LangSmith Configuration
LANGSMITH_API_KEY=your_langsmith_api_key
LANGSMITH_PROJECT_NAME=xmessage-chat-agent
# Platform Configuration (Optional)
WECHAT_WORK_ENABLED=false
WECHAT_WORK_CORP_ID=your_corp_id
WECHAT_WORK_CORP_SECRET=your_corp_secret- Run the application
mvn spring-boot:runThe application will start on http://localhost:8080
server:
port: 8080
spring:
datasource:
url: ${SPRING_DATASOURCE_URL}
username: ${SPRING_DATASOURCE_USERNAME}
password: ${SPRING_DATASOURCE_PASSWORD}
data:
redis:
host: ${SPRING_DATA_REDIS_HOST}
port: ${SPRING_DATA_REDIS_PORT}
password: ${SPRING_DATA_REDIS_PASSWORD}
ai:
active-model: ${AI_ACTIVE_MODEL:openai}
models:
openai:
api-key: ${OPENAI_API_KEY}
base-url: ${OPENAI_BASE_URL:https://api.openai.com}
model: gpt-4o
deepseek:
api-key: ${DEEPSEEK_API_KEY}
base-url: ${DEEPSEEK_BASE_URL:https://api.deepseek.com/v1}
model: deepseek-chat
doubao:
api-key: ${DOUBAO_API_KEY}
base-url: ${DOUBAO_BASE_URL:https://api.doubao.com/v1}
model: doubao-prochat:
data-sources:
wechat-work:
enabled: ${WECHAT_WORK_ENABLED:false}
corp-id: ${WECHAT_WORK_CORP_ID}
corp-secret: ${WECHAT_WORK_CORP_SECRET}
dingtalk:
enabled: ${DINGTALK_ENABLED:false}
app-key: ${DINGTALK_APP_KEY}
app-secret: ${DINGTALK_APP_SECRET}
telegram:
enabled: ${TELEGRAM_ENABLED:false}
bot-token: ${TELEGRAM_BOT_TOKEN}
whatsapp:
enabled: ${WHATSAPP_ENABLED:false}
api-key: ${WHATSAPP_API_KEY}
phone-number-id: ${WHATSAPP_PHONE_NUMBER_ID}
teammors:
enabled: ${TEAMMORS_ENABLED:false}
api-url: ${TEAMMORS_API_URL}
api-key: ${TEAMMORS_API_KEY}| Endpoint | Method | Description |
|---|---|---|
/api/agent/task |
POST | Execute agent task |
/api/agent/tasks |
GET | Get all tasks |
/api/agent/tasks/{id} |
GET | Get task status |
/api/agent/tasks/{id} |
DELETE | Cancel task |
| Endpoint | Method | Description |
|---|---|---|
/api/chat/messages |
GET | Get chat messages |
/api/chat/messages/filter |
POST | Filter messages |
/api/chat/summary |
POST | Summarize messages |
| Endpoint | Method | Description |
|---|---|---|
/api/forward/message |
POST | Forward message |
/api/forward/batch |
POST | Batch forward |
| Endpoint | Method | Description |
|---|---|---|
/api/email/send |
POST | Send email |
/api/email/send/text |
POST | Send email from text |
| Endpoint | Method | Description |
|---|---|---|
/api/chat/sources/platforms |
GET | Get supported platforms |
/api/chat/sources/fetch |
POST | Fetch messages from platforms |
/api/chat/sources/send |
POST | Send message to platform |
curl -X POST http://localhost:8080/api/agent/task \
-H "Content-Type: application/json" \
-d '{
"userId": "user123",
"filter": {
"chatId": "group_chat_001",
"isGroup": true,
"keyword": "重要"
},
"needForward": true,
"forwardTargets": ["user456", "user789"],
"needEmail": true,
"emailTargets": ["admin@example.com"],
"reportTargetUserId": "user123"
}'curl -X POST http://localhost:8080/api/chat/summary \
-H "Content-Type: application/json" \
-d '{
"chatId": "group_chat_001",
"customPrompt": "请总结以下群聊消息的要点"
}'curl -X POST http://localhost:8080/api/chat/sources/fetch \
-H "Content-Type: application/json" \
-d '{
"platforms": ["wechat-work", "dingtalk"],
"groupId": "group_001",
"startTime": "2024-01-01",
"endTime": "2024-01-31"
}'curl -X POST http://localhost:8080/api/chat/sources/send \
-H "Content-Type: application/json" \
-d '{
"platform": "wechat-work",
"targetId": "user123",
"content": "Hello from XMessageChatAgent!"
}'| Platform | Service Name | Status |
|---|---|---|
| WeChat Work | wechat-work |
✅ Available |
| DingTalk | dingtalk |
✅ Available |
| Telegram | telegram |
✅ Available |
whatsapp |
✅ Available | |
| Teammors | teammors |
✅ Available |
- Create a new class implementing
ChatDataSource:
@Service("newplatform")
public class NewPlatformDataSource implements ChatDataSource {
// Implement interface methods
}- Add configuration to
application.yml:
chat:
data-sources:
newplatform:
enabled: true
api-key: ${NEW_PLATFORM_API_KEY}The agent supports multiple LLM providers:
curl -X POST http://localhost:8080/api/chat/model/switch \
-H "Content-Type: application/json" \
-d '{
"model": "deepseek"
}'| Model | Provider |
|---|---|
gpt-4o |
OpenAI |
deepseek-chat |
DeepSeek |
doubao-pro |
Doubao |
We welcome contributions! Please follow these steps:
- Fork the repository
- Create a feature branch (
git checkout -b feature/AmazingFeature) - Commit your changes (
git commit -m 'Add some AmazingFeature') - Push to the branch (
git push origin feature/AmazingFeature) - Open a Pull Request
- Follow Java 21 best practices
- Use Lombok for reducing boilerplate code
- Write unit tests for new features
- Follow REST API design principles
- Maintain code style consistency
This project is licensed under the MIT License - see the LICENSE file for details.
一个基于 Spring Boot、Spring AI、Harness 和 LangSmith 构建的智能聊天消息处理代理。
English | 中文
- 多平台聊天集成: 连接企业微信、钉钉、Telegram、WhatsApp 和 Teammors
- 消息过滤: 按关键词、时间范围、发送者等条件过滤消息
- AI 驱动的总结: 使用 OpenAI、DeepSeek、Doubao 等大模型进行消息总结
- 消息转发: 将消息转发给指定用户或群聊
- 邮件通知: 通过邮件发送消息
- Redis 集成: 将转发消息存储在 Redis 中进行缓存
- LangSmith 集成: 跟踪和追踪 LLM 交互
- Harness 集成: 使用 Harness 编排工作流
- Java: 21
- Spring Boot: 3.2.x
- Spring AI: 1.0.0-SNAPSHOT
- Spring Data JPA: 数据库操作
- Spring Data Redis: 缓存
- MySQL: 主数据库
- Redis: 缓存和消息队列
- OpenAI/DeepSeek/Doubao: LLM 提供商
- LangSmith: LLM 追踪
- Harness: 工作流编排
- Java 21 或更高版本
- Maven 3.8+
- MySQL 8.0+
- Redis 7.0+
- LLM 提供商的 API 密钥(OpenAI、DeepSeek、Doubao)
- 克隆仓库
git clone https://github.com/yourusername/xmessage-chat-agent.git
cd xmessage-chat-agent- 配置环境变量
在根目录创建 .env 文件:
# 数据库配置
SPRING_DATASOURCE_URL=jdbc:mysql://localhost:3306/xteam_videos?useUnicode=true&characterEncoding=utf8&serverTimezone=Asia/Shanghai
SPRING_DATASOURCE_USERNAME=your_username
SPRING_DATASOURCE_PASSWORD=your_password
# Redis 配置
SPRING_DATA_REDIS_HOST=localhost
SPRING_DATA_REDIS_PORT=6379
SPRING_DATA_REDIS_PASSWORD=your_redis_password
# LLM 配置
OPENAI_API_KEY=your_openai_api_key
DEEPSEEK_API_KEY=your_deepseek_api_key
DOUBAO_API_KEY=your_doubao_api_key
# LangSmith 配置
LANGSMITH_API_KEY=your_langsmith_api_key
LANGSMITH_PROJECT_NAME=xmessage-chat-agent
# 平台配置(可选)
WECHAT_WORK_ENABLED=false
WECHAT_WORK_CORP_ID=your_corp_id
WECHAT_WORK_CORP_SECRET=your_corp_secret- 运行应用
mvn spring-boot:run应用将在 http://localhost:8080 启动
server:
port: 8080
spring:
datasource:
url: ${SPRING_DATASOURCE_URL}
username: ${SPRING_DATASOURCE_USERNAME}
password: ${SPRING_DATASOURCE_PASSWORD}
data:
redis:
host: ${SPRING_DATA_REDIS_HOST}
port: ${SPRING_DATA_REDIS_PORT}
password: ${SPRING_DATA_REDIS_PASSWORD}
ai:
active-model: ${AI_ACTIVE_MODEL:openai}
models:
openai:
api-key: ${OPENAI_API_KEY}
base-url: ${OPENAI_BASE_URL:https://api.openai.com}
model: gpt-4o
deepseek:
api-key: ${DEEPSEEK_API_KEY}
base-url: ${DEEPSEEK_BASE_URL:https://api.deepseek.com/v1}
model: deepseek-chat
doubao:
api-key: ${DOUBAO_API_KEY}
base-url: ${DOUBAO_BASE_URL:https://api.doubao.com/v1}
model: doubao-prochat:
data-sources:
wechat-work:
enabled: ${WECHAT_WORK_ENABLED:false}
corp-id: ${WECHAT_WORK_CORP_ID}
corp-secret: ${WECHAT_WORK_CORP_SECRET}
dingtalk:
enabled: ${DINGTALK_ENABLED:false}
app-key: ${DINGTALK_APP_KEY}
app-secret: ${DINGTALK_APP_SECRET}
telegram:
enabled: ${TELEGRAM_ENABLED:false}
bot-token: ${TELEGRAM_BOT_TOKEN}
whatsapp:
enabled: ${WHATSAPP_ENABLED:false}
api-key: ${WHATSAPP_API_KEY}
phone-number-id: ${WHATSAPP_PHONE_NUMBER_ID}
teammors:
enabled: ${TEAMMORS_ENABLED:false}
api-url: ${TEAMMORS_API_URL}
api-key: ${TEAMMORS_API_KEY}| 端点 | 方法 | 描述 |
|---|---|---|
/api/agent/task |
POST | 执行代理任务 |
/api/agent/tasks |
GET | 获取所有任务 |
/api/agent/tasks/{id} |
GET | 获取任务状态 |
/api/agent/tasks/{id} |
DELETE | 取消任务 |
| 端点 | 方法 | 描述 |
|---|---|---|
/api/chat/messages |
GET | 获取聊天消息 |
/api/chat/messages/filter |
POST | 过滤消息 |
/api/chat/summary |
POST | 总结消息 |
| 端点 | 方法 | 描述 |
|---|---|---|
/api/forward/message |
POST | 转发消息 |
/api/forward/batch |
POST | 批量转发 |
| 端点 | 方法 | 描述 |
|---|---|---|
/api/email/send |
POST | 发送邮件 |
/api/email/send/text |
POST | 从文本发送邮件 |
| 端点 | 方法 | 描述 |
|---|---|---|
/api/chat/sources/platforms |
GET | 获取支持的平台 |
/api/chat/sources/fetch |
POST | 从平台获取消息 |
/api/chat/sources/send |
POST | 发送消息到平台 |
curl -X POST http://localhost:8080/api/agent/task \
-H "Content-Type: application/json" \
-d '{
"userId": "user123",
"filter": {
"chatId": "group_chat_001",
"isGroup": true,
"keyword": "重要"
},
"needForward": true,
"forwardTargets": ["user456", "user789"],
"needEmail": true,
"emailTargets": ["admin@example.com"],
"reportTargetUserId": "user123"
}'curl -X POST http://localhost:8080/api/chat/summary \
-H "Content-Type: application/json" \
-d '{
"chatId": "group_chat_001",
"customPrompt": "请总结以下群聊消息的要点"
}'curl -X POST http://localhost:8080/api/chat/sources/fetch \
-H "Content-Type: application/json" \
-d '{
"platforms": ["wechat-work", "dingtalk"],
"groupId": "group_001",
"startTime": "2024-01-01",
"endTime": "2024-01-31"
}'curl -X POST http://localhost:8080/api/chat/sources/send \
-H "Content-Type: application/json" \
-d '{
"platform": "wechat-work",
"targetId": "user123",
"content": "来自 XMessageChatAgent 的消息!"
}'| 平台 | 服务名称 | 状态 |
|---|---|---|
| 企业微信 | wechat-work |
✅ 可用 |
| 钉钉 | dingtalk |
✅ 可用 |
| Telegram | telegram |
✅ 可用 |
whatsapp |
✅ 可用 | |
| Teammors | teammors |
✅ 可用 |
- 创建实现
ChatDataSource接口的类:
@Service("newplatform")
public class NewPlatformDataSource implements ChatDataSource {
// 实现接口方法
}- 在
application.yml中添加配置:
chat:
data-sources:
newplatform:
enabled: true
api-key: ${NEW_PLATFORM_API_KEY}代理支持多个 LLM 提供商:
curl -X POST http://localhost:8080/api/chat/model/switch \
-H "Content-Type: application/json" \
-d '{
"model": "deepseek"
}'| 模型 | 提供商 |
|---|---|
gpt-4o |
OpenAI |
deepseek-chat |
DeepSeek |
doubao-pro |
Doubao |
欢迎贡献代码!请遵循以下步骤:
- Fork 仓库
- 创建功能分支 (
git checkout -b feature/AmazingFeature) - 提交更改 (
git commit -m 'Add some AmazingFeature') - 推送到分支 (
git push origin feature/AmazingFeature) - 打开 Pull Request
- 遵循 Java 21 最佳实践
- 使用 Lombok 减少样板代码
- 为新功能编写单元测试
- 遵循 REST API 设计原则
- 保持代码风格一致
本项目采用 MIT 许可证 - 详见 LICENSE 文件。
