parse channel

This commit is contained in:
jiangyong27 2024-07-18 19:18:15 +08:00
parent ce73e3b561
commit c0d9ac7420
2 changed files with 24 additions and 1 deletions

View File

@ -52,6 +52,7 @@ type CustomerMessage struct {
Image *CustomerImage
Video *CustomerVideo
Voice *CustomerVoice
Channels *CustomerChannels
}
type CustomerServicer struct {
@ -69,6 +70,12 @@ type CustomerText struct {
MenuId string
}
type CustomerChannels struct {
Nickname string
Title string
SubType int
}
type CustomerImage struct {
MediaId string
}
@ -323,8 +330,23 @@ func (m *CustomerMessage) From(data map[string]interface{}) {
m.parseText(data)
} else if m.Msgtype == message.MsgTypeImage || m.Msgtype == message.MsgTypeVideo || m.Msgtype == message.MsgTypeVoice {
m.parseMedia(m.Msgtype, data)
} else if m.Msgtype == message.MsgTypeChannels {
m.parseChannels(data)
}
}
func (m *CustomerMessage) parseChannels(data map[string]interface{}) error {
channels, err := cast.ToStringMapE(data["channels"])
if err != nil {
return err
}
m.Channels = &CustomerChannels{
Title: cast.ToString(channels["title"]),
Nickname: cast.ToString(channels["nickname"]),
SubType: cast.ToInt(channels["sub_type"]),
}
return nil
}
func (m *CustomerMessage) parseEvent(data map[string]interface{}) error {
event, err := cast.ToStringMapE(data["event"])

View File

@ -35,7 +35,8 @@ const (
//MsgTypeTransfer 表示消息消息转发到客服
MsgTypeTransfer = "transfer_customer_service"
//MsgTypeEvent 表示事件推送消息
MsgTypeEvent = "event"
MsgTypeEvent = "event"
MsgTypeChannels = "channels"
)
const (