-
Notifications
You must be signed in to change notification settings - Fork 6
/
structures.go
194 lines (167 loc) · 6.04 KB
/
structures.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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
// Package webhooks implements handlers and definitions of LiveChat webhooks.
//
// General LiveChat webhooks documentation is available here:
// https://developers.livechatinc.com/docs/management/configuration-api/#webhooks
package webhooks
import (
"encoding/json"
"github.com/livechat/lc-sdk-go/objects"
)
// WebhookBase represents general webhook format.
type WebhookBase struct {
WebhookID string `json:"webhook_id"`
SecretKey string `json:"secret_key"`
Action string `json:"action"`
Payload json.RawMessage `json:"payload"`
AdditionalData json.RawMessage `json:"additional_data"`
}
// IncomingChatThread represents payload of incoming_chat_thread webhook.
type IncomingChatThread struct {
Chat objects.Chat `json:"chat"`
}
// ThreadClosed represents payload of thread_closed webhook.
type ThreadClosed struct {
ChatID string `json:"chat_id"`
ThreadID string `json:"thread_id"`
UserID string `json:"user_id"`
}
// AccessGranted represents payload of access_granted webhook.
type AccessGranted struct {
Resource string `json:"resource"`
ID string `json:"id"`
Access objects.Access `json:"access"`
}
// AccessRevoked represents payload of access_revoked webhook.
type AccessRevoked struct {
Resource string `json:"resource"`
ID string `json:"id"`
Access objects.Access `json:"access"`
}
// AccessSet represents payload of access_set webhook.
type AccessSet struct {
Resource string `json:"resource"`
ID string `json:"id"`
Access objects.Access `json:"access"`
}
// ChatUserAdded represents payload of chat_user_added webhook.
type ChatUserAdded struct {
ChatID string `json:"chat_id"`
ThreadID string `json:"thread_id"`
User objects.User `json:"user"`
UserType string `json:"user_type"`
}
// ChatUserRemoved represents payload of chat_user_removed webhook.
type ChatUserRemoved struct {
ChatID string `json:"chat_id"`
ThreadID string `json:"thread_id"`
UserID string `json:"user_id"`
UserType string `json:"user_type"`
}
// IncomingEvent represents payload of incoming_event webhook.
type IncomingEvent struct {
ChatID string `json:"chat_id"`
ThreadID string `json:"thread_id"`
Event objects.Event `json:"event"`
}
// EventUpdated represents payload of event_updated webhook.
type EventUpdated struct {
ChatID string `json:"chat_id"`
ThreadID string `json:"thread_id"`
Event objects.Event `json:"event"`
}
// IncomingRichMessagePostback represents payload of incoming_rich_message_postback webhook.
type IncomingRichMessagePostback struct {
UserID string `json:"user_id"`
ChatID string `json:"chat_id"`
ThreadID string `json:"thread_id"`
EventID string `json:"event_id"`
Postback struct {
ID string `json:"id"`
Toggled bool `json:"toggled"`
} `json:"postback"`
}
// ChatPropertiesUpdated represents payload of chat_properties_updated webhook.
type ChatPropertiesUpdated struct {
ChatID string `json:"chat_id"`
Properties objects.Properties `json:"properties"`
}
// ChatPropertiesDeleted represents payload of chat_properties_deleted webhook.
type ChatPropertiesDeleted struct {
ChatID string `json:"chat_id"`
Properties map[string][]string `json:"properties"`
}
// ChatThreadPropertiesDeleted represents payload of chat_thread_properties_deleted webhook.
type ChatThreadPropertiesDeleted struct {
ChatID string `json:"chat_id"`
ThreadID string `json:"thread_id"`
Properties map[string][]string `json:"properties"`
}
// ChatThreadPropertiesUpdated represents payload of chat_thread_properties_updated webhook.
type ChatThreadPropertiesUpdated struct {
ChatID string `json:"chat_id"`
ThreadID string `json:"thread_id"`
Properties objects.Properties `json:"properties"`
}
// EventPropertiesUpdated represents payload of event_properties_updated webhook.
type EventPropertiesUpdated struct {
ChatID string `json:"chat_id"`
ThreadID string `json:"thread_id"`
EventID string `json:"event_id"`
Properties objects.Properties `json:"properties"`
}
// EventPropertiesDeleted represents payload of event_properties_deleted webhook.
type EventPropertiesDeleted struct {
ChatID string `json:"chat_id"`
ThreadID string `json:"thread_id"`
EventID string `json:"event_id"`
Properties map[string][]string `json:"properties"`
}
// ChatThreadTagged represents payload of chat_thread_tagged webhook.
type ChatThreadTagged struct {
ChatID string `json:"chat_id"`
ThreadID string `json:"thread_id"`
Tag string `json:"tag"`
}
// ChatThreadUntagged represents payload of chat_thread_untagged webhook.
type ChatThreadUntagged struct {
ChatID string `json:"chat_id"`
ThreadID string `json:"thread_id"`
Tag string `json:"tag"`
}
// AgentStatusChanged represents payload of agent_status_changed webhook.
type AgentStatusChanged struct {
AgentID string `json:"agent_id"`
Status string `json:"status"`
}
// AgentDeleted represents payload of agent_deleted webhook.
type AgentDeleted struct {
AgentID string `json:"agent_id"`
}
// CustomerCreated represents payload of customer_created webhook.
type CustomerCreated objects.Customer
// EventsMarkedAsSeen represents payload of events_marked_as_seen webhook.
type EventsMarkedAsSeen struct {
UserID string `json:"user_id"`
ChatID string `json:"chat_id"`
SeenUpTo string `json:"seen_up_to"`
}
// UnmarshalJSON implements json.Unmarshaler interface for IncomingChatThread.
func (p *IncomingChatThread) UnmarshalJSON(data []byte) error {
type PayloadAlias IncomingChatThread
type SingleThread struct {
Chat struct {
Thread objects.Thread `json:"thread"`
} `json:"chat"`
}
var pa PayloadAlias
if err := json.Unmarshal(data, &pa); err != nil {
return err
}
*p = IncomingChatThread(pa)
var st SingleThread
if err := json.Unmarshal(data, &st); err != nil {
return err
}
p.Chat.Threads = append(p.Chat.Threads, st.Chat.Thread)
return nil
}