Merged
Conversation
Co-authored-by: binarywang <[email protected]>
Copilot
AI
changed the title
[WIP] Add additional fields to customer message parameters
添加客服消息aimsgcontext字段支持
Dec 5, 2025
There was a problem hiding this comment.
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 格式 |
weixin-java-miniapp/src/test/java/cn/binarywang/wx/miniapp/bean/WxMaKefuMessageTest.java
Show resolved
Hide resolved
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
根据微信官方文档更新,小程序客服消息API新增了
aimsgcontext字段用于AI消息上下文关联。变更内容
aimsgcontext字段和AiMsgContext内部类(包含msgid字段)aiMsgContextMsgId()方法支持链式设置上下文消息ID使用示例
生成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
💡 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.