-
Notifications
You must be signed in to change notification settings - Fork 1
/
notification.go
93 lines (81 loc) · 2.99 KB
/
notification.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
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
package monday
// NotificationsService handles all the notification related methods of the Monday API.
// Notifications are sent in the platform in response to various triggers such as due dates, updates, and more.
type NotificationsService service
// Create returns a mutation that allows to trigger a notification within the platform.
// Keep in mind that notifications are async and you will not be able to query their ID's back after sending then out.
// - userID: the user's unique identifier.
// - targetID: the target's unique identifier.
// - text: the notification text.
// - targetType: the target's type (project/post).
//
// DOCS: https://monday.com/developers/v2#mutations-section-notifications
func (*NotificationsService) Create(userID, targetID int, text string, targetType NotificationType, notificationFields []NotificationsField) Mutation {
if len(notificationFields) == 0 {
notificationFields = append(notificationFields, notificationTextField)
}
var fields []field
for _, nf := range notificationFields {
fields = append(fields, nf.field)
}
return Mutation{
name: "create_notification",
fields: fields,
args: []argument{
{"text", text},
{"user_id", userID},
{"target_id", targetID},
{"target_type", targetType},
},
}
}
// Create returns a mutation that allows to trigger a notification within the platform.
// Keep in mind that notifications are async and you will not be able to query their ID's back after sending then out.
// - userID: the user's unique identifier.
// - targetID: the target's unique identifier.
// - text: the notification text.
// - payload: the notification payload (JSON).
// - targetType: the target's type (project/post).
//
// DOCS: https://monday.com/developers/v2#mutations-section-notifications
func CreateWithPayload(userID, targetID int, text, payload string, targetType NotificationType, notificationFields []NotificationsField) Mutation {
notification := Notifications.Create(userID, targetID, text, targetType, notificationFields)
notification.args = append(notification.args, argument{"payload", payload})
return notification
}
// The notification's graphql field(s).
type NotificationsField struct {
field field
}
var (
notificationIDField = NotificationsField{field{"id", nil}}
notificationTextField = NotificationsField{field{"text", nil}}
)
// The notification's unique identifier.
func NotificationIDField() NotificationsField {
return notificationIDField
}
// The notification text.
func NotificationTextField() NotificationsField {
return notificationTextField
}
// The notification's graphql argument(s).
type NotificationArgument struct {
arg argument
}
// The notification's target type.
type NotificationType struct {
kind string
}
var (
notificationTypeProject = NotificationType{"project"}
notificationTypePost = NotificationType{"post"}
)
// Pulse or Board.
func NotificationTypeProject() NotificationType {
return notificationTypeProject
}
// Update.
func NotificationTypePost() NotificationType {
return notificationTypePost
}