1+ package WeChatCustomerServiceSDK
2+
3+ import (
4+ "encoding/json"
5+ "errors"
6+ "fmt"
7+ "github.com/NICEXAI/WeChatCustomerServiceSDK/util"
8+ )
9+
10+ const (
11+ //获取会话状态
12+ serviceStateGetAddr = "https://qyapi.weixin.qq.com/cgi-bin/kf/service_state/get?access_token=%s"
13+ // 变更会话状态
14+ serviceStateTransAddr = "https://qyapi.weixin.qq.com/cgi-bin/kf/service_state/trans?access_token=%s"
15+ )
16+
17+ // ServiceStateGetOptions 获取会话状态请求参数
18+ type ServiceStateGetOptions struct {
19+ OpenKFID string `json:"open_kfid"` // 客服帐号ID
20+ ExternalUserID string `json:"external_userid"` // 微信客户的external_userid
21+ }
22+
23+ // ServiceStateGetSchema 获取会话状态响应内容
24+ type ServiceStateGetSchema struct {
25+ BaseModel
26+ ServiceState int `json:"service_state"` // 当前的会话状态,状态定义参考概述中的表格
27+ ServiceUserID string `json:"service_userid"` // 接待人员的userid,仅当state=3时有效
28+ }
29+
30+ // ServiceStateGet 获取会话状态
31+ //0 未处理 新会话接入。可选择:1.直接用API自动回复消息。2.放进待接入池等待接待人员接待。3.指定接待人员进行接待
32+ //1 由智能助手接待 可使用API回复消息。可选择转入待接入池或者指定接待人员处理。
33+ //2 待接入池排队中 在待接入池中排队等待接待人员接入。可选择转为指定人员接待
34+ //3 由人工接待 人工接待中。可选择结束会话
35+ //4 已结束 会话已经结束。不允许变更会话状态,等待用户重新发起咨询
36+ func (r * Client ) ServiceStateGet (options ServiceStateGetOptions ) (info ServiceStateGetSchema , err error ) {
37+ data , err := util .HttpPost (fmt .Sprintf (serviceStateGetAddr , r .accessToken ), options )
38+ if err != nil {
39+ return info , err
40+ }
41+ _ = json .Unmarshal (data , & info )
42+ if info .ErrCode != 0 {
43+ return info , errors .New (info .ErrMsg )
44+ }
45+ return info , nil
46+ }
47+
48+ // ServiceStateTransOptions 变更会话状态请求参数
49+ type ServiceStateTransOptions struct {
50+ OpenKFID string `json:"open_kfid"` // 客服帐号ID
51+ ExternalUserID string `json:"external_userid"` // 微信客户的external_userid
52+ ServiceState int `json:"service_state"` // 变更的目标状态,状态定义和所允许的变更可参考概述中的流程图和表格
53+ ServicerUserID string `json:"servicer_userid"` // 接待人员的userid,当state=3时要求必填
54+ }
55+
56+ // ServiceStateTrans 变更会话状态
57+ func (r * Client ) ServiceStateTrans (options ServiceStateTransOptions ) (info BaseModel , err error ) {
58+ data , err := util .HttpPost (fmt .Sprintf (serviceStateTransAddr , r .accessToken ), options )
59+ if err != nil {
60+ return info , err
61+ }
62+ _ = json .Unmarshal (data , & info )
63+ if info .ErrCode != 0 {
64+ return info , errors .New (info .ErrMsg )
65+ }
66+ return info , nil
67+ }
0 commit comments