1
0
mirror of https://github.com/silenceper/wechat.git synced 2026-02-10 07:42:26 +08:00

feat:微信客服支持向客户发送欢迎语 (#478)

* feat:微信客服支持向客户发送欢迎语

* chore: go fmt file

* feat:移除空白文件
This commit is contained in:
Afeyer
2021-09-13 10:07:18 +08:00
committed by GitHub
parent bc9f483c8e
commit d776f5c400
3 changed files with 101 additions and 0 deletions

45
work/kf/sendmsgonevent.go Normal file
View File

@@ -0,0 +1,45 @@
package kf
import (
"encoding/json"
"fmt"
"github.com/silenceper/wechat/v2/util"
)
const (
// 发送事件响应消息
sendMsgOnEventAddr = "https://qyapi.weixin.qq.com/cgi-bin/kf/send_msg_on_event?access_token=%s"
)
// SendMsgOnEventSchema 发送事件响应消息
type SendMsgOnEventSchema struct {
util.CommonError
MsgID string `json:"msgid"` // 消息ID。如果请求参数指定了msgid则原样返回否则系统自动生成并返回。不多于32字节, 字符串取值范围(正则表达式)[0-9a-zA-Z_-]*
}
// SendMsgOnEvent 发送事件响应消息
//「进入会话事件」响应消息:
// 如果满足通过API下发欢迎语条件条件为1. 企业没有在管理端配置了原生欢迎语2. 用户在过去48小时里未收过欢迎语且未向该用户发过消息则用户进入会话事件会额外返回一个welcome_code开发者以此为凭据调用接口填到该接口code参数即可向客户发送客服欢迎语。
// 为了保证用户体验以及避免滥用开发者仅可在收到相关事件后20秒内调用且只可调用一次。
func (r *Client) SendMsgOnEvent(options interface{}) (info SendMsgOnEventSchema, err error) {
var (
accessToken string
data []byte
)
accessToken, err = r.ctx.GetAccessToken()
if err != nil {
return
}
data, err = util.PostJSON(fmt.Sprintf(sendMsgOnEventAddr, accessToken), options)
if err != nil {
return
}
if err = json.Unmarshal(data, &info); err != nil {
return
}
if info.ErrCode != 0 {
return info, NewSDKErr(info.ErrCode, info.ErrMsg)
}
return info, nil
}