Skip to content

Commit

Permalink
feat(botgo): 新增进入aio事件 (merge request !96)
Browse files Browse the repository at this point in the history
Squash merge branch 'feat/20240805_ericyhbao_add_enter_aio_story_0' into 'master'
feat(botgo): 新增进入aio事件

--story=0
  • Loading branch information
ericyhbao committed Aug 23, 2024
1 parent 4854142 commit df169eb
Show file tree
Hide file tree
Showing 8 changed files with 49 additions and 1 deletion.
7 changes: 7 additions & 0 deletions dto/enter_aio.go
Original file line number Diff line number Diff line change
@@ -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的来源
}
8 changes: 7 additions & 1 deletion dto/keyboard/keyboard.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 每行结构
Expand Down
8 changes: 8 additions & 0 deletions dto/message_create.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 流式消息信息
Expand Down Expand Up @@ -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 模版参数 键值对
Expand Down
2 changes: 2 additions & 0 deletions dto/websocket_event.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ const (
EventSubscribeMsgStatus EventType = "SUBSCRIBE_MESSAGE_STATUS"
EventC2CFriendAdd EventType = "FRIEND_ADD"
EventC2CFriendDel EventType = "FRIEND_DEL"
EventEnterAIO EventType = "ENTER_AIO"
)

// intentEventMap 不同 intent 对应的事件定义
Expand All @@ -66,6 +67,7 @@ var intentEventMap = map[Intent][]EventType{
EventForumPostDelete, EventForumReplyCreate, EventForumReplyDelete, EventForumAuditResult,
},
IntentInteraction: {EventInteractionCreate},
IntentEnterAIO: {EventEnterAIO},
}

var eventIntentMap = transposeIntentEventMap(intentEventMap)
Expand Down
2 changes: 2 additions & 0 deletions dto/websocket_intent.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ const (
IntentDirectMessageReactions
IntentDirectMessageTyping

IntentEnterAIO Intent = 1 << 23 // 进入aio事件

// IntentGroupMessages 群消息事件
// - GROUP_AT_MESSAGE_CREATE // 群中@机器人时的消息
IntentGroupMessages Intent = 1 << 25 // 群消息事件
Expand Down
3 changes: 3 additions & 0 deletions dto/websocket_payload.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,3 +127,6 @@ type WSC2CFriendData C2CFriendData

// WSSubscribeMsgStatus 订阅消息模板授权状态变更事件
type WSSubscribeMsgStatus SubscribeMessageStatusData

// WSEnterAIOData 进入aio事件
type WSEnterAIOData EnterAIO
12 changes: 12 additions & 0 deletions event/event.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
}

Expand Down Expand Up @@ -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
}
8 changes: 8 additions & 0 deletions event/register.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ var DefaultHandlers struct {
C2CMessage C2CMessageEventHandler
SubscribeMsgStatus SubscribeMsgStatusEventHandler
C2CFriend C2CFriendEventHandler

EnterAIO EnterAIOEventHandler
}

// ReadyHandler 可以处理 ws 的 ready 事件
Expand Down Expand Up @@ -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
Expand All @@ -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:
}
}
Expand Down

0 comments on commit df169eb

Please sign in to comment.