This repository was archived by the owner on Dec 22, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathwebhook.go
More file actions
104 lines (90 loc) · 2.88 KB
/
webhook.go
File metadata and controls
104 lines (90 loc) · 2.88 KB
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
package monday
// WebhooksService handles all the webhook related methods of the Monday API.
// A webhooks allows you to subscribe to events on your boards, and get notified by an HTTP post request to
// a specified URL with the event information as a payload.
//
// DOCS: https://monday.com/integrations/webhooks
type WebhooksService service
// Create returns a mutation that allows you to create a new webhook.
// After the mutation runs, the webhook will report the wanted event on the specific board given to the wanted URL.
// - id: the board's unique identifier.
// - url: the webhook URL.
// - event: the event to listen to (change_column_value / create_item / create_update).
//
// DOCS: https://monday.com/developers/v2#mutations-section-webhooks-create
func (*WebhooksService) Create(id int, url string, event WebhookEventType, webhookFields []WebhookField) Mutation {
if len(webhookFields) == 0 {
webhookFields = append(webhookFields, webhookIDField)
}
var fields []field
for _, wf := range webhookFields {
fields = append(fields, wf.field)
}
return Mutation{
name: "create_webhook",
fields: fields,
args: []argument{
{"board_id", id},
{"url", url},
{"event", event.typ},
},
}
}
// Delete returns a mutation that deletes a webhook.
// After the mutation runs it will no longer report events to the URL given.
// - id: the webhook's unique identifier.
//
// DOCS: https://monday.com/developers/v2#mutations-section-webhooks-delete
func (*WebhooksService) Delete(id int, webhookFields []WebhookField) Mutation {
if len(webhookFields) == 0 {
webhookFields = append(webhookFields, webhookIDField)
}
var fields []field
for _, wf := range webhookFields {
fields = append(fields, wf.field)
}
return Mutation{
name: "delete_webhook",
fields: fields,
args: []argument{
{"id", id},
},
}
}
// The webhook's graphql field(s).
type WebhookField struct {
field field
}
var (
webhookBoardIDField = WebhookField{field{"board_id", nil}}
webhookIDField = WebhookField{field{"id", nil}}
)
// The webhook's board id.
func WebhookBoardIDField() WebhookField {
return webhookBoardIDField
}
// The webhook's unique identifier.
func WebhookIDField() WebhookField {
return webhookIDField
}
// The webhook's target type.
type WebhookEventType struct {
typ string
}
var (
webhookEventTypeChangeColumnValue = WebhookEventType{"change_column_value"}
webhookEventTypeCreateItem = WebhookEventType{"create_item"}
webhookEventTypeCreateUpdate = WebhookEventType{"create_update"}
)
// Column value changed on board.
func WebhookEventTypeChangeColumnValue() WebhookEventType {
return webhookEventTypeChangeColumnValue
}
// An item was created on board.
func WebhookEventTypeCreateItem() WebhookEventType {
return webhookEventTypeCreateItem
}
// An update was posted on board item.
func WebhookEventTypeCreateUpdate() WebhookEventType {
return webhookEventTypeCreateUpdate
}