diff --git a/dto/enter_aio.go b/dto/enter_aio.go new file mode 100644 index 0000000..6aebcdd --- /dev/null +++ b/dto/enter_aio.go @@ -0,0 +1,7 @@ +package dto + +// EnterAIO 进入aio的事件 +type EnterAIO struct { + UserOpenid string `json:"user_openid,omitempty"` // 用户openid + FromSource string `json:"from_source,omitempty"` // 进入aio的来源 +} diff --git a/dto/keyboard/keyboard.go b/dto/keyboard/keyboard.go index d9a5693..71c5283 100644 --- a/dto/keyboard/keyboard.go +++ b/dto/keyboard/keyboard.go @@ -37,7 +37,13 @@ type MessageKeyboard struct { // CustomKeyboard 自定义 Keyboard type CustomKeyboard struct { - Rows []*Row `json:"rows,omitempty"` // 行数组 + Rows []*Row `json:"rows,omitempty"` // 行数组 + Style *KeyboardStyle `json:"style,omitempty"` // 按钮样式 +} + +// KeyboardStyle 键盘样式 +type KeyboardStyle struct { + FontSize string `json:"font_size,omitempty"` // 字体大小 } // Row 每行结构 diff --git a/dto/message_create.go b/dto/message_create.go index b1a27a6..bf14a6d 100644 --- a/dto/message_create.go +++ b/dto/message_create.go @@ -71,6 +71,7 @@ type MessageToCreate struct { PromptKeyboard *PromptKeyboard `json:"prompt_keyboard,omitempty"` // 消息扩展信息 ActionButton *ActionButton `json:"action_button,omitempty"` // 消息操作结构 Stream *Stream `json:"stream,omitempty"` // 流式消息信息 + FeatureID uint `json:"feature_id,omitempty"` // 控制消息发送 } // Stream 流式消息信息 @@ -128,6 +129,13 @@ type Markdown struct { CustomTemplateID string `json:"custom_template_id"` // 自定义模板id Params []*MarkdownParams `json:"params"` // 模版参数 Content string `json:"content"` // 原生 markdown + Style *MarkdownStyle `json:"style"` // markdown样式 +} + +// MarkdownStyle markdown 样式 +type MarkdownStyle struct { + MainFontSize string `json:"main_font_size"` // 正文字体大小 small middle large + Layout string `json:"layout"` // hide_avatar_and_center 隐藏头像并居中 } // MarkdownParams markdown 模版参数 键值对 diff --git a/dto/websocket_event.go b/dto/websocket_event.go index 0f35879..4414a8e 100644 --- a/dto/websocket_event.go +++ b/dto/websocket_event.go @@ -43,6 +43,7 @@ const ( EventSubscribeMsgStatus EventType = "SUBSCRIBE_MESSAGE_STATUS" EventC2CFriendAdd EventType = "FRIEND_ADD" EventC2CFriendDel EventType = "FRIEND_DEL" + EventEnterAIO EventType = "ENTER_AIO" ) // intentEventMap 不同 intent 对应的事件定义 @@ -66,6 +67,7 @@ var intentEventMap = map[Intent][]EventType{ EventForumPostDelete, EventForumReplyCreate, EventForumReplyDelete, EventForumAuditResult, }, IntentInteraction: {EventInteractionCreate}, + IntentEnterAIO: {EventEnterAIO}, } var eventIntentMap = transposeIntentEventMap(intentEventMap) diff --git a/dto/websocket_intent.go b/dto/websocket_intent.go index d5903fa..4566823 100644 --- a/dto/websocket_intent.go +++ b/dto/websocket_intent.go @@ -43,6 +43,8 @@ const ( IntentDirectMessageReactions IntentDirectMessageTyping + IntentEnterAIO Intent = 1 << 23 // 进入aio事件 + // IntentGroupMessages 群消息事件 // - GROUP_AT_MESSAGE_CREATE // 群中@机器人时的消息 IntentGroupMessages Intent = 1 << 25 // 群消息事件 diff --git a/dto/websocket_payload.go b/dto/websocket_payload.go index 58f1ab1..9aabd36 100644 --- a/dto/websocket_payload.go +++ b/dto/websocket_payload.go @@ -127,3 +127,6 @@ type WSC2CFriendData C2CFriendData // WSSubscribeMsgStatus 订阅消息模板授权状态变更事件 type WSSubscribeMsgStatus SubscribeMessageStatusData + +// WSEnterAIOData 进入aio事件 +type WSEnterAIOData EnterAIO diff --git a/event/event.go b/event/event.go index 1c5994b..31cb5d7 100644 --- a/event/event.go +++ b/event/event.go @@ -60,6 +60,7 @@ var eventParseFuncMap = map[dto.OPCode]map[dto.EventType]eventParseFunc{ dto.EventSubscribeMsgStatus: subscribeStatusHandler, dto.EventC2CFriendAdd: c2cFriendAddHandler, dto.EventC2CFriendDel: c2cFriendDelHandler, + dto.EventEnterAIO: enterAIOHandler, }, } @@ -342,3 +343,14 @@ func interactionHandler(payload *dto.WSPayload, message []byte) error { } return nil } + +func enterAIOHandler(payload *dto.WSPayload, message []byte) error { + data := &dto.WSEnterAIOData{} + if err := ParseData(message, data); err != nil { + return err + } + if DefaultHandlers.EnterAIO != nil { + return DefaultHandlers.EnterAIO(payload, data) + } + return nil +} diff --git a/event/register.go b/event/register.go index 5849475..0949e2a 100644 --- a/event/register.go +++ b/event/register.go @@ -36,6 +36,8 @@ var DefaultHandlers struct { C2CMessage C2CMessageEventHandler SubscribeMsgStatus SubscribeMsgStatusEventHandler C2CFriend C2CFriendEventHandler + + EnterAIO EnterAIOEventHandler } // ReadyHandler 可以处理 ws 的 ready 事件 @@ -117,6 +119,9 @@ type C2CFriendEventHandler func(event *dto.WSPayload, data *dto.WSC2CFriendData) // SubscribeMsgStatusEventHandler 订阅消息模板授权状态变更事件 handler type SubscribeMsgStatusEventHandler func(event *dto.WSPayload, data *dto.WSSubscribeMsgStatus) error +// EnterAIOEventHandler 进入AIO事件 handler +type EnterAIOEventHandler func(event *dto.WSPayload, data *dto.WSEnterAIOData) error + // RegisterHandlers 注册事件回调,并返回 intent 用于 websocket 的鉴权 func RegisterHandlers(handlers ...interface{}) dto.Intent { var i dto.Intent @@ -143,6 +148,9 @@ func RegisterHandlers(handlers ...interface{}) dto.Intent { case C2CFriendEventHandler: DefaultHandlers.C2CFriend = handle i = i | dto.EventToIntent(dto.EventC2CFriendAdd) + case EnterAIOEventHandler: + DefaultHandlers.EnterAIO = handle + i = i | dto.EventToIntent(dto.EventEnterAIO) default: } }