-
Notifications
You must be signed in to change notification settings - Fork 70
/
msg.go
127 lines (105 loc) · 3.14 KB
/
msg.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
package courier
import (
"database/sql/driver"
"encoding/json"
"strconv"
"time"
"github.com/nyaruka/gocommon/i18n"
"github.com/nyaruka/gocommon/urns"
"github.com/nyaruka/gocommon/uuids"
"github.com/nyaruka/null/v3"
)
// MsgID is our typing of the db int type
type MsgID null.Int64
// NilMsgID is our nil value for MsgID
var NilMsgID = MsgID(0)
// String satisfies the Stringer interface
func (i MsgID) String() string { return strconv.FormatInt(int64(i), 10) }
func (i *MsgID) Scan(value any) error { return null.ScanInt(value, i) }
func (i MsgID) Value() (driver.Value, error) { return null.IntValue(i) }
func (i *MsgID) UnmarshalJSON(b []byte) error { return null.UnmarshalInt(b, i) }
func (i MsgID) MarshalJSON() ([]byte, error) { return null.MarshalInt(i) }
// MsgUUID is the UUID of a message which has been received
type MsgUUID uuids.UUID
// NilMsgUUID is a "zero value" message UUID
const NilMsgUUID = MsgUUID("")
type FlowReference struct {
UUID string `json:"uuid" validate:"uuid4"`
Name string `json:"name"`
}
type OptInReference struct {
ID int64 `json:"id" validate:"required"`
Name string `json:"name" validate:"required"`
}
type UserID int
type MsgOrigin string
const (
MsgOriginFlow MsgOrigin = "flow"
MsgOriginBroadcast MsgOrigin = "broadcast"
MsgOriginTicket MsgOrigin = "ticket"
MsgOriginChat MsgOrigin = "chat"
)
type TemplatingVariable struct {
Type string `json:"type"`
Value string `json:"value"`
}
type Templating struct {
Template struct {
Name string `json:"name" validate:"required"`
UUID string `json:"uuid" validate:"required"`
} `json:"template" validate:"required,dive"`
Namespace string `json:"namespace"`
Components []struct {
Type string `json:"type"`
Name string `json:"name"`
Variables map[string]int `json:"variables"`
} `json:"components"`
Variables []TemplatingVariable `json:"variables"`
Language string `json:"language"`
ExternalID string `json:"external_id"`
}
//-----------------------------------------------------------------------------
// Msg interface
//-----------------------------------------------------------------------------
// Msg is our interface for common methods for an incoming or outgoing message
type Msg interface {
Event
ID() MsgID
UUID() MsgUUID
ExternalID() string
Text() string
Attachments() []string
URN() urns.URN
Channel() Channel
}
// MsgOut is our interface to represent an outgoing
type MsgOut interface {
Msg
// outgoing specific
QuickReplies() []string
Locale() i18n.Locale
Templating() *Templating
URNAuth() string
Origin() MsgOrigin
ContactLastSeenOn() *time.Time
Topic() string
Metadata() json.RawMessage
ResponseToExternalID() string
SentOn() *time.Time
IsResend() bool
Flow() *FlowReference
OptIn() *OptInReference
UserID() UserID
SessionStatus() string
HighPriority() bool
}
// MsgIn is our interface to represent an incoming
type MsgIn interface {
Msg
// incoming specific
ReceivedOn() *time.Time
WithAttachment(url string) MsgIn
WithContactName(name string) MsgIn
WithURNAuthTokens(tokens map[string]string) MsgIn
WithReceivedOn(date time.Time) MsgIn
}