From a1adda144f785d35a3c83688688b88d086c094e0 Mon Sep 17 00:00:00 2001 From: Stinelle <1595191198@qq.com> Date: Thu, 5 Jun 2025 22:39:48 +0800 Subject: [PATCH 1/2] add:profile.view.get callback --- event/dispatcher/callback/event.go | 20 +++++++++++++++++ event/dispatcher/callback/model.go | 31 +++++++++++++++++++++++++++ event/dispatcher/callback_dispatch.go | 9 ++++++++ sample/event/event.go | 3 +++ 4 files changed, 63 insertions(+) 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..b143161e 100644 --- a/event/dispatcher/callback/model.go +++ b/event/dispatcher/callback/model.go @@ -105,3 +105,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 路由 From e9d04fd8319eb2229fc8f55c796785ef50f9b10e Mon Sep 17 00:00:00 2001 From: Stinelle <1595191198@qq.com> Date: Sun, 8 Jun 2025 23:10:53 +0800 Subject: [PATCH 2/2] =?UTF-8?q?fix:=E8=A1=A5=E4=B8=8A=E5=9C=A8=20profile?= =?UTF-8?q?=20=E5=8D=A1=E7=89=87=E8=A7=A6=E5=8F=91=E5=8D=A1=E7=89=87?= =?UTF-8?q?=E5=9B=9E=E4=BC=A0=E4=BA=A4=E4=BA=92=E5=9B=9E=E8=B0=83=EF=BC=8C?= =?UTF-8?q?=E5=9B=9E=E8=B0=83=E5=8D=8F=E8=AE=AE=E4=B8=AD=E7=BC=BA=E5=A4=B1?= =?UTF-8?q?=E7=9A=84=E5=AD=97=E6=AE=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- event/dispatcher/callback/model.go | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/event/dispatcher/callback/model.go b/event/dispatcher/callback/model.go index b143161e..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 {