Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Dec 5, 2025

根据微信官方文档更新,小程序客服消息API新增了 aimsgcontext 字段用于AI消息上下文关联。

变更内容

  • WxMaKefuMessage: 新增 aimsgcontext 字段和 AiMsgContext 内部类(包含 msgid 字段)
  • BaseBuilder: 添加 aiMsgContextMsgId() 方法支持链式设置上下文消息ID
  • WxMaKefuMessageTest: 添加序列化测试验证JSON输出

使用示例

// 在回复中引用之前的消息ID作为上下文
WxMaKefuMessage message = WxMaKefuMessage.newTextBuilder()
  .toUser("OPENID")
  .content("根据您的问题...")
  .aiMsgContextMsgId("MSG_ID_123")
  .build();

生成JSON:

{
  "touser": "OPENID",
  "msgtype": "text",
  "text": {"content": "根据您的问题..."},
  "aimsgcontext": {"msgid": "MSG_ID_123"}
}

字段可选,向后兼容现有代码。

参考

https://developers.weixin.qq.com/doc/subscription/api/customer/message/api_sendcustommessage.html#Body-aimsgcontext-Object-Payload

Original prompt

This section details on the original issue you should resolve

<issue_title>客服消息参数增加了一些字段</issue_title>
<issue_description># 提问前,请确保阅读过项目首页说明以及wiki开发文档相关内容,完成内容后,请务必移除包括本句在内的无用内容,以免影响他人阅读,否则直接关闭,谢谢合作~

简要描述

一些参数字段可以加上

官方文档地址

请提供所需功能对应的微信官方文档地址以便进行确认。
https://developers.weixin.qq.com/doc/subscription/api/customer/message/api_sendcustommessage.html#Body-aimsgcontext-Object-Payload</issue_description>

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

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


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Co-authored-by: binarywang <1343140+binarywang@users.noreply.github.com>
Copilot AI changed the title [WIP] Add additional fields to customer message parameters 添加客服消息aimsgcontext字段支持 Dec 5, 2025
Copilot AI requested a review from binarywang December 5, 2025 04:39
@binarywang binarywang marked this pull request as ready for review December 5, 2025 04:48
Copilot AI review requested due to automatic review settings December 5, 2025 04:48
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 添加了 aimsgcontext 字段支持,使得开发者可以在回复消息时关联之前的消息 ID 作为 AI 对话上下文。这是根据微信官方文档更新新增的功能字段,该字段为可选字段,不影响现有代码的向后兼容性。

主要变更

  • WxMaKefuMessage 中新增 AiMsgContext 内部类和 aiMsgContext 字段,支持 JSON 序列化
  • BaseBuilder 中添加 aiMsgContextMsgId() 方法,支持所有消息类型的构建器使用该字段
  • 添加了序列化测试用例,验证 JSON 输出格式符合微信 API 要求

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

File Description
weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/bean/WxMaKefuMessage.java 新增 AiMsgContext 内部类和 aiMsgContext 字段,使用 Gson 注解支持 JSON 序列化
weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/builder/BaseBuilder.java 在基础构建器中添加 aiMsgContextMsgId 字段和对应的链式设置方法,并在 build() 方法中条件性创建 AiMsgContext 对象
weixin-java-miniapp/src/test/java/cn/binarywang/wx/miniapp/bean/WxMaKefuMessageTest.java 添加测试方法验证带有 aimsgcontext 字段的消息序列化为正确的 JSON 格式

@binarywang binarywang merged commit 85bd274 into develop Dec 5, 2025
7 checks passed
@binarywang binarywang deleted the copilot/add-additional-parameters branch December 5, 2025 08:20
@binarywang binarywang added this to the 4.8.0 milestone Dec 10, 2025
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