-
Notifications
You must be signed in to change notification settings - Fork 0
/
message.go
107 lines (90 loc) · 3.54 KB
/
message.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
package viber
// MessageType represents a Viber message type.
type MessageType uint16
const (
TextOnly MessageType = 106
TextImageButton MessageType = 108
TextOnly2Way MessageType = 206
TextImageButton2Way MessageType = 208
)
// MessageSourceType represents message sending procedure.
type MessageSourceType uint16
const (
Promotional MessageSourceType = iota + 1
Transactional
)
// Message represents a Viber message.
type Message struct {
Sender string `json:"source_addr"` // Sender is a message sender (from whom message is sent).
Receiver string `json:"destination_addr"` // Receiver is a message receiver (to whom message is sent).
MessageType MessageType `json:"message_type"` // Message type is a message type.
Text string `json:"text"` // Text is a message in the UTF8 format.
ImageUrl string `json:"image"` // ImageUrl is URL of an image for promotional message with button caption and button action.
ButtonCaption string `json:"button_caption"` // ButtonCaption is a button caption in the UTF8 format.
ButtonAction string `json:"button_action"` // ButtonAction is an URL for transition when the button is pressed.
SourceType MessageSourceType `json:"source_type"` // SourceType is a message sending procedure.
CallbackUrl string `json:"callback_url"` // CallbackUrl is an URL for message status callback.
ValidityPeriod int `json:"validity_period"` // ValidityPeriod is a life time of a message (in seconds).
}
// NewMessage creates new Message.
func NewMessage() *Message {
return &Message{}
}
// SetSender sets message sender.
func (m *Message) SetSender(sender string) *Message {
m.Sender = sender
return m
}
// SetReceiver sets message receiver.
func (m *Message) SetReceiver(receiver string) *Message {
m.Receiver = receiver
return m
}
// SetMessageType sets message type.
func (m *Message) SetMessageType(messageType MessageType) *Message {
m.MessageType = messageType
return m
}
// SetText sets message text.
func (m *Message) SetText(text string) *Message {
m.Text = text
return m
}
// SetImageUrl sets image url for promotional message with button caption and button action.
func (m *Message) SetImageUrl(imageUrl string) *Message {
m.ImageUrl = imageUrl
return m
}
// SetButtonCaption sets button caption.
func (m *Message) SetButtonCaption(buttonCaption string) *Message {
m.ButtonCaption = buttonCaption
return m
}
// SetButtonAction sets button action (an URL for transition when the button is pressed).
func (m *Message) SetButtonAction(buttonAction string) *Message {
m.ButtonAction = buttonAction
return m
}
// SetSourceType sets message source type (sending procedure).
func (m *Message) SetSourceType(sourceType MessageSourceType) *Message {
m.SourceType = sourceType
return m
}
// SetCallbackUrl sets callback URL (an URL for message status callback).
func (m *Message) SetCallbackUrl(callbackUrl string) *Message {
m.CallbackUrl = callbackUrl
return m
}
// SetValidityPeriod sets message validity period (life time of a message, in seconds).
func (m *Message) SetValidityPeriod(validityPeriod int) *Message {
m.ValidityPeriod = validityPeriod
return m
}
// AddSmsText adds SMS text to the message (alternative SMS message text for cases when Viber message is not sent).
/*func (m *Message) AddSmsText(smsText string) *MessageWithSms {
msgSms := MessageWithSms{
Message: *m,
}
msgSms.SmsText = smsText
return &msgSms
}*/