-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
89 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package WeChatCustomerServiceSDK | ||
|
||
import ( | ||
"encoding/json" | ||
"fmt" | ||
"github.com/NICEXAI/WeChatCustomerServiceSDK/util" | ||
) | ||
|
||
const ( | ||
// 发送事件响应消息 | ||
sendMsgOnEventAddr = "https://qyapi.weixin.qq.com/cgi-bin/kf/send_msg_on_event?access_token=%s" | ||
) | ||
|
||
// SendMsgOnEventSchema 发送事件响应消息 | ||
type SendMsgOnEventSchema struct { | ||
BaseModel | ||
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 SendMsgSchema, err error) { | ||
data, err := util.HttpPost(fmt.Sprintf(sendMsgOnEventAddr, r.accessToken), options) | ||
if err != nil { | ||
return info, err | ||
} | ||
_ = json.Unmarshal(data, &info) | ||
if info.ErrCode != 0 { | ||
return info, NewSDKErr(info.ErrCode, info.ErrMsg) | ||
} | ||
return info, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
package sendmsgonevent | ||
|
||
// Message 发送事件响应消息 | ||
type Message struct { | ||
Code string `json:"code"` // 事件响应消息对应的code。通过事件回调下发,仅可使用一次。 | ||
MsgID string `json:"msgid"` // 消息ID。如果请求参数指定了msgid,则原样返回,否则系统自动生成并返回。不多于32字节,不多于32字节 | ||
} | ||
|
||
// Text 文本消息 | ||
type Text struct { | ||
Message | ||
MsgType string `json:"msgtype"` // 消息类型,此时固定为:text | ||
Text struct { | ||
Content string `json:"content"` // 消息内容,最长不超过2048个字节 | ||
} `json:"text"` // 文本消息 | ||
} | ||
|
||
// Menu 发送菜单消息 | ||
type Menu struct { | ||
Message | ||
MsgType string `json:"msgtype"` // 消息类型,此时固定为:msgmenu | ||
MsgMenu struct { | ||
HeadContent string `json:"head_content"` // 消息内容,不多于1024字节 | ||
List []interface{} `json:"list"` // 菜单项配置 | ||
TailContent string `json:"tail_content"` // 结束文本, 不多于1024字 | ||
} `json:"msgmenu"` | ||
} | ||
|
||
// MenuClick 回复菜单 | ||
type MenuClick struct { | ||
Type string `json:"type"` // 菜单类型: click 回复菜单 | ||
Click struct { | ||
ID string `json:"id"` // 菜单ID, 不少于1字节, 不多于64字节 | ||
Content string `json:"content"` // 菜单显示内容, 不少于1字节, 不多于128字节 | ||
} `json:"click"` | ||
} | ||
|
||
// MenuView 超链接菜单 | ||
type MenuView struct { | ||
Type string `json:"type"` // 菜单类型: view 超链接菜单 | ||
View struct { | ||
URL string `json:"url"` // 点击后跳转的链接, 不少于1字节, 不多于2048字节 | ||
Content string `json:"content"` // 菜单显示内容, 不少于1字节, 不多于1024字节 | ||
} `json:"view"` | ||
} | ||
|
||
// MenuMiniProgram 小程序菜单 | ||
type MenuMiniProgram struct { | ||
Type string `json:"type"` // 菜单类型: miniprogram 小程序菜单 | ||
MiniProgram struct { | ||
AppID string `json:"appid"` // 小程序appid, 不少于1字节, 不多于32字节 | ||
PagePath string `json:"pagepath"` // 点击后进入的小程序页面, 不少于1字节, 不多于1024字节 | ||
Content string `json:"content"` // 菜单显示内容, 不少于1字节, 不多于1024字节 | ||
} `json:"miniprogram"` | ||
} |