|
| 1 | +# 企业微信智能机器人接口 |
| 2 | + |
| 3 | +本模块提供企业微信智能机器人相关的API接口实现。 |
| 4 | + |
| 5 | +## 官方文档 |
| 6 | + |
| 7 | +- [企业微信智能机器人接口](https://developer.work.weixin.qq.com/document/path/101039) |
| 8 | + |
| 9 | +## 接口说明 |
| 10 | + |
| 11 | +### 获取服务实例 |
| 12 | + |
| 13 | +```java |
| 14 | +WxCpService wxCpService = ...; // 初始化企业微信服务 |
| 15 | +WxCpIntelligentRobotService robotService = wxCpService.getIntelligentRobotService(); |
| 16 | +``` |
| 17 | + |
| 18 | +### 创建智能机器人 |
| 19 | + |
| 20 | +```java |
| 21 | +WxCpIntelligentRobotCreateRequest request = new WxCpIntelligentRobotCreateRequest(); |
| 22 | +request.setName("我的智能机器人"); |
| 23 | +request.setDescription("这是一个智能客服机器人"); |
| 24 | +request.setAvatar("http://example.com/avatar.jpg"); |
| 25 | + |
| 26 | +WxCpIntelligentRobotCreateResponse response = robotService.createRobot(request); |
| 27 | +String robotId = response.getRobotId(); |
| 28 | +``` |
| 29 | + |
| 30 | +### 更新智能机器人 |
| 31 | + |
| 32 | +```java |
| 33 | +WxCpIntelligentRobotUpdateRequest request = new WxCpIntelligentRobotUpdateRequest(); |
| 34 | +request.setRobotId("robot_id_here"); |
| 35 | +request.setName("更新后的机器人名称"); |
| 36 | +request.setDescription("更新后的描述"); |
| 37 | +request.setStatus(1); // 1:启用, 0:停用 |
| 38 | + |
| 39 | +robotService.updateRobot(request); |
| 40 | +``` |
| 41 | + |
| 42 | +### 查询智能机器人 |
| 43 | + |
| 44 | +```java |
| 45 | +String robotId = "robot_id_here"; |
| 46 | +WxCpIntelligentRobot robot = robotService.getRobot(robotId); |
| 47 | + |
| 48 | +System.out.println("机器人名称: " + robot.getName()); |
| 49 | +System.out.println("机器人状态: " + robot.getStatus()); |
| 50 | +``` |
| 51 | + |
| 52 | +### 智能对话 |
| 53 | + |
| 54 | +```java |
| 55 | +WxCpIntelligentRobotChatRequest request = new WxCpIntelligentRobotChatRequest(); |
| 56 | +request.setRobotId("robot_id_here"); |
| 57 | +request.setUserid("user123"); |
| 58 | +request.setMessage("你好,请问如何使用这个功能?"); |
| 59 | +request.setSessionId("session123"); // 可选,用于保持会话连续性 |
| 60 | + |
| 61 | +WxCpIntelligentRobotChatResponse response = robotService.chat(request); |
| 62 | +String reply = response.getReply(); |
| 63 | +String sessionId = response.getSessionId(); |
| 64 | +``` |
| 65 | + |
| 66 | +### 重置会话 |
| 67 | + |
| 68 | +```java |
| 69 | +String robotId = "robot_id_here"; |
| 70 | +String userid = "user123"; |
| 71 | +String sessionId = "session123"; |
| 72 | + |
| 73 | +robotService.resetSession(robotId, userid, sessionId); |
| 74 | +``` |
| 75 | + |
| 76 | +### 删除智能机器人 |
| 77 | + |
| 78 | +```java |
| 79 | +String robotId = "robot_id_here"; |
| 80 | +robotService.deleteRobot(robotId); |
| 81 | +``` |
| 82 | + |
| 83 | +## 主要类说明 |
| 84 | + |
| 85 | +### 请求类 |
| 86 | + |
| 87 | +- `WxCpIntelligentRobotCreateRequest`: 创建机器人请求 |
| 88 | +- `WxCpIntelligentRobotUpdateRequest`: 更新机器人请求 |
| 89 | +- `WxCpIntelligentRobotChatRequest`: 智能对话请求 |
| 90 | + |
| 91 | +### 响应类 |
| 92 | + |
| 93 | +- `WxCpIntelligentRobotCreateResponse`: 创建机器人响应 |
| 94 | +- `WxCpIntelligentRobotChatResponse`: 智能对话响应 |
| 95 | +- `WxCpIntelligentRobot`: 机器人信息实体 |
| 96 | + |
| 97 | +### 服务接口 |
| 98 | + |
| 99 | +- `WxCpIntelligentRobotService`: 智能机器人服务接口 |
| 100 | +- `WxCpIntelligentRobotServiceImpl`: 智能机器人服务实现 |
| 101 | + |
| 102 | +## 注意事项 |
| 103 | + |
| 104 | +1. 需要确保企业微信应用具有智能机器人相关权限 |
| 105 | +2. 智能机器人功能可能需要特定的企业微信版本支持 |
| 106 | +3. 会话ID可以用于保持对话的连续性,提升用户体验 |
| 107 | +4. 机器人状态: 0表示停用,1表示启用 |
0 commit comments