🆕 #3815 【企业微信】增加智能机器人消息接收和主动发送功能
This commit is contained in:
@@ -64,4 +64,14 @@ public interface WxCpIntelligentRobotService {
|
||||
*/
|
||||
void resetSession(String robotId, String userid, String sessionId) throws WxErrorException;
|
||||
|
||||
/**
|
||||
* 智能机器人主动发送消息
|
||||
* 官方文档: https://developer.work.weixin.qq.com/document/path/100719
|
||||
*
|
||||
* @param request 发送消息请求参数
|
||||
* @return 发送消息响应
|
||||
* @throws WxErrorException 微信接口异常
|
||||
*/
|
||||
WxCpIntelligentRobotSendMessageResponse sendMessage(WxCpIntelligentRobotSendMessageRequest request) throws WxErrorException;
|
||||
|
||||
}
|
||||
@@ -61,4 +61,10 @@ public class WxCpIntelligentRobotServiceImpl implements WxCpIntelligentRobotServ
|
||||
this.cpService.post(RESET_SESSION, jsonObject.toString());
|
||||
}
|
||||
|
||||
@Override
|
||||
public WxCpIntelligentRobotSendMessageResponse sendMessage(WxCpIntelligentRobotSendMessageRequest request) throws WxErrorException {
|
||||
String responseText = this.cpService.post(SEND_MESSAGE, request.toJson());
|
||||
return WxCpIntelligentRobotSendMessageResponse.fromJson(responseText);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
package me.chanjar.weixin.cp.bean.intelligentrobot;
|
||||
|
||||
import com.google.gson.annotations.SerializedName;
|
||||
import lombok.Data;
|
||||
import me.chanjar.weixin.cp.util.json.WxCpGsonBuilder;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* 智能机器人发送消息请求
|
||||
* 官方文档: https://developer.work.weixin.qq.com/document/path/100719
|
||||
*
|
||||
* @author Binary Wang
|
||||
*/
|
||||
@Data
|
||||
public class WxCpIntelligentRobotSendMessageRequest implements Serializable {
|
||||
private static final long serialVersionUID = -1L;
|
||||
|
||||
/**
|
||||
* 机器人ID,必填
|
||||
*/
|
||||
@SerializedName("robot_id")
|
||||
private String robotId;
|
||||
|
||||
/**
|
||||
* 接收消息的用户ID,必填
|
||||
*/
|
||||
@SerializedName("userid")
|
||||
private String userid;
|
||||
|
||||
/**
|
||||
* 消息内容,必填
|
||||
*/
|
||||
@SerializedName("message")
|
||||
private String message;
|
||||
|
||||
/**
|
||||
* 会话ID,可选,用于保持会话连续性
|
||||
*/
|
||||
@SerializedName("session_id")
|
||||
private String sessionId;
|
||||
|
||||
/**
|
||||
* 消息ID,可选
|
||||
*/
|
||||
@SerializedName("msg_id")
|
||||
private String msgId;
|
||||
|
||||
public String toJson() {
|
||||
return WxCpGsonBuilder.create().toJson(this);
|
||||
}
|
||||
|
||||
public static WxCpIntelligentRobotSendMessageRequest fromJson(String json) {
|
||||
return WxCpGsonBuilder.create().fromJson(json, WxCpIntelligentRobotSendMessageRequest.class);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
package me.chanjar.weixin.cp.bean.intelligentrobot;
|
||||
|
||||
import com.google.gson.annotations.SerializedName;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import me.chanjar.weixin.cp.bean.WxCpBaseResp;
|
||||
import me.chanjar.weixin.cp.util.json.WxCpGsonBuilder;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* 智能机器人发送消息响应
|
||||
* 官方文档: https://developer.work.weixin.qq.com/document/path/100719
|
||||
*
|
||||
* @author Binary Wang
|
||||
*/
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
public class WxCpIntelligentRobotSendMessageResponse extends WxCpBaseResp implements Serializable {
|
||||
private static final long serialVersionUID = -1L;
|
||||
|
||||
/**
|
||||
* 消息ID
|
||||
*/
|
||||
@SerializedName("msg_id")
|
||||
private String msgId;
|
||||
|
||||
/**
|
||||
* 会话ID
|
||||
*/
|
||||
@SerializedName("session_id")
|
||||
private String sessionId;
|
||||
|
||||
public static WxCpIntelligentRobotSendMessageResponse fromJson(String json) {
|
||||
return WxCpGsonBuilder.create().fromJson(json, WxCpIntelligentRobotSendMessageResponse.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toJson() {
|
||||
return WxCpGsonBuilder.create().toJson(this);
|
||||
}
|
||||
}
|
||||
@@ -253,6 +253,24 @@ public class WxCpXmlMessage implements Serializable {
|
||||
@XStreamConverter(value = XStreamCDataConverter.class)
|
||||
private String linkId;
|
||||
|
||||
/**
|
||||
* 智能机器人ID
|
||||
* 接收智能机器人消息时使用
|
||||
* https://developer.work.weixin.qq.com/document/path/100719
|
||||
*/
|
||||
@XStreamAlias("RobotId")
|
||||
@XStreamConverter(value = XStreamCDataConverter.class)
|
||||
private String robotId;
|
||||
|
||||
/**
|
||||
* 智能机器人会话ID
|
||||
* 接收智能机器人消息时使用,用于保持会话连续性
|
||||
* https://developer.work.weixin.qq.com/document/path/100719
|
||||
*/
|
||||
@XStreamAlias("SessionId")
|
||||
@XStreamConverter(value = XStreamCDataConverter.class)
|
||||
private String sessionId;
|
||||
|
||||
/**
|
||||
* 通讯录变更事件.
|
||||
* 请参考常量 me.chanjar.weixin.cp.constant.WxCpConsts.ContactChangeType
|
||||
|
||||
@@ -1666,5 +1666,11 @@ public interface WxCpApiPathConsts {
|
||||
* 重置智能机器人会话
|
||||
*/
|
||||
String RESET_SESSION = "/cgi-bin/intelligent_robot/reset_session";
|
||||
|
||||
/**
|
||||
* 智能机器人主动发送消息
|
||||
* 官方文档: https://developer.work.weixin.qq.com/document/path/100719
|
||||
*/
|
||||
String SEND_MESSAGE = "/cgi-bin/intelligent_robot/send_message";
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user