work/kf/customer.pm untested

filter: Statementstmt 0.0% 0 / 60 Branchbran 0.0% 0 / 16 Conditioncond 0.0% 0 / 21 MC/DCmcdc 0.0% 0 / 11 Subroutinesub 0.0% 0 / 10 Podpod 0.0% 0 / 4 totaltotal 0.0% 0 / 122 CC 9 SCAR 21.6
CC
9
Cov
0%
get_upgrade_service_config
12.0
upgrade_service
12.0
cancel_upgrade_service
12.0
CRAP 8.7
1 package QQ::weixin::work::kf::customer;
2
3 =encoding utf8
4
5 =head1 Name
6
7 QQ::weixin::work::kf::customer
8
9 =head1 DESCRIPTION
10
11 「升级服务」配置
12 最后更新:2024/01/22
13
14 =cut
15
16 use strict;
17 use base qw(QQ::weixin::work::kf);
18 use Encode;
19 use LWP::UserAgent;
20 use JSON;
21 use utf8;
22
23 our $VERSION = '0.10';
24 our @EXPORT = qw/ get_upgrade_service_config upgrade_service cancel_upgrade_service batchget /;
25
26 =head1 FUNCTION
27
28 =head2 get_upgrade_service_config(access_token, hash);
29
30 获取配置的专员与客户群
31
32 =head2 SYNOPSIS
33
34 L<https://developer.work.weixin.qq.com/document/path/94674#获取配置的专员与客户群>
35
36 =head3 请求说明:
37
38 企业需要在管理后台或移动端中的「微信客服」-「升级服务」中,配置专员和客户群。该接口提供获取配置的专员与客户群列表的能力。
39
40 =head4 参数说明:
41
42 参数 必须 类型 说明
43 access_token 是 string 调用接口凭证
44
45 =head3 权限说明
46
47 调用的应用需要满足如下的权限
48
49 应用类型 权限要求
50 自建应用 配置到「 微信客服- 可调用接口的应用」中
51 第三方应用 具有“微信客服->服务工具->配置「升级服务」”权限
52 代开发自建应用 具有“微信客服->服务工具->配置「升级服务」”权限
53
54 注: 从2023年12月1日0点起,不再支持通过系统应用secret调用接口,存量企业暂不受影响 查看详情
55
56 要求 userid/chatid 对应群主在应用可见范围内
57
58 =head3 RETURN 返回结果
59
60 {
61 "errcode": 0,
62 "errmsg": "ok",
63 "member_range": {
64 "userid_list": [
65 "zhangsan",
66 "lisi"
67 ],
68 "department_id_list": [
69 2,
70 3
71 ]
72 },
73 "groupchat_range": {
74 "chat_id_list": [
75 "wraaaaaaaaaaaaaaaa",
76 "wrbbbbbbbbbbbbbbb"
77 ]
78 }
79 }
80
81 =head4 RETURN 参数说明
82
83 参数 类型 说明
84 errcode int 返回码
85 errmsg string 错误码描述
86 member_range object 专员服务配置范围
87 member_range.userid_list string 专员userid列表
88 member_range.department_list unsigned int 专员部门列表
89 groupchat_range object 客户群配置范围
90 groupchat_range.chat_id_list string 客户群列表
91
92 =cut
93
94 sub get_upgrade_service_config {
95 if ( @_ && $_[0] ) {
96 my $access_token = $_[0];
97 my $ua = LWP::UserAgent->new;
98 $ua->timeout(30);
99 $ua->env_proxy;
100
101 my $response = $ua->get("https://qyapi.weixin.qq.com/cgi-bin/kf/customer/get_upgrade_service_config?access_token=$access_token");
102 if ($response->is_success) {
103 return from_json($response->decoded_content,{utf8 => 1, allow_nonref => 1});
104 }
105
106 }
107 return 0;
108 }
109
110 =head2 upgrade_service(access_token, hash);
111
112 为客户升级为专员或客户群服务
113
114 =head2 SYNOPSIS
115
116 L<https://developer.work.weixin.qq.com/document/path/94674#为客户升级为专员或客户群服务>
117
118 =head3 请求说明:
119
120 企业可通过其他接口获知客户的 external_userid 以及客户与接待人员的聊天内容,因此可以结合实际业务场景,为客户推荐指定的服务专员或客户群。
121 通过该 API 为客户指定专员或客户群后,接待人员可在企业微信中,见到特殊的状态提示(Windows 为 icon 样式变化,移动端为出现一条 bar ),便于接待人员知晓企业的指定动作。
122
123 =head4 请求包结构体为:
124
125 =head4 升级专员服务:
126
127 {
128 "open_kfid": "kfxxxxxxxxxxxxxx",
129 "external_userid": "wmxxxxxxxxxxxxxxxxxx",
130 "type": 1,
131 "member": {
132 "userid": "zhangsan",
133 "wording": "你好,我是你的专属服务专员zhangsan"
134 }
135 }
136
137 =head4 升级客户群服务:
138
139 {
140 "open_kfid": "kfxxxxxxxxxxxxxx",
141 "external_userid": "wmxxxxxxxxxxxxxxxxxx",
142 "type": 2,
143 "groupchat": {
144 "chat_id": "wraaaaaaaaaaaaaaaa",
145 "wording": "欢迎加入你的专属服务群"
146 }
147 }
148
149 =head4 参数说明:
150
151 参数 必须 说明
152 access_token 是 调用接口凭证
153 open_kfid 是 客服帐号ID
154 external_userid 是 微信客户的external_userid
155 type 是 表示是升级到专员服务还是客户群服务。1:专员服务。2:客户群服务
156 member 否 推荐的服务专员,type等于1时有效
157 member.userid 是 服务专员的userid
158 member.wording 否 推荐语
159 groupchat 否 推荐的客户群,type等于2时有效
160 groupchat.chat_id 是 客户群id
161 groupchat.wording 否 推荐语
162
163 =head3 权限说明
164
165 调用的应用需要满足如下的权限
166
167 应用类型 权限要求
168 自建应用 配置到「 微信客服- 可调用接口的应用」中
169 第三方应用 具有“微信客服->服务工具->配置「升级服务”权限
170 代开发自建应用 具有“微信客服->服务工具->配置「升级服务”权限
171
172 注: 从2023年12月1日0点起,不再支持通过系统应用secret调用接口,存量企业暂不受影响 查看详情
173
174 操作的客服账号对应的接待人员应在应用的可见范围内
175 要求 userid/chatid 对应群主在应用可见范围内
176 要求userid/chatid已配置在微信客服中的“升级服务”中专员服务或客户群服务才可使用API进行设置,否则会返回95021错误码。
177 要求userid在“客户联系->权限配置->客户联系和客户群"的使用范围内
178
179 =head3 RETURN 返回结果
180
181 {
182 "errcode": 0,
183 "errmsg": "ok"
184 }
185
186 =head4 RETURN 参数说明
187
188 参数 类型 说明
189 errcode int32 返回码
190 errmsg string 错误码描述
191
192 =cut
193
194 sub upgrade_service {
195 if ( @_ && $_[0] && ref $_[1] eq 'HASH' ) {
196 my $access_token = $_[0];
197 my $json = $_[1];
198 my $ua = LWP::UserAgent->new;
199 $ua->timeout(30);
200 $ua->env_proxy;
201
202 my $response = $ua->post("https://qyapi.weixin.qq.com/cgi-bin/kf/customer/upgrade_service?access_token=$access_token",Content => to_json($json,{allow_nonref=>1}),Content_type =>'application/json');
203 if ($response->is_success) {
204 return from_json($response->decoded_content,{utf8 => 1, allow_nonref => 1});
205 }
206
207 }
208 return 0;
209 }
210
211 =head2 cancel_upgrade_service(access_token, hash);
212
213 为客户取消推荐
214
215 =head2 SYNOPSIS
216
217 L<https://developer.work.weixin.qq.com/document/path/94674#为客户取消推荐>
218
219 =head3 请求说明:
220
221 当企业通过 API 为客户指定了专员或客户群后,如果客户已经完成服务升级,或是企业需要取消推荐,则可调用该接口清空之前为客户指定的专员或客户群。清空后,企业微信中的特殊状态提示也会同步消失。
222
223 =head4 请求包结构体为:
224
225 {
226 "open_kfid": "kfxxxxxxxxxxxxxx",
227 "external_userid": "wmxxxxxxxxxxxxxxxxxx"
228 }
229
230 =head4 参数说明:
231
232 参数 必须 说明
233 access_token 是 调用接口凭证
234 open_kfid 是 客服帐号ID
235 external_userid 是 微信客户的external_userid
236
237 =head3 权限说明
238
239 调用的应用需要满足如下的权限
240
241 应用类型 权限要求
242 自建应用 配置到「 微信客服- 可调用接口的应用」中
243 第三方应用 具有“微信客服->服务工具->配置「升级服务”权限
244 代开发自建应用 具有“微信客服->服务工具->配置「升级服务”权限
245
246 注: 从2023年12月1日0点起,不再支持通过系统应用secret调用接口,存量企业暂不受影响 查看详情
247
248 操作的客服账号对应的接待人员应在应用的可见范围内
249 要求 userid/chatid 对应群主在应用可见范围内
250
251 =head3 RETURN 返回结果
252
253 {
254 "errcode": 0,
255 "errmsg": "ok"
256 }
257
258 =head4 RETURN 参数说明
259
260 参数 类型 说明
261 errcode int32 返回码
262 errmsg string 错误码描述
263
264 =cut
265
266 sub cancel_upgrade_service {
267 if ( @_ && $_[0] && ref $_[1] eq 'HASH' ) {
268 my $access_token = $_[0];
269 my $json = $_[1];
270 my $ua = LWP::UserAgent->new;
271 $ua->timeout(30);
272 $ua->env_proxy;
273
274 my $response = $ua->post("https://qyapi.weixin.qq.com/cgi-bin/kf/customer/cancel_upgrade_service?access_token=$access_token",Content => to_json($json,{allow_nonref=>1}),Content_type =>'application/json');
275 if ($response->is_success) {
276 return from_json($response->decoded_content,{utf8 => 1, allow_nonref => 1});
277 }
278
279 }
280 return 0;
281 }
282
283 =head2 batchget(access_token, hash);
284
285 获取客户基础信息
286 最后更新:2023/11/30
287
288 =head2 SYNOPSIS
289
290 L<https://developer.work.weixin.qq.com/document/path/95159>
291
292 =head3 请求说明:
293
294 =head4 请求包结构体为:
295
296 {
297 "external_userid_list": [
298 "wmxxxxxxxxxxxxxxxxxxxxxx",
299 "zhangsan"
300 ],
301 "need_enter_session_context": 0
302 }
303
304 =head4 参数说明:
305
306 参数 必须 说明
307 access_token 是 调用接口凭证
308 external_userid_list 是 external_userid列表
309 可填充个数:1 ~ 100。超过100个需分批调用。
310 need_enter_session_context 否 是否需要返回客户48小时内最后一次进入会话的上下文信息。
311 0-不返回 1-返回。默认不返回
312
313 =head3 权限说明
314
315 调用的应用需要满足如下的权限
316
317 应用类型 权限要求
318 自建应用 配置到「 微信客服- 可调用接口的应用」中
319 第三方应用 具有“微信客服->获取基础信息”权限
320 代开发自建应用 具有“微信客服->获取基础信息”权限
321
322 注: 从2023年12月1日0点起,不再支持通过系统应用secret调用接口,存量企业暂不受影响 查看详情
323
324 external_userid需为最近 48 小时内有咨询过的客户,咨询的客服账号对应的接待人员需在应用的可见范围内。若 48 小时内咨询过多个客服账号,以最近一个为准
325
326 =head3 RETURN 返回结果
327
328 {
329 "errcode": 0,
330 "errmsg": "ok",
331 "customer_list": [
332 {
333 "external_userid": "wmxxxxxxxxxxxxxxxxxxxxxx",
334 "nickname": "张三",
335 "avatar": "http://xxxxx",
336 "gender": 1,
337 "unionid": "oxasdaosaosdasdasdasd",
338 "enter_session_context": {
339 "scene": "123",
340 "scene_param": "abc",
341 "wechat_channels": {
342 "nickname": "进入会话的视频号名称",
343 "scene": 1
344 }
345 }
346 }
347 ],
348 "invalid_external_userid": [
349 "zhangsan"
350 ]
351 }
352
353 =head4 RETURN 参数说明
354
355 参数 类型 说明
356 errcode int 返回码
357 errmsg string 错误码描述
358 customer_list array 返回结果
359 customer_list.external_userid string 微信客户的external_userid
360 customer_list.nickname string 微信昵称
361 customer_list.avatar string 微信头像。第三方不可获取
362 customer_list.gender int 性别。第三方不可获取,统一返回0
363 customer_list.unionid string unionid,需要绑定微信开发者账号才能获取到,查看绑定方法。第三方不可获取
364 customer_list.enter_session_context obj 48小时内最后一次进入会话的上下文信息。
365 请求的need_enter_session_context参数设置为1才返回
366 customer_list.enter_session_context.scene string 进入会话的场景值,获取客服账号链接开发者自定义的场景值
367 customer_list.enter_session_context.scene_param string 进入会话的自定义参数,获取客服账号链接返回的url,开发者按规范拼接的scene_param参数
368 customer_list.enter_session_context.wechat_channels obj 进入会话的视频号信息,从视频号进入会话才有值
369 customer_list.enter_session_context.wechat_channels.nickname string 视频号名称,视频号场景值为1、2、3时返回此项
370 customer_list.enter_session_context.wechat_channels.shop_nickname string 视频号小店名称,视频号场景值为4、5时返回此项
371 customer_list.enter_session_context.wechat_channels.scene uint32 视频号场景值。1:视频号主页,2:视频号直播间商品列表页,3:视频号商品橱窗页,4:视频号小店商品详情页,5:视频号小店订单页
372
373 =cut
374
375 sub batchget {
376 if ( @_ && $_[0] && ref $_[1] eq 'HASH' ) {
377 my $access_token = $_[0];
378 my $json = $_[1];
379 my $ua = LWP::UserAgent->new;
380 $ua->timeout(30);
381 $ua->env_proxy;
382
383 my $response = $ua->post("https://qyapi.weixin.qq.com/cgi-bin/kf/customer/batchget?access_token=$access_token",Content => to_json($json,{allow_nonref=>1}),Content_type =>'application/json');
384 if ($response->is_success) {
385 return from_json($response->decoded_content,{utf8 => 1, allow_nonref => 1});
386 }
387
388 }
389 return 0;
390 }
391
392 1;
393 __END__