微信客服

概述

客服帐号管理

添加客服帐号

  1. mediaID := "294DpAog3YA5b9rT`K4PjjfRfYLO0L5qpDHAJIzhhQ2jAEWjb9i661Q4lk8oFnPtmj"
  2. WeComApp.AccountService.Add(ctx,"新建的客服帐号", mediaID)

微信官方文档

删除客服帐号

  1. openKFID := "wkAJ2GCAAAZSfhHCt7IFSvLKtMPxyJTw"
  2. WeComApp.AccountService.Del(ctx,openKFID)

微信官方文档

修改客服帐号

  1. options := &request.RequestAccountUpdate{
  2. ctx,
  3. OpenKFID: "wkAJ2GCAAAZSfhHCt7IFSvLKtMPxyJTw",
  4. Name: "修改客服名",
  5. MediaID: "294DpAog3YA5b9rTK4PjjfRfYLO0L5qpDHAJIzhhQ2jAEWjb9i661Q4lk8oFnPtmj",
  6. }
  7. WeComApp.AccountService.Update(ctx,options)

微信官方文档

获取客服帐号列表

  1. WeComApp.AccountService.List(ctx)

微信官方文档

获取客服帐号链接

  1. openKFID := "wkAJ2GCAAAZSfhHCt7IFSvLKtMPxyJTw"
  2. scene := "1234"
  3. WeComApp.AccountService.AddContactWay(openKFID, scene)

微信官方文档

接待人员管理

添加接待人员

  1. openKFID := "kfxxxxxxxxxxxxxx"
  2. userIDList := []string{"zhangsan", "lisi"}
  3. WeComApp.AccountServiceServicer.Add(ctx,openKFID, userIDList)

微信官方文档

删除接待人员

  1. openKFID := "kfxxxxxxxxxxxxxx"
  2. userIDList := []string{"zhangsan", "lisi"}
  3. WeComApp.AccountServiceServicer.Del(ctx,openKFID, userIDList)

微信官方文档

获取接待人员列表

  1. openKFID := "kfxxxxxxxxxxxxxx"
  2. WeComApp.AccountServiceServicer.List(ctx,openKFID)

微信官方文档

会话分配与消息收发

分配客服会话

获取会话状态

  1. openKFID := "kfxxxxxxxxxxxxxx"
  2. externalUserID := "wmxxxxxxxxxxxxxxxxxx"
  3. WeComApp.AccountServiceState.Get(ctx,openKFID, externalUserID)

变更会话状态

  1. openKFID := "wkxxxxxxxxxxxxxxxxxx"
  2. externalUserID := "wmxxxxxxxxxxxxxxxxxx"
  3. serviceState := 3
  4. servicerUserID := "zhangsan"
  5. WeComApp.AccountServiceState.Trans(ctx,openKFID, externalUserID,serviceState,servicerUserID)

微信官方文档

接收消息和事件

当微信客户、接待人员发消息或有行为动作时,企业微信后台会将事件的回调数据包发送到企业指定URL;企业收到请求后,再通过读取消息接口主动读取具体的消息内容。

回调事件

接收并解析事件的方法见:接收事件 (TODO: 这里需要改成docs的连接)。

读取消息

  1. cursor := "4gw7MepFLfgF2VC5npN"
  2. token := "ENCApHxnGDNAVNY4AaSJKj4Tb5mwsEMzxhFmHVGcra996NR"
  3. limit := 1000
  4. WeComApp.AccountServiceMessage.SyncMsg(ctx,cursor, token, limit)

微信官方文档

发送消息

  1. options := &request.RequestAccountServiceSendMsg{
  2. ctx,
  3. ToUser: "EXTERNAL_USERID",
  4. OpenKfid: "kfxxxxxxxxxxxxxx",
  5. MsgID: "MSGID",
  6. MsgType: "text",
  7. Text: request.RequestAccountServiceMsgText{
  8. Content: "你购买的物品已发货,可点击链接查看物流状态http://work.weixin.qq.com/xxxxxx",
  9. },
  10. }
  11. WeComApp.AccountServiceMessage.SendMsg(options)

微信官方文档

发送事件响应消息

  1. options := &request.RequestAccountServiceSendMsgOnEvent{
  2. ctx,
  3. Code: "CODE",
  4. MsgID: "MSG_ID",
  5. MsgType: "text", // 对应的消息体字段,目前支持文本与菜单消息,详见下文
  6. Text: request.RequestAccountServiceMsgText{
  7. Content: "欢迎咨询",
  8. },
  9. }
  10. WeComApp.AccountServiceMessage.SendMsgOnEvent(options)

微信官方文档

「升级服务」配置

获取配置的专员与客户群

  1. WeComApp.AccountServiceCustomer.GetUpgradeServiceConfig(ctx)

为客户升级为专员或客户群服务

  1. options := &request.RequestUpgradeService{
  2. ctx,
  3. OpenKFID: c.DefaultQuery("openKFID", "kfxxxxxxxxxxxxxx"),
  4. ExternalUserID: c.DefaultQuery("externalUserID", "wmxxxxxxxxxxxxxxxxxx"),
  5. Type: 2,
  6. Member: &request.RequestUpgradeServiceMember{
  7. UserID: c.DefaultQuery("member", "matrix-x"),
  8. Wording: "你好,我是你的专属服务专员zhangsan",
  9. }, // 推荐的服务专员,type等于1时有效
  10. GroupChat: &request.RequestUpgradeServiceGroupChat{
  11. ChatID: "wraaaaaaaaaaaaaaaa",
  12. Wording: "欢迎加入你的专属服务群",
  13. }, // 推荐的客户群,type等于2时有效
  14. }
  15. WeComApp.AccountServiceCustomer.UpgradeService(options)

为客户取消推荐

  1. openKFID := "kfxxxxxxxxxxxxxx"
  2. externalUserID := "wmxxxxxxxxxxxxxxxxxx"
  3. WeComApp.AccountServiceCustomer.CancelUpgradeService(openKFID, externalUserID)

微信官方文档

其他基础信息获取

获取客户基础信息

  1. externalUserIDList := []string{"externalUserIDList", "matrix-x"}
  2. WeComApp.AccountServiceCustomer.BatchGet(externalUserIDList)

微信官方文档

使用示例

参考:PowerWechatTutorial