Skip to content

teammors/xteammors-chat-agent

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

XMessageChatAgent

Banner

An intelligent chat message processing agent built with Spring Boot, Spring AI, Harness, and LangSmith.

JDK Spring Boot Redis Protocol License Build

English | 中文

Table of Contents

Features

  • 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

Tech Stack

  • 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

Quick Start

Prerequisites

  • Java 21 or higher
  • Maven 3.8+
  • MySQL 8.0+
  • Redis 7.0+
  • API keys for LLM providers (OpenAI, DeepSeek, Doubao)

Installation

  1. Clone the repository
git clone https://github.com/yourusername/xmessage-chat-agent.git
cd xmessage-chat-agent
  1. 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
  1. Run the application
mvn spring-boot:run

The application will start on http://localhost:8080

Configuration

Application Configuration (application.yml)

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-pro

Chat Platform Configuration

chat:
  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 Documentation

Agent API

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

Chat API

Endpoint Method Description
/api/chat/messages GET Get chat messages
/api/chat/messages/filter POST Filter messages
/api/chat/summary POST Summarize messages

Forward API

Endpoint Method Description
/api/forward/message POST Forward message
/api/forward/batch POST Batch forward

Email API

Endpoint Method Description
/api/email/send POST Send email
/api/email/send/text POST Send email from text

Data Source API

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

Usage Examples

Execute Agent Task

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"
  }'

Summarize Messages

curl -X POST http://localhost:8080/api/chat/summary \
  -H "Content-Type: application/json" \
  -d '{
    "chatId": "group_chat_001",
    "customPrompt": "请总结以下群聊消息的要点"
  }'

Fetch Messages from Multiple Platforms

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"
  }'

Send Message to Platform

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!"
  }'

Supported Platforms

Platform Service Name Status
WeChat Work wechat-work ✅ Available
DingTalk dingtalk ✅ Available
Telegram telegram ✅ Available
WhatsApp whatsapp ✅ Available
Teammors teammors ✅ Available

Adding a New Platform

  1. Create a new class implementing ChatDataSource:
@Service("newplatform")
public class NewPlatformDataSource implements ChatDataSource {
    // Implement interface methods
}
  1. Add configuration to application.yml:
chat:
  data-sources:
    newplatform:
      enabled: true
      api-key: ${NEW_PLATFORM_API_KEY}

Multi-Model Support

The agent supports multiple LLM providers:

Switch Models at Runtime

curl -X POST http://localhost:8080/api/chat/model/switch \
  -H "Content-Type: application/json" \
  -d '{
    "model": "deepseek"
  }'

Available Models

Model Provider
gpt-4o OpenAI
deepseek-chat DeepSeek
doubao-pro Doubao

Contributing

We welcome contributions! Please follow these steps:

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/AmazingFeature)
  3. Commit your changes (git commit -m 'Add some AmazingFeature')
  4. Push to the branch (git push origin feature/AmazingFeature)
  5. Open a Pull Request

Development Guidelines

  • 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

License

This project is licensed under the MIT License - see the LICENSE file for details.


Acknowledgments


XMessageChatAgent

一个基于 Spring Boot、Spring AI、Harness 和 LangSmith 构建的智能聊天消息处理代理。

JDK Spring Boot Redis Protocol License Build

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)

安装步骤

  1. 克隆仓库
git clone https://github.com/yourusername/xmessage-chat-agent.git
cd xmessage-chat-agent
  1. 配置环境变量

在根目录创建 .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
  1. 运行应用
mvn spring-boot:run

应用将在 http://localhost:8080 启动

配置说明

应用配置 (application.yml)

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-pro

聊天平台配置

chat:
  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 API

端点 方法 描述
/api/agent/task POST 执行代理任务
/api/agent/tasks GET 获取所有任务
/api/agent/tasks/{id} GET 获取任务状态
/api/agent/tasks/{id} DELETE 取消任务

聊天 API

端点 方法 描述
/api/chat/messages GET 获取聊天消息
/api/chat/messages/filter POST 过滤消息
/api/chat/summary POST 总结消息

转发 API

端点 方法 描述
/api/forward/message POST 转发消息
/api/forward/batch POST 批量转发

邮件 API

端点 方法 描述
/api/email/send POST 发送邮件
/api/email/send/text POST 从文本发送邮件

数据源 API

端点 方法 描述
/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 whatsapp ✅ 可用
Teammors teammors ✅ 可用

添加新平台

  1. 创建实现 ChatDataSource 接口的类:
@Service("newplatform")
public class NewPlatformDataSource implements ChatDataSource {
    // 实现接口方法
}
  1. 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

贡献指南

欢迎贡献代码!请遵循以下步骤:

  1. Fork 仓库
  2. 创建功能分支 (git checkout -b feature/AmazingFeature)
  3. 提交更改 (git commit -m 'Add some AmazingFeature')
  4. 推送到分支 (git push origin feature/AmazingFeature)
  5. 打开 Pull Request

开发规范

  • 遵循 Java 21 最佳实践
  • 使用 Lombok 减少样板代码
  • 为新功能编写单元测试
  • 遵循 REST API 设计原则
  • 保持代码风格一致

许可证

本项目采用 MIT 许可证 - 详见 LICENSE 文件。


致谢

About

An intelligent chat message processing agent built with Spring Boot, Spring AI, Harness, and LangSmith.一个基于 Spring Boot、Spring AI、Harness 和 LangSmith 构建的智能聊天消息处理代理。

Topics

Resources

License

Stars

0 stars

Watchers

0 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors