/
webhook.go
41 lines (35 loc) · 1.11 KB
/
webhook.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
package aws
import (
"encoding/json"
"time"
"github.com/reearth/reearth-cms/server/pkg/asset"
"github.com/reearth/reearth-cms/server/pkg/integrationapi"
"github.com/reearth/reearth-cms/server/pkg/task"
)
type webhookData struct {
URL string `json:"url"`
Secret string `json:"secret"`
Timestamp time.Time `json:"timestamp"`
WebhookID string `json:"webhookId"`
EventID string `json:"eventId"`
EventType string `json:"type"`
EventData any `json:"data"`
Operator integrationapi.Operator `json:"operator"`
}
func marshalWebhookData(w *task.WebhookPayload, urlResolver asset.URLResolver) ([]byte, error) {
ed, err := integrationapi.NewEventWith(w.Event, w.Override, "", urlResolver)
if err != nil {
return nil, err
}
d := webhookData{
URL: w.Webhook.URL().String(),
Secret: w.Webhook.Secret(),
Timestamp: ed.Timestamp,
WebhookID: w.Webhook.ID().String(),
EventID: ed.ID,
EventType: ed.Type,
EventData: ed.Data,
Operator: ed.Operator,
}
return json.Marshal(d)
}