Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions event/dispatcher/callback/event.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,23 @@ func (h *URLPreviewGetEventHandler) Event() interface{} {
func (h *URLPreviewGetEventHandler) Handle(ctx context.Context, event interface{}) (interface{}, error) {
return h.handler(ctx, event.(*URLPreviewGetEvent))
}

// 消息处理器定义
type ProfileViewGetEventHandler struct {
handler func(context.Context, *ProfileViewGetEvent) (*ProfileViewGetResponse, error)
}

func NewProfileViewGetEventHandler(handler func(context.Context, *ProfileViewGetEvent) (*ProfileViewGetResponse, error)) *ProfileViewGetEventHandler {
h := &ProfileViewGetEventHandler{handler: handler}
return h
}

// 返回事件的消息体的实例,用于反序列化用
func (h *ProfileViewGetEventHandler) Event() interface{} {
return &ProfileViewGetEvent{}
}

// 回调开发者注册的handle
func (h *ProfileViewGetEventHandler) Handle(ctx context.Context, event interface{}) (interface{}, error) {
return h.handler(ctx, event.(*ProfileViewGetEvent))
}
54 changes: 44 additions & 10 deletions event/dispatcher/callback/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,13 @@ func (m *CardActionTriggerEvent) RawReq(req *larkevent.EventReq) {
}

type CardActionTriggerRequest struct {
Operator *Operator `json:"operator,omitempty"`
Token string `json:"token,omitempty"` // 更新卡片用的token(凭证)
Action *CallBackAction `json:"action,omitempty"`
Host string `json:"host,omitempty"` // 宿主: im_message/im_top_notice
DeliveryType string `json:"delivery_type,omitempty"` // 卡片发送渠道: url_preview/
Context *Context `json:"context,omitempty"`
Operator *Operator `json:"operator,omitempty"`
Token string `json:"token,omitempty"` // 更新卡片用的token(凭证)
Action *CallBackAction `json:"action,omitempty"`
Host string `json:"host,omitempty"` // 宿主: im_message/im_top_notice
DeliveryType string `json:"delivery_type,omitempty"` // 卡片发送渠道: url_preview/
Context *Context `json:"context,omitempty"`
Observer *ProfileViewGetOperator `json:"observer,omitempty"`
}

type Operator struct {
Expand All @@ -40,10 +41,12 @@ type CallBackAction struct {
}

type Context struct {
URL string `json:"url,omitempty"`
PreviewToken string `json:"preview_token,omitempty"`
OpenMessageID string `json:"open_message_id,omitempty"`
OpenChatID string `json:"open_chat_id,omitempty"`
URL string `json:"url,omitempty"`
PreviewToken string `json:"preview_token,omitempty"`
OpenMessageID string `json:"open_message_id,omitempty"`
OpenChatID string `json:"open_chat_id,omitempty"`
Owner *ProfileViewGetOperator `json:"owner,omitempty"`
ProfileSceneID *string `json:"profile_scene_id,omitempty"`
}

type CardActionTriggerResponse struct {
Expand Down Expand Up @@ -105,3 +108,34 @@ type URL struct {
PC string `json:"pc,omitempty"`
Web string `json:"web,omitempty"`
}

type ProfileViewGetEvent struct {
*larkevent.EventV2Base // 事件基础数据
*larkevent.EventReq // 请求原生数据
Event *ProfileViewGetRequest `json:"event"` // 事件内容
}

func (m *ProfileViewGetEvent) RawReq(req *larkevent.EventReq) {
m.EventReq = req
}

type ProfileViewGetRequest struct {
ProfileSceneID string `json:"profile_scene_id,omitempty"`
Observer *ProfileViewGetOperator `json:"observer,omitempty"`
Owner *ProfileViewGetOperator `json:"owner,omitempty"`
}

type ProfileViewGetResponse struct {
Card *Card `json:"card,omitempty"`
}

type ProfileViewGetOperator struct {
TenantKey *string `json:"tenant_key,omitempty"`
ID *UserIDList `json:"id,omitempty"`
}

type UserIDList struct {
UserID *string `json:"user_id,omitempty"`
OpenID string `json:"open_id,omitempty"`
UnionID *string `json:"union_id,omitempty"`
}
9 changes: 9 additions & 0 deletions event/dispatcher/callback_dispatch.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,12 @@ func (dispatcher *EventDispatcher) OnP2CardURLPreviewGet(handler func(ctx contex
dispatcher.callbackType2CallbackHandler["url.preview.get"] = callback.NewURLPreviewGetEventHandler(handler)
return dispatcher
}

func (dispatcher *EventDispatcher) OnP2CardProfileViewGet(handler func(ctx context.Context, event *callback.ProfileViewGetEvent) (*callback.ProfileViewGetResponse, error)) *EventDispatcher {
_, existed := dispatcher.callbackType2CallbackHandler["profile.view.get"]
if existed {
panic("event: multiple handler registrations for " + "profile.view.get")
}
dispatcher.callbackType2CallbackHandler["profile.view.get"] = callback.NewProfileViewGetEventHandler(handler)
return dispatcher
}
3 changes: 3 additions & 0 deletions sample/event/event.go
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,9 @@ func main() {
}).OnP2CardURLPreviewGet(func(ctx context.Context, event *callback.URLPreviewGetEvent) (*callback.URLPreviewGetResponse, error) {
fmt.Println(event)
return nil, nil
}).OnP2CardProfileViewGet(func(ctx context.Context, event *callback.ProfileViewGetEvent) (*callback.ProfileViewGetResponse, error) {
fmt.Println(event)
return nil, nil
})

// 注册 http 路由
Expand Down