Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
C
canifa_note
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Vũ Hoàng Anh
canifa_note
Commits
2e0d5412
Commit
2e0d5412
authored
Jun 01, 2024
by
Steven
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
chore: tweak webhook payload
parent
8c0bee38
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
24 additions
and
10 deletions
+24
-10
webhook.go
plugin/webhook/webhook.go
+19
-9
memo_service.go
server/router/api/v1/memo_service.go
+5
-1
No files found.
plugin/webhook/webhook.go
View file @
2e0d5412
...
@@ -8,8 +8,6 @@ import (
...
@@ -8,8 +8,6 @@ import (
"time"
"time"
"github.com/pkg/errors"
"github.com/pkg/errors"
v1pb
"github.com/usememos/memos/proto/gen/api/v1"
)
)
var
(
var
(
...
@@ -17,6 +15,18 @@ var (
...
@@ -17,6 +15,18 @@ var (
timeout
=
30
*
time
.
Second
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.
// WebhookPayload is the payload of webhook request.
// nolint
// nolint
type
WebhookPayload
struct
{
type
WebhookPayload
struct
{
...
@@ -24,7 +34,7 @@ type WebhookPayload struct {
...
@@ -24,7 +34,7 @@ type WebhookPayload struct {
ActivityType
string
`json:"activityType"`
ActivityType
string
`json:"activityType"`
CreatorID
int32
`json:"creatorId"`
CreatorID
int32
`json:"creatorId"`
CreatedTs
int64
`json:"createdTs"`
CreatedTs
int64
`json:"createdTs"`
Memo
*
v1pb
.
Memo
`json:"memo"`
Memo
*
Memo
`json:"memo"`
}
}
// WebhookResponse is the response of webhook request.
// WebhookResponse is the response of webhook request.
...
@@ -40,8 +50,8 @@ func Post(payload WebhookPayload) error {
...
@@ -40,8 +50,8 @@ func Post(payload WebhookPayload) error {
if
err
!=
nil
{
if
err
!=
nil
{
return
errors
.
Wrapf
(
err
,
"failed to marshal webhook request to %s"
,
payload
.
URL
)
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
{
if
err
!=
nil
{
return
errors
.
Wrapf
(
err
,
"failed to construct webhook request to %s"
,
payload
.
URL
)
return
errors
.
Wrapf
(
err
,
"failed to construct webhook request to %s"
,
payload
.
URL
)
}
}
...
...
server/router/api/v1/memo_service.go
View file @
2e0d5412
...
@@ -1224,6 +1224,10 @@ func convertMemoToWebhookPayload(memo *v1pb.Memo) (*webhook.WebhookPayload, erro
...
@@ -1224,6 +1224,10 @@ func convertMemoToWebhookPayload(memo *v1pb.Memo) (*webhook.WebhookPayload, erro
return
&
webhook
.
WebhookPayload
{
return
&
webhook
.
WebhookPayload
{
CreatorID
:
creatorID
,
CreatorID
:
creatorID
,
CreatedTs
:
time
.
Now
()
.
Unix
(),
CreatedTs
:
time
.
Now
()
.
Unix
(),
Memo
:
memo
,
Memo
:
&
webhook
.
Memo
{
Name
:
memo
.
Name
,
Creator
:
memo
.
Creator
,
Content
:
memo
.
Content
,
},
},
nil
},
nil
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment