Skip to content

Commit 2e0d541

Browse files
committed
chore: tweak webhook payload
1 parent 8c0bee3 commit 2e0d541

File tree

2 files changed

+24
-10
lines changed

2 files changed

+24
-10
lines changed

plugin/webhook/webhook.go

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,23 +8,33 @@ import (
88
"time"
99

1010
"github.com/pkg/errors"
11-
12-
v1pb "github.com/usememos/memos/proto/gen/api/v1"
1311
)
1412

1513
var (
1614
// timeout is the timeout for webhook request. Default to 30 seconds.
1715
timeout = 30 * time.Second
1816
)
1917

18+
type Memo struct {
19+
// The name of the memo.
20+
// Format: memos/{id}
21+
// id is the system generated id.
22+
Name string
23+
// The name of the creator.
24+
// Format: users/{id}
25+
Creator string
26+
// The raw content.
27+
Content string
28+
}
29+
2030
// WebhookPayload is the payload of webhook request.
2131
// nolint
2232
type WebhookPayload struct {
23-
URL string `json:"url"`
24-
ActivityType string `json:"activityType"`
25-
CreatorID int32 `json:"creatorId"`
26-
CreatedTs int64 `json:"createdTs"`
27-
Memo *v1pb.Memo `json:"memo"`
33+
URL string `json:"url"`
34+
ActivityType string `json:"activityType"`
35+
CreatorID int32 `json:"creatorId"`
36+
CreatedTs int64 `json:"createdTs"`
37+
Memo *Memo `json:"memo"`
2838
}
2939

3040
// WebhookResponse is the response of webhook request.
@@ -40,8 +50,8 @@ func Post(payload WebhookPayload) error {
4050
if err != nil {
4151
return errors.Wrapf(err, "failed to marshal webhook request to %s", payload.URL)
4252
}
43-
req, err := http.NewRequest("POST",
44-
payload.URL, bytes.NewBuffer(body))
53+
54+
req, err := http.NewRequest("POST", payload.URL, bytes.NewBuffer(body))
4555
if err != nil {
4656
return errors.Wrapf(err, "failed to construct webhook request to %s", payload.URL)
4757
}

server/router/api/v1/memo_service.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1224,6 +1224,10 @@ func convertMemoToWebhookPayload(memo *v1pb.Memo) (*webhook.WebhookPayload, erro
12241224
return &webhook.WebhookPayload{
12251225
CreatorID: creatorID,
12261226
CreatedTs: time.Now().Unix(),
1227-
Memo: memo,
1227+
Memo: &webhook.Memo{
1228+
Name: memo.Name,
1229+
Creator: memo.Creator,
1230+
Content: memo.Content,
1231+
},
12281232
}, nil
12291233
}

0 commit comments

Comments
 (0)