Skip to content

Commit 73d9013

Browse files
committed
feat: 微信客服 接收消息和事件、发送消息、发送欢迎语等事件响应消息 fix: 删除微信客服账号的接口定义错误问题
1 parent 2fe83ea commit 73d9013

14 files changed

+379
-25
lines changed

README.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -193,9 +193,9 @@ CI 会在 `go1.17` 和 Go 的当前稳定版本、上一个稳定版本上跑测
193193
- [x] 获取接待人员列表
194194
* [x] 会话分配与消息收发
195195
- [x] 分配客服会话
196-
- [ ] 接收消息和事件
197-
- [ ] 发送消息
198-
- [ ] 发送欢迎语等事件响应消息
196+
- [x] 接收消息和事件
197+
- [x] 发送消息
198+
- [x] 发送欢迎语等事件响应消息
199199
* [ ] 「升级服务」配置
200200
* [ ] 其他基础信息获取
201201
- [ ] 获取客户基础信息

apis.md.go

+43-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/apis.md

+4-1
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,7 @@ Name|Request Type|Response Type|Access Token|URL|Doc
247247
:---|------------|-------------|------------|:--|:--
248248
`execKfAccountCreate`|`reqKfAccountCreate`|`respKfAccountCreate`|+|`POST /cgi-bin/kf/account/add`|[添加客服账号](https://developer.work.weixin.qq.com/document/path/94662)
249249
`execKfAccountUpdate`|`reqKfAccountUpdate`|`respKfAccountUpdate`|+|`POST /cgi-bin/kf/account/update`|[修改客服账号](https://developer.work.weixin.qq.com/document/path/94664)
250-
`execKfAccountDelete`|`reqKfAccountDelete`|`respKfAccountDelete`|+|`GET /cgi-bin/kf/account/del`|[删除客服账号](https://developer.work.weixin.qq.com/document/path/94663)
250+
`execKfAccountDelete`|`reqKfAccountDelete`|`respKfAccountDelete`|+|`POST /cgi-bin/kf/account/del`|[删除客服账号](https://developer.work.weixin.qq.com/document/path/94663)
251251
`execKfAccountList`|`reqKfAccountList`|`respKfAccountList`|+|`GET /cgi-bin/kf/account/list`|[获取客服账号列表](https://developer.work.weixin.qq.com/document/path/94661)
252252
`execAddKfContact`|`reqAddKfContact`|`respAddKfContact`|+|`POST /cgi-bin/kf/add_contact_way`|[获取客服账号链接](https://developer.work.weixin.qq.com/document/path/94665)
253253

@@ -269,3 +269,6 @@ Name|Request Type|Response Type|Access Token|URL|Doc
269269
:---|------------|-------------|------------|:--|:--
270270
`execKfServiceStateGet`|`reqKfServiceStateGet`|`respKfServiceStateGet`|+|`POST /cgi-bin/kf/service_state/get`|[获取会话状态](https://developer.work.weixin.qq.com/document/path/94669)
271271
`execKfServiceStateTrans`|`reqKfServiceStateTrans`|`respKfServiceStateTrans`|+|`POST /cgi-bin/kf/service_state/trans`|[变更会话状态](https://developer.work.weixin.qq.com/document/path/94669)
272+
`execKfSyncMsg`|`reqKfSyncMsg`|`respKfSyncMsg`|+|`POST /cgi-bin/kf/sync_msg`|[读取消息](https://developer.work.weixin.qq.com/document/path/94670)
273+
`execKfSend`|`reqMessage`|`respMessageSend`|+|`POST /cgi-bin/kf/send_msg`|[发送消息](https://developer.work.weixin.qq.com/document/path/94677)
274+
`execKfOnEventSend`|`reqMessage`|`respMessageSend`|+|`POST /cgi-bin/kf/send_msg_on_event`|[发送欢迎语等事件响应消息](https://developer.work.weixin.qq.com/document/path/95122)

docs/kf.md

+69-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
`StopType` | `stop_type` | `int` | 接待人员的接待状态为「停止接待」的子类型。0:停止接待,1:暂时挂起
2121
`DepartmentID` | `department_id,omitempty` | `int64` | 接待人员部门的id
2222

23-
### `KfServicerResult` 客户群列表数据
23+
### `KfServicerResult` 接待人员数据
2424

2525
Name | JSON | Type | Doc
2626
:---------------|:--------------------------|:---------|:------------
@@ -29,7 +29,75 @@
2929
`ErrCode` | `errcode` | `int64` | 该条记录的结果
3030
`ErrMsg` | `errmsg` | `string` | 结果信息
3131

32+
### `KfMsg` 客服消息数据
33+
34+
Name | JSON | Type | Doc
35+
:---------------|:----------------------------|:--------------|:------------
36+
`MsgID` | `msgid,omitempty` | `string` | 消息ID
37+
`OpenKfID`| `open_kfid,omitempty` | `string` |客服账号ID(msgtype为event,该字段不返回)
38+
`ExternalUserID`| `external_userid,omitempty` | `string` |客客户UserID(msgtype为event,该字段不返回)
39+
`SendTime` | `send_time,omitempty` | `int64` | 消息发送时间
40+
`Origin` | `origin,omitempty` | `int` | 消息来源。3-微信客户发送的消息 4-系统推送的事件消息 5-接待人员在企业微信客户端发送的消息
41+
`ServicerUserID`| `servicer_userid,omitempty` | `string` |从企业微信给客户发消息的接待人员userid(即仅origin为5才返回;msgtype为event,该字段不返回)
42+
`MsgType` | `msgtype` | `MessageType` | 消息类型
43+
`Text` | `text,omitempty` | `Text` | 文本消息
44+
`Image` | `image,omitempty` | `Image` | 图片消息
45+
`Link` | `link,omitempty` | `Link` | 链接消息
46+
`MiniProgram` | `mini_program,omitempty` | `MiniProgram` | 小程序消息
47+
`Event` | `event,omitempty` | `KfEvent` | 事件类型
48+
49+
### `KfEvent` 客服会话事件
50+
51+
Name|JSON|Type|Doc
52+
:---|:--|:---|:--
53+
`EventType`|`event_type`|`KfEventType`|事件类型
54+
`OpenKfID`|`open_kfid`|`string`|客服账号ID
55+
`ExternalUserID`|`external_userid,omitempty`|`string`|客户UserID,注意不是企业成员的帐号
56+
`ServicerUserID`|`servicer_userid,omitempty`|`string`|接待人员userid
57+
`Scene`|`scene,omitempty`|`string`|用户进入会话事件特有。进入会话的场景值,获取客服账号链接开发者自定义的场景值
58+
`SceneParam`|`scene_param,omitempty`|`string`|用户进入会话事件特有。进入会话的自定义参数,获取客服账号链接返回的url,开发者按规范拼接的scene_param参数
59+
`WelcomeCode`|`welcome_code,omitempty`|`string`|用户进入会话事件特有。如果满足发送欢迎语条件(条件为:用户在过去48小时里未收过欢迎语,且未向客服发过消息),会返回该字段。可用该welcome_code调用发送事件响应消息接口给客户发送欢迎语。
60+
`WechatChannels`|`wechat_channels,omitempty`|`KfWechatChannels`|用户进入会话事件特有。进入会话的视频号信息,从视频号进入会话才有值
61+
`FailMsgID`|`fail_msgid,omitempty`|`string`|消息发送失败事件特有。发送失败的消息msgid
62+
`FailType`|`fail_type,omitempty`|`int`|消息发送失败事件特有。失败类型。0-未知原因 1-客服账号已删除 2-应用已关闭 4-会话已过期,超过48小时 5-会话已关闭 6-超过5条限制 8-主体未验证 10-用户拒收 11-企业未有成员登录企业微信App(排查方法:企业至少一个成员通过手机号验证/微信授权登录企业微信App即可)12-发送的消息为客服组件禁发的消息类型
63+
`Status`|`status,omitempty`|`int`|接待人员接待状态变更事件特有。状态类型。1-接待中 2-停止接待
64+
`StopType`|`stop_type,omitempty`|`int`|接待人员接待状态变更事件特有。接待人员的状态为「停止接待」的子类型。0:停止接待,1:暂时挂起
65+
`ChangeType`|`change_type,omitempty`|`KfServiceState`|会话状态变更事件特有。变更类型,均为接待人员在企业微信客户端操作触发。1-从接待池接入会话 2-转接会话 3-结束会话 4-重新接入已结束/已转接会话
66+
`OldServicerUserID`|`old_servicer_userid,omitempty`|`string`|会话状态变更事件特有。老的接待人员userid。仅change_type为2、3和4有值
67+
`NewServicerUserid`|`new_servicer_userid,omitempty`|`string`|会话状态变更事件特有。新的接待人员userid。仅change_type为1、2和4有值
68+
`MsgCode`|`msg_code,omitempty`|`string`|会话状态变更事件特有。用于发送事件响应消息的code,仅change_type为1和3时,会返回该字段。可用该msg_code调用发送事件响应消息接口给客户发送回复语或结束语。
69+
`RecallMsgID`|`recall_msgid,omitempty`|`string`|撤回消息事件特有。 撤回的消息msgid
70+
`RejectSwitch`|`reject_switch,omitempty`|`int`|拒收客户消息变更事件特有。 拒收客户消息,1表示接待人员拒收了客户消息,0表示接待人员取消拒收客户消息
71+
72+
### `KfWechatChannels` 进入会话的视频号信息,从视频号进入会话才有值
73+
74+
Name | JSON | Type | Doc
75+
:---------------|:--------------------------|:---------|:------------
76+
`NickName` | `nickname,omitempty` | `string` | 视频号名称,视频号场景值为1、2、3时返回此项
77+
`ShopNickName` | `shop_nickname,omitempty` | `string` | 视频号小店名称,视频号场景值为4、5时返回此项
78+
`Scene` | `scene` | `int64` | 视频号场景值。1:视频号主页,2:视频号直播间商品列表页,3:视频号商品橱窗页,4:视频号小店商品详情页,5:视频号小店订单页
79+
3280
```go
81+
// KfEventType 事件类型
82+
type KfEventType string
83+
84+
const (
85+
// KfEventTypeEnterSession 用户进入会话事件
86+
KfEventTypeEnterSession KfEventType = "enter_session"
87+
// KfEventTypeMsgSendFail 消息发送失败事件
88+
KfEventTypeMsgSendFail KfEventType = "msg_send_fail"
89+
// KfEventTypeServicerStatusChange 接待人员接待状态变更事件
90+
KfEventTypeServicerStatusChange KfEventType = "servicer_status_change"
91+
// KfEventTypeSessionStatusChange 会话状态变更事件
92+
KfEventTypeSessionStatusChange KfEventType = "session_status_change"
93+
// KfEventTypeUserRecallMsg 用户撤回消息事件
94+
KfEventTypeUserRecallMsg KfEventType = "user_recall_msg"
95+
// KfEventTypeServicerRecallMsg 接待人员撤回消息事件
96+
KfEventTypeServicerRecallMsg KfEventType = "servicer_recall_msg"
97+
// KfEventTypeRejectCustomerMsgSwitchChange 拒收客户消息变更事件
98+
KfEventTypeRejectCustomerMsgSwitchChange KfEventType = "reject_customer_msg_switch_change"
99+
)
100+
33101
// KfServiceState 客服会话状态
34102
//
35103
// 0 未处理 新会话接入

docs/rx_msg.md

+10
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,9 @@ const EventTypeSysApprovalChange EventType = "sys_approval_change"
5555
// EventTypeChangeContact 通讯录回调通知
5656
const EventTypeChangeContact EventType = "change_contact"
5757

58+
// EventTypeKfMsgOrEvent 客服回调通知
59+
const EventTypeKfMsgOrEvent EventType = "kf_msg_or_event"
60+
5861
// ChangeType 变更类型
5962
type ChangeType string
6063

@@ -297,6 +300,13 @@ Name|XML|Type|Doc
297300
:---|:--|:---|:--
298301
`EventKey`|`EventKey`|`string`|事件key
299302

303+
### `rxEventKfMsgOrEvent` 接受的事件消息,客服接收消息和事件
304+
305+
Name|XML|Type|Doc
306+
:---|:--|:---|:--
307+
`OpenKfID`|`OpenKfId`|`string`|有新消息的客服账号。可通过sync_msg接口指定open_kfid获取此客服账号的消息
308+
`Token`|`Token`|`string`|调用拉取消息接口时,需要传此token,用于校验请求的合法性
309+
300310
### `rxEventUnknown` 接受的事件消息,未定义的事件类型
301311

302312
Name|XML|Type|Doc

errcodes/mod.go

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

kf.go

+15
Original file line numberDiff line numberDiff line change
@@ -124,3 +124,18 @@ func (c *WorkwxApp) TransKfServiceState(openKfID, externalUserID, servicerUserID
124124
}
125125
return resp.MsgCode, nil
126126
}
127+
128+
// KfSyncMsg 微信客服获取消息列表
129+
func (c *WorkwxApp) KfSyncMsg(openKfID, token, cursor string, limit int64, voiceFormat int) ([]KfMsg, int, string, error) {
130+
resp, err := c.execKfSyncMsg(reqKfSyncMsg{
131+
OpenKfID: openKfID,
132+
Cursor: cursor,
133+
Token: token,
134+
Limit: limit,
135+
VoiceFormat: voiceFormat,
136+
})
137+
if err != nil {
138+
return nil, 0, "", err
139+
}
140+
return resp.MsgList, resp.HasMore, resp.NextCursor, nil
141+
}

kf.md.go

+99-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)