-
Notifications
You must be signed in to change notification settings - Fork 8
/
servicer.go
79 lines (71 loc) · 2.61 KB
/
servicer.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
package WeChatCustomerServiceSDK
import (
"encoding/json"
"fmt"
"github.com/NICEXAI/WeChatCustomerServiceSDK/util"
)
const (
//添加接待人员
receptionistAddAddr = "https://qyapi.weixin.qq.com/cgi-bin/kf/servicer/add?access_token=%s"
//删除接待人员
receptionistDelAddr = "https://qyapi.weixin.qq.com/cgi-bin/kf/servicer/del?access_token=%s"
//获取接待人员列表
receptionistListAddr = "https://qyapi.weixin.qq.com/cgi-bin/kf/servicer/list?access_token=%s&open_kfid=%s"
)
// ReceptionistOptions 添加接待人员请求参数
type ReceptionistOptions struct {
OpenKFID string `json:"open_kfid"` // 客服帐号ID
UserIDList []string `json:"userid_list"` // 接待人员userid列表。第三方应用填密文userid,即open_userid 可填充个数:1 ~ 100。超过100个需分批调用。
}
// ReceptionistSchema 添加接待人员响应内容
type ReceptionistSchema struct {
BaseModel
ResultList []struct {
UserID string `json:"userid"`
BaseModel
} `json:"result_list"`
}
// ReceptionistAdd 添加接待人员
func (r *Client) ReceptionistAdd(options ReceptionistOptions) (info ReceptionistSchema, err error) {
data, err := util.HttpPost(fmt.Sprintf(receptionistAddAddr, r.accessToken), options)
if err != nil {
return info, err
}
_ = json.Unmarshal(data, &info)
if info.ErrCode != 0 {
return info, NewSDKErr(info.ErrCode, info.ErrMsg)
}
return info, nil
}
// ReceptionistDel 删除接待人员
func (r *Client) ReceptionistDel(options ReceptionistOptions) (info ReceptionistSchema, err error) {
data, err := util.HttpPost(fmt.Sprintf(receptionistDelAddr, r.accessToken), options)
if err != nil {
return info, err
}
_ = json.Unmarshal(data, &info)
if info.ErrCode != 0 {
return info, NewSDKErr(info.ErrCode, info.ErrMsg)
}
return info, nil
}
// ReceptionistListSchema 获取接待人员列表响应内容
type ReceptionistListSchema struct {
BaseModel
ReceptionistList []struct {
UserID string `json:"userid"` // 接待人员的userid。第三方应用获取到的为密文userid,即open_userid
Status int `json:"status"` // 接待人员的接待状态。0:接待中,1:停止接待。第三方应用需具有“管理帐号、分配会话和收发消息”权限才可获取
} `json:"servicer_list"`
}
// ReceptionistList 获取接待人员列表
func (r *Client) ReceptionistList(kfID string) (info ReceptionistListSchema, err error) {
data, err := util.HttpGet(fmt.Sprintf(receptionistListAddr, r.accessToken, kfID))
if err != nil {
return info, err
}
_ = json.Unmarshal(data, &info)
if info.ErrCode != 0 {
return info, NewSDKErr(info.ErrCode, info.ErrMsg)
}
return info, nil
}