-
Notifications
You must be signed in to change notification settings - Fork 20
/
interfaces.go
282 lines (257 loc) · 6.11 KB
/
interfaces.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
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
package assets
import (
"encoding/json"
"github.com/nyaruka/goflow/envs"
"github.com/nyaruka/goflow/utils"
"github.com/nyaruka/goflow/utils/uuids"
)
// ChannelUUID is the UUID of a channel
type ChannelUUID uuids.UUID
// ChannelRole is a role that a channel can perform
type ChannelRole string
// different roles that channels can perform
const (
ChannelRoleSend ChannelRole = "send"
ChannelRoleReceive ChannelRole = "receive"
ChannelRoleCall ChannelRole = "call"
ChannelRoleAnswer ChannelRole = "answer"
ChannelRoleUSSD ChannelRole = "ussd"
)
// Channel is something that can send/receive messages.
//
// {
// "uuid": "14782905-81a6-4910-bc9f-93ad287b23c3",
// "name": "My Android",
// "address": "+593979011111",
// "schemes": ["tel"],
// "roles": ["send", "receive"],
// "country": "EC"
// }
//
// @asset channel
type Channel interface {
UUID() ChannelUUID
Name() string
Address() string
Schemes() []string
Roles() []ChannelRole
Parent() *ChannelReference
Country() string
MatchPrefixes() []string
AllowInternational() bool
}
// ClassifierUUID is the UUID of an NLU classifier
type ClassifierUUID uuids.UUID
// Classifier is an NLU classifier.
//
// {
// "uuid": "37657cf7-5eab-4286-9cb0-bbf270587bad",
// "name": "Booking",
// "type": "wit",
// "intents": ["book_flight", "book_hotel"]
// }
//
// @asset classifier
type Classifier interface {
UUID() ClassifierUUID
Name() string
Type() string
Intents() []string
}
// FieldUUID is the UUID of a field
type FieldUUID uuids.UUID
// FieldType is the data type of values for each field
type FieldType string
// field value types
const (
FieldTypeText FieldType = "text"
FieldTypeNumber FieldType = "number"
FieldTypeDatetime FieldType = "datetime"
FieldTypeWard FieldType = "ward"
FieldTypeDistrict FieldType = "district"
FieldTypeState FieldType = "state"
)
// Field is a custom contact property.
//
// {
// "uuid": "d66a7823-eada-40e5-9a3a-57239d4690bf",
// "key": "gender",
// "name": "Gender",
// "type": "text"
// }
//
// @asset field
type Field interface {
UUID() FieldUUID
Key() string
Name() string
Type() FieldType
}
// FlowUUID is the UUID of a flow
type FlowUUID uuids.UUID
// Flow is graph of nodes with actions and routers.
//
// {
// "uuid": "14782905-81a6-4910-bc9f-93ad287b23c3",
// "name": "Registration",
// "definition": {
// "nodes": []
// }
// }
//
// @asset flow
type Flow interface {
UUID() FlowUUID
Name() string
Definition() json.RawMessage
}
// Global is a named constant.
//
// {
// "key": "organization_name",
// "name": "Organization Name",
// "value": "U-Report"
// }
//
// @asset global
type Global interface {
Key() string
Name() string
Value() string
}
// GroupUUID is the UUID of a group
type GroupUUID uuids.UUID
// Group is a set of contacts which can be static or dynamic (i.e. based on a query).
//
// {
// "uuid": "14782905-81a6-4910-bc9f-93ad287b23c3",
// "name": "Youth",
// "query": "age <= 18"
// }
//
// @asset group
type Group interface {
UUID() GroupUUID
Name() string
Query() string
}
// LabelUUID is the UUID of a label
type LabelUUID uuids.UUID
// Label is an organizational tag that can be applied to a message.
//
// {
// "uuid": "14782905-81a6-4910-bc9f-93ad287b23c3",
// "name": "Spam"
// }
//
// @asset label
type Label interface {
UUID() LabelUUID
Name() string
}
// LocationHierarchy is a searchable hierarchy of locations.
//
// {
// "name": "Rwanda",
// "aliases": ["Ruanda"],
// "children": [
// {
// "name": "Kigali City",
// "aliases": ["Kigali", "Kigari"],
// "children": [
// {
// "name": "Gasabo",
// "children": [
// {
// "id": "575743222",
// "name": "Gisozi"
// },
// {
// "id": "457378732",
// "name": "Ndera"
// }
// ]
// },
// {
// "name": "Nyarugenge",
// "children": []
// }
// ]
// },
// {
// "name": "Eastern Province"
// }
// ]
// }
//
// @asset location
type LocationHierarchy interface {
FindByPath(path utils.LocationPath) *utils.Location
FindByName(name string, level utils.LocationLevel, parent *utils.Location) []*utils.Location
}
// Resthook is a set of URLs which are subscribed to the named event.
//
// {
// "slug": "new-registration",
// "subscribers": [
// "http://example.com/record.php?@contact.uuid"
// ]
// }
//
// @asset resthook
type Resthook interface {
Slug() string
Subscribers() []string
}
type TemplateUUID uuids.UUID
// Template is a message template, currently only used by WhatsApp channels
//
// {
// "name": "revive-issue",
// "uuid": "14782905-81a6-4910-bc9f-93ad287b23c3",
// "translations": [
// {
// "language": "eng",
// "content": "Hi {{1}}, are you still experiencing your issue?",
// "channel": {
// "uuid": "cf26be4c-875f-4094-9e08-162c3c9dcb5b",
// "name": "Twilio Channel"
// }
// },
// {
// "language": "fra",
// "content": "Bonjour {{1}}",
// "channel": {
// "uuid": "cf26be4c-875f-4094-9e08-162c3c9dcb5b",
// "name": "Twilio Channel"
// }
// }
// ]
// }
//
// @asset template
type Template interface {
UUID() TemplateUUID
Name() string
Translations() []TemplateTranslation
}
// TemplateTranslation represents a single translation for a specific template and channel
type TemplateTranslation interface {
Content() string
Language() envs.Language
VariableCount() int
Channel() ChannelReference
}
// Source is a source of assets
type Source interface {
Channels() ([]Channel, error)
Classifiers() ([]Classifier, error)
Fields() ([]Field, error)
Flow(FlowUUID) (Flow, error)
Globals() ([]Global, error)
Groups() ([]Group, error)
Labels() ([]Label, error)
Locations() ([]LocationHierarchy, error)
Resthooks() ([]Resthook, error)
Templates() ([]Template, error)
}