-
Notifications
You must be signed in to change notification settings - Fork 20
/
msg.go
81 lines (67 loc) · 2.24 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
package flows
import (
"github.com/nyaruka/gocommon/urns"
"github.com/nyaruka/goflow/utils"
)
// BaseMsg represents a incoming or outgoing message with the session contact
type BaseMsg struct {
UUID_ MsgUUID `json:"uuid"`
URN_ urns.URN `json:"urn" validate:"omitempty,urn"`
Channel_ *ChannelReference `json:"channel,omitempty"`
Text_ string `json:"text"`
Attachments_ []Attachment `json:"attachments,omitempty"`
}
// MsgIn represents a incoming message from the session contact
type MsgIn struct {
BaseMsg
}
// MsgOut represents a outgoing message to the session contact
type MsgOut struct {
BaseMsg
QuickReplies_ []string `json:"quick_replies,omitempty"`
}
// NewMsgIn creates a new incoming message
func NewMsgIn(uuid MsgUUID, urn urns.URN, channel Channel, text string, attachments []Attachment) *MsgIn {
var channelRef *ChannelReference
if channel != nil {
channelRef = channel.Reference()
}
return &MsgIn{
BaseMsg: BaseMsg{
UUID_: uuid,
URN_: urn,
Channel_: channelRef,
Text_: text,
Attachments_: attachments,
},
}
}
// NewMsgOut creates a new outgoing message
func NewMsgOut(urn urns.URN, channel Channel, text string, attachments []Attachment, quickReplies []string) *MsgOut {
var channelRef *ChannelReference
if channel != nil {
channelRef = channel.Reference()
}
return &MsgOut{
BaseMsg: BaseMsg{
UUID_: MsgUUID(utils.NewUUID()),
URN_: urn,
Channel_: channelRef,
Text_: text,
Attachments_: attachments,
},
QuickReplies_: quickReplies,
}
}
// UUID returns the UUID of this message
func (m *BaseMsg) UUID() MsgUUID { return m.UUID_ }
// URN returns the URN of this message
func (m *BaseMsg) URN() urns.URN { return m.URN_ }
// Channel returns the channel of this message
func (m *BaseMsg) Channel() *ChannelReference { return m.Channel_ }
// Text returns the text of this message
func (m *BaseMsg) Text() string { return m.Text_ }
// Attachments returns the attachments of this message
func (m *BaseMsg) Attachments() []Attachment { return m.Attachments_ }
// QuickReplies returns the quick replies of this outgoing message
func (m *MsgOut) QuickReplies() []string { return m.QuickReplies_ }