1
0
mirror of https://github.com/silenceper/wechat.git synced 2026-02-04 12:52:27 +08:00
Files
wechat/work/kf/sendmsgonevent.go
Afeyer d776f5c400 feat:微信客服支持向客户发送欢迎语 (#478)
* feat:微信客服支持向客户发送欢迎语

* chore: go fmt file

* feat:移除空白文件
2021-09-13 10:07:18 +08:00

46 lines
1.6 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
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
}