diff --git a/event/dispatcher/callback/event.go b/event/dispatcher/callback/event.go index b6861729..66f99fcc 100644 --- a/event/dispatcher/callback/event.go +++ b/event/dispatcher/callback/event.go @@ -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)) +} diff --git a/event/dispatcher/callback/model.go b/event/dispatcher/callback/model.go index 97160f28..f8b7afa1 100644 --- a/event/dispatcher/callback/model.go +++ b/event/dispatcher/callback/model.go @@ -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 { @@ -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 { @@ -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"` +} diff --git a/event/dispatcher/callback_dispatch.go b/event/dispatcher/callback_dispatch.go index ce41917c..069563d0 100644 --- a/event/dispatcher/callback_dispatch.go +++ b/event/dispatcher/callback_dispatch.go @@ -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 +} diff --git a/sample/event/event.go b/sample/event/event.go index 843eeeee..a7e43e27 100644 --- a/sample/event/event.go +++ b/sample/event/event.go @@ -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 路由