Skip to content

Commit ae86228

Browse files
committed
feat:支持发送欢迎语
1 parent 618a360 commit ae86228

File tree

2 files changed

+89
-0
lines changed

2 files changed

+89
-0
lines changed

sendmsgonevent.go

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
package WeChatCustomerServiceSDK
2+
3+
import (
4+
"encoding/json"
5+
"fmt"
6+
"github.com/NICEXAI/WeChatCustomerServiceSDK/util"
7+
)
8+
9+
const (
10+
// 发送事件响应消息
11+
sendMsgOnEventAddr = "https://qyapi.weixin.qq.com/cgi-bin/kf/send_msg_on_event?access_token=%s"
12+
)
13+
14+
// SendMsgOnEventSchema 发送事件响应消息
15+
type SendMsgOnEventSchema struct {
16+
BaseModel
17+
MsgID string `json:"msgid"` // 消息ID。如果请求参数指定了msgid,则原样返回,否则系统自动生成并返回。不多于32字节, 字符串取值范围(正则表达式):[0-9a-zA-Z_-]*
18+
}
19+
20+
// SendMsgOnEvent 发送事件响应消息
21+
//「进入会话事件」响应消息:
22+
// 如果满足通过API下发欢迎语条件(条件为:1. 企业没有在管理端配置了原生欢迎语;2. 用户在过去48小时里未收过欢迎语,且未向该用户发过消息),则用户进入会话事件会额外返回一个welcome_code,开发者以此为凭据调用接口(填到该接口code参数),即可向客户发送客服欢迎语。
23+
// 为了保证用户体验以及避免滥用,开发者仅可在收到相关事件后20秒内调用,且只可调用一次。
24+
func (r *Client) SendMsgOnEvent(options interface{}) (info SendMsgSchema, err error) {
25+
data, err := util.HttpPost(fmt.Sprintf(sendMsgOnEventAddr, r.accessToken), options)
26+
if err != nil {
27+
return info, err
28+
}
29+
_ = json.Unmarshal(data, &info)
30+
if info.ErrCode != 0 {
31+
return info, NewSDKErr(info.ErrCode, info.ErrMsg)
32+
}
33+
return info, nil
34+
}

sendmsgonevent/message.go

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
package sendmsgonevent
2+
3+
// Message 发送事件响应消息
4+
type Message struct {
5+
Code string `json:"code"` // 事件响应消息对应的code。通过事件回调下发,仅可使用一次。
6+
MsgID string `json:"msgid"` // 消息ID。如果请求参数指定了msgid,则原样返回,否则系统自动生成并返回。不多于32字节,不多于32字节
7+
}
8+
9+
// Text 文本消息
10+
type Text struct {
11+
Message
12+
MsgType string `json:"msgtype"` // 消息类型,此时固定为:text
13+
Text struct {
14+
Content string `json:"content"` // 消息内容,最长不超过2048个字节
15+
} `json:"text"` // 文本消息
16+
}
17+
18+
// Menu 发送菜单消息
19+
type Menu struct {
20+
Message
21+
MsgType string `json:"msgtype"` // 消息类型,此时固定为:msgmenu
22+
MsgMenu struct {
23+
HeadContent string `json:"head_content"` // 消息内容,不多于1024字节
24+
List []interface{} `json:"list"` // 菜单项配置
25+
TailContent string `json:"tail_content"` // 结束文本, 不多于1024字
26+
} `json:"msgmenu"`
27+
}
28+
29+
// MenuClick 回复菜单
30+
type MenuClick struct {
31+
Type string `json:"type"` // 菜单类型: click 回复菜单
32+
Click struct {
33+
ID string `json:"id"` // 菜单ID, 不少于1字节, 不多于64字节
34+
Content string `json:"content"` // 菜单显示内容, 不少于1字节, 不多于128字节
35+
} `json:"click"`
36+
}
37+
38+
// MenuView 超链接菜单
39+
type MenuView struct {
40+
Type string `json:"type"` // 菜单类型: view 超链接菜单
41+
View struct {
42+
URL string `json:"url"` // 点击后跳转的链接, 不少于1字节, 不多于2048字节
43+
Content string `json:"content"` // 菜单显示内容, 不少于1字节, 不多于1024字节
44+
} `json:"view"`
45+
}
46+
47+
// MenuMiniProgram 小程序菜单
48+
type MenuMiniProgram struct {
49+
Type string `json:"type"` // 菜单类型: miniprogram 小程序菜单
50+
MiniProgram struct {
51+
AppID string `json:"appid"` // 小程序appid, 不少于1字节, 不多于32字节
52+
PagePath string `json:"pagepath"` // 点击后进入的小程序页面, 不少于1字节, 不多于1024字节
53+
Content string `json:"content"` // 菜单显示内容, 不少于1字节, 不多于1024字节
54+
} `json:"miniprogram"`
55+
}

0 commit comments

Comments
 (0)