Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Dec 19, 2025

问题

API 模式创建的智能机器人回调消息无法被 WxCpXmlMessage 正确解析,缺少主动发送消息的 API。

变更

消息接收支持

  • WxCpXmlMessage 添加 robotIdsessionId 字段及 XStream 注解
// 现在可以正确解析智能机器人回调消息
WxCpXmlMessage message = WxCpXmlMessage.fromEncryptedXml(...);
String robotId = message.getRobotId();
String sessionId = message.getSessionId();

主动发送消息 API

  • 新增 WxCpIntelligentRobotSendMessageRequest/Response
  • WxCpIntelligentRobotService 添加 sendMessage() 方法
  • 添加 SEND_MESSAGE API 路径常量
WxCpIntelligentRobotSendMessageRequest request = new WxCpIntelligentRobotSendMessageRequest();
request.setRobotId("robot_id");
request.setUserid("user123");
request.setMessage("消息内容");

WxCpIntelligentRobotSendMessageResponse response = robotService.sendMessage(request);

文档和测试

  • 更新 INTELLIGENT_ROBOT.md 添加使用示例
  • 添加消息解析和发送的单元测试

参考文档: https://developer.work.weixin.qq.com/document/path/100719

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • developer.work.weixin.qq.com
    • Triggering command: /usr/bin/curl curl -s REDACTED (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

Original prompt

This section details on the original issue you should resolve

<issue_title>企微智能机器人接收消息和主动发消息</issue_title>
<issue_description># 提问前,请确保阅读过项目首页说明以及wiki开发文档相关内容,完成内容后,请务必移除包括本句在内的无用内容,以免影响他人阅读,否则直接关闭,谢谢合作~

简要描述

用”API模式创建“智能机器人后
将自己的智能体接入到智能机器人,接收并回复消息
目前4.7.9.B用WxCpXmlMessage接收消息无法解析

官方文档地址

https://developer.work.weixin.qq.com/document/path/100719
#3684</issue_description>

Comments on the Issue (you are @copilot in this section)

Custom agent used: 全部用中文
需要用中文,包括PR标题和分析总结过程


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Copilot AI self-assigned this Dec 19, 2025
Copilot AI changed the title [WIP] Fix message parsing issue in intelligent robot 添加企微智能机器人消息接收和主动发送功能 Dec 19, 2025
Copilot AI requested a review from binarywang December 19, 2025 17:36
@binarywang binarywang marked this pull request as ready for review December 20, 2025 04:06
Copilot AI review requested due to automatic review settings December 20, 2025 04:06
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

本 PR 为企业微信智能机器人模块添加了消息接收解析和主动发送消息的功能支持,解决了 API 模式创建的智能机器人回调消息无法被正确解析的问题。

主要变更包括:

  • WxCpXmlMessage 中添加 robotIdsessionId 字段支持智能机器人消息解析
  • 新增主动发送消息的请求/响应类和服务方法
  • 完善相关测试用例和文档说明

Reviewed changes

Copilot reviewed 9 out of 9 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/message/WxCpXmlMessage.java 添加 robotId 和 sessionId 字段及 XStream 注解,支持智能机器人消息解析
weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/intelligentrobot/WxCpIntelligentRobotSendMessageRequest.java 新增主动发送消息请求类,包含 robotId、userid、message、sessionId、msgId 字段
weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/intelligentrobot/WxCpIntelligentRobotSendMessageResponse.java 新增主动发送消息响应类,包含 msgId 和 sessionId 字段
weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpIntelligentRobotService.java 在服务接口中添加 sendMessage 方法定义
weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/impl/WxCpIntelligentRobotServiceImpl.java 实现 sendMessage 方法,调用微信 API 发送消息
weixin-java-cp/src/main/java/me/chanjar/weixin/cp/constant/WxCpApiPathConsts.java 添加 SEND_MESSAGE API 路径常量
weixin-java-cp/src/test/java/me/chanjar/weixin/cp/bean/message/WxCpXmlMessageTest.java 添加智能机器人消息解析测试用例
weixin-java-cp/src/test/java/me/chanjar/weixin/cp/api/impl/WxCpIntelligentRobotServiceImplTest.java 添加主动发送消息请求/响应的序列化和反序列化测试用例
weixin-java-cp/INTELLIGENT_ROBOT.md 更新文档,添加主动发送消息和接收消息的使用说明和示例代码

/**
* Test intelligent robot message parsing
* 测试智能机器人消息解析
*/
Copy link

Copilot AI Dec 20, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

测试方法缺少 @test 注解。在 TestNG 中,每个测试方法都需要添加 @test 注解才能被测试框架识别和执行。虽然类级别有 @test 注解,但按照项目中其他测试文件的惯例(如同一文件中的 testFromXml、testMsgIdStringAndNumericFormats 等方法),每个测试方法也应该单独标注 @test

Suggested change
*/
*/
@Test

Copilot uses AI. Check for mistakes.
assert this.wxCpService.getIntelligentRobotService() instanceof WxCpIntelligentRobotServiceImpl;
}

@Test
Copy link

Copilot AI Dec 20, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

测试方法缺少 @test 注解。在 TestNG 中,每个测试方法都需要添加 @test 注解才能被测试框架识别和执行。按照项目中其他测试类的惯例(如 testCreateRobot、testChatRequest 等方法),每个测试方法都应该单独标注 @test

Suggested change
@Test
@Test
@Test

Copilot uses AI. Check for mistakes.
}

@Test
public void testSendMessageResponse() {
Copy link

Copilot AI Dec 20, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

测试方法缺少 @test 注解。在 TestNG 中,每个测试方法都需要添加 @test 注解才能被测试框架识别和执行。按照项目中其他测试类的惯例(如 testCreateRobot、testChatRequest 等方法),每个测试方法都应该单独标注 @test

Copilot uses AI. Check for mistakes.
public static WxCpIntelligentRobotSendMessageResponse fromJson(String json) {
return WxCpGsonBuilder.create().fromJson(json, WxCpIntelligentRobotSendMessageResponse.class);
}

Copy link

Copilot AI Dec 20, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This method overrides WxCpBaseResp.toJson; it is advisable to add an Override annotation.

Suggested change
@Override

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

企微智能机器人接收消息和主动发消息

2 participants