-
Notifications
You must be signed in to change notification settings - Fork 19
/
template.go
117 lines (102 loc) · 2.8 KB
/
template.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
package assets
import (
"fmt"
"github.com/nyaruka/gocommon/i18n"
"github.com/nyaruka/gocommon/uuids"
)
// TemplateUUID is the UUID of a template
type TemplateUUID uuids.UUID
// Template is a message template, currently only used by WhatsApp channels
//
// {
// "name": "greeting",
// "uuid": "14782905-81a6-4910-bc9f-93ad287b23c3",
// "translations": [
// {
// "locale": "eng-US",
// "channel": {
// "uuid": "cf26be4c-875f-4094-9e08-162c3c9dcb5b",
// "name": "Twilio Channel"
// },
// "components": [
// {
// "type": "body",
// "name": "body",
// "content": "Hello {{1}}",
// "variables": {"1": 0}
// }
// ],
// "variables": [{"type": "text"}]
// },
// {
// "locale": "fra",
// "channel": {
// "uuid": "cf26be4c-875f-4094-9e08-162c3c9dcb5b",
// "name": "Twilio Channel"
// },
// "components": [
// {
// "type": "body",
// "name": "body",
// "content": "Bonjour {{1}}",
// "variables": {"1": 0}
// }
// ],
// "variables": [{"type": "text"}]
// }
// ]
// }
//
// @asset template
type Template interface {
UUID() TemplateUUID
Name() string
Translations() []TemplateTranslation
}
type TemplateVariable interface {
Type() string
}
type TemplateComponent interface {
Type() string
Name() string
Content() string
Display() string
Variables() map[string]int
}
// TemplateTranslation represents a single translation for a specific template and channel
type TemplateTranslation interface {
Locale() i18n.Locale
Namespace() string
Channel() *ChannelReference
Components() []TemplateComponent
Variables() []TemplateVariable
}
// TemplateReference is used to reference a Template
type TemplateReference struct {
UUID TemplateUUID `json:"uuid" validate:"required,uuid"`
Name string `json:"name"`
}
// NewTemplateReference creates a new template reference with the given UUID and name
func NewTemplateReference(uuid TemplateUUID, name string) *TemplateReference {
return &TemplateReference{UUID: uuid, Name: name}
}
// GenericUUID returns the untyped UUID
func (r *TemplateReference) GenericUUID() uuids.UUID {
return uuids.UUID(r.UUID)
}
// Identity returns the unique identity of the asset
func (r *TemplateReference) Identity() string {
return string(r.UUID)
}
// Type returns the name of the asset type
func (r *TemplateReference) Type() string {
return "template"
}
func (r *TemplateReference) String() string {
return fmt.Sprintf("%s[uuid=%s,name=%s]", r.Type(), r.Identity(), r.Name)
}
// Variable returns whether this a variable (vs concrete) reference
func (r *TemplateReference) Variable() bool {
return false
}
var _ UUIDReference = (*TemplateReference)(nil)