From 2e0d5412b468654cc4a9236fbd413abcc2014cf7 Mon Sep 17 00:00:00 2001 From: Steven Date: Sat, 1 Jun 2024 23:46:00 +0800 Subject: [PATCH] chore: tweak webhook payload --- plugin/webhook/webhook.go | 28 +++++++++++++++++++--------- server/router/api/v1/memo_service.go | 6 +++++- 2 files changed, 24 insertions(+), 10 deletions(-) diff --git a/plugin/webhook/webhook.go b/plugin/webhook/webhook.go index 0aa34683396c3..b30659e7603fd 100644 --- a/plugin/webhook/webhook.go +++ b/plugin/webhook/webhook.go @@ -8,8 +8,6 @@ import ( "time" "github.com/pkg/errors" - - v1pb "github.com/usememos/memos/proto/gen/api/v1" ) var ( @@ -17,14 +15,26 @@ var ( timeout = 30 * time.Second ) +type Memo struct { + // The name of the memo. + // Format: memos/{id} + // id is the system generated id. + Name string + // The name of the creator. + // Format: users/{id} + Creator string + // The raw content. + Content string +} + // WebhookPayload is the payload of webhook request. // nolint type WebhookPayload struct { - URL string `json:"url"` - ActivityType string `json:"activityType"` - CreatorID int32 `json:"creatorId"` - CreatedTs int64 `json:"createdTs"` - Memo *v1pb.Memo `json:"memo"` + URL string `json:"url"` + ActivityType string `json:"activityType"` + CreatorID int32 `json:"creatorId"` + CreatedTs int64 `json:"createdTs"` + Memo *Memo `json:"memo"` } // WebhookResponse is the response of webhook request. @@ -40,8 +50,8 @@ func Post(payload WebhookPayload) error { if err != nil { return errors.Wrapf(err, "failed to marshal webhook request to %s", payload.URL) } - req, err := http.NewRequest("POST", - payload.URL, bytes.NewBuffer(body)) + + req, err := http.NewRequest("POST", payload.URL, bytes.NewBuffer(body)) if err != nil { return errors.Wrapf(err, "failed to construct webhook request to %s", payload.URL) } diff --git a/server/router/api/v1/memo_service.go b/server/router/api/v1/memo_service.go index 09e71d2cff71b..e40e4bad918a7 100644 --- a/server/router/api/v1/memo_service.go +++ b/server/router/api/v1/memo_service.go @@ -1224,6 +1224,10 @@ func convertMemoToWebhookPayload(memo *v1pb.Memo) (*webhook.WebhookPayload, erro return &webhook.WebhookPayload{ CreatorID: creatorID, CreatedTs: time.Now().Unix(), - Memo: memo, + Memo: &webhook.Memo{ + Name: memo.Name, + Creator: memo.Creator, + Content: memo.Content, + }, }, nil }