@@ -73,6 +73,42 @@ String sessionId = "session123";
7373robotService. resetSession(robotId, userid, sessionId);
7474```
7575
76+ ### 主动发送消息
77+
78+ 智能机器人可以主动向用户发送消息,用于推送通知或提醒。
79+
80+ ``` java
81+ WxCpIntelligentRobotSendMessageRequest request = new WxCpIntelligentRobotSendMessageRequest ();
82+ request. setRobotId(" robot_id_here" );
83+ request. setUserid(" user123" );
84+ request. setMessage(" 您好,这是来自智能机器人的主动消息" );
85+ request. setSessionId(" session123" ); // 可选,用于保持会话连续性
86+
87+ WxCpIntelligentRobotSendMessageResponse response = robotService. sendMessage(request);
88+ String msgId = response. getMsgId();
89+ String sessionId = response. getSessionId();
90+ ```
91+
92+ ### 接收用户消息
93+
94+ 当用户向智能机器人发送消息时,企业微信会通过回调接口推送消息。可以使用 ` WxCpXmlMessage ` 接收和解析这些消息:
95+
96+ ``` java
97+ // 在接收回调消息的接口中
98+ WxCpXmlMessage message = WxCpXmlMessage . fromEncryptedXml(
99+ requestBody, wxCpConfigStorage, timestamp, nonce, msgSignature
100+ );
101+
102+ // 获取智能机器人相关字段
103+ String robotId = message. getRobotId(); // 机器人ID
104+ String sessionId = message. getSessionId(); // 会话ID
105+ String content = message. getContent(); // 消息内容
106+ String fromUser = message. getFromUserName(); // 发送用户
107+
108+ // 处理消息并回复
109+ // ...
110+ ```
111+
76112### 删除智能机器人
77113
78114``` java
@@ -87,13 +123,19 @@ robotService.deleteRobot(robotId);
87123- ` WxCpIntelligentRobotCreateRequest ` : 创建机器人请求
88124- ` WxCpIntelligentRobotUpdateRequest ` : 更新机器人请求
89125- ` WxCpIntelligentRobotChatRequest ` : 智能对话请求
126+ - ` WxCpIntelligentRobotSendMessageRequest ` : 主动发送消息请求
90127
91128### 响应类
92129
93130- ` WxCpIntelligentRobotCreateResponse ` : 创建机器人响应
94131- ` WxCpIntelligentRobotChatResponse ` : 智能对话响应
132+ - ` WxCpIntelligentRobotSendMessageResponse ` : 主动发送消息响应
95133- ` WxCpIntelligentRobot ` : 机器人信息实体
96134
135+ ### 消息接收
136+
137+ - ` WxCpXmlMessage ` : 支持接收智能机器人回调消息,包含 ` robotId ` 和 ` sessionId ` 字段
138+
97139### 服务接口
98140
99141- ` WxCpIntelligentRobotService ` : 智能机器人服务接口
0 commit comments