-
Notifications
You must be signed in to change notification settings - Fork 19
/
channel.go
84 lines (70 loc) · 2.03 KB
/
channel.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
package assets
import (
"fmt"
"github.com/nyaruka/gocommon/uuids"
"github.com/nyaruka/goflow/envs"
)
// 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() envs.Country
MatchPrefixes() []string
AllowInternational() bool
}
// ChannelReference is used to reference a channel
type ChannelReference struct {
UUID ChannelUUID `json:"uuid" validate:"required,uuid"`
Name string `json:"name"`
}
// NewChannelReference creates a new channel reference with the given UUID and name
func NewChannelReference(uuid ChannelUUID, name string) *ChannelReference {
return &ChannelReference{UUID: uuid, Name: name}
}
// Type returns the name of the asset type
func (r *ChannelReference) Type() string {
return "channel"
}
// GenericUUID returns the untyped UUID
func (r *ChannelReference) GenericUUID() uuids.UUID {
return uuids.UUID(r.UUID)
}
// Identity returns the unique identity of the asset
func (r *ChannelReference) Identity() string {
return string(r.UUID)
}
// Variable returns whether this a variable (vs concrete) reference
func (r *ChannelReference) Variable() bool {
return false
}
func (r *ChannelReference) String() string {
return fmt.Sprintf("%s[uuid=%s,name=%s]", r.Type(), r.Identity(), r.Name)
}
var _ UUIDReference = (*ChannelReference)(nil)