-
Notifications
You must be signed in to change notification settings - Fork 19
/
template.go
90 lines (77 loc) · 2.25 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
package assets
import (
"fmt"
"github.com/nyaruka/gocommon/uuids"
"github.com/nyaruka/goflow/envs"
)
// TemplateUUID is the UUID of a template
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
Country() envs.Country
Namespace() string
VariableCount() int
Channel() ChannelReference
}
// 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)