forked from abhinavdahiya/go-messenger-bot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
helpers.go
178 lines (160 loc) · 3.24 KB
/
helpers.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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
package mbotapi
import "github.com/satori/go.uuid"
// Creates a User from ID(int64)
func NewUserFromID(id int64) User {
return User{
ID: id,
}
}
// Creates a User from phone no(string)
func NewUserFromPhone(p string) User {
return User{
PhoneNumber: p,
}
}
//Create a sender action
// takes const TypingON/TypingOFF/MarkSeen
func NewAction(ac Action) Action {
return ac
}
// Creates a Message with given text to be sent by bot
func NewMessage(text string) Message {
return Message{
Text: text,
}
}
//Creates a quick reply
//Takes two parameters:
// - title(string)
// - postback_payload(string)
func NewQuickReply(title string, pst string) QR {
return QR{
Title: title,
Payload: pst,
Type: "text",
}
}
// Creates a Message with image attachment to be
// sent by bot
func NewImageFromURL(url string) Message {
return Message{
Attachment: &Attachment{
Type: "image",
Payload: FilePayload{
URL: url,
},
},
}
}
// Creates a Message with audio attachment to be
// sent by bot
func NewAudioFromURL(url string) Message {
return Message{
Attachment: &Attachment{
Type: "audio",
Payload: FilePayload{
URL: url,
},
},
}
}
// Creates a Message with video attachment to be
// sent by bot
func NewVideoFromURL(url string) Message {
return Message{
Attachment: &Attachment{
Type: "video",
Payload: FilePayload{
URL: url,
},
},
}
}
// Creates a Message with file attachment to be
// sent by bot
func NewFileFromURL(url string) Message {
return Message{
Attachment: &Attachment{
Type: "file",
Payload: FilePayload{
URL: url,
},
},
}
}
// Creates an empty generic template
func NewGenericTemplate() GenericTemplate {
return GenericTemplate{
TemplateBase: TemplateBase{
Type: "generic",
},
Elements: []Element{},
}
}
// Creates an empty list template
func NewListTemplate() ListTemplate {
return ListTemplate{
GenericTemplate: GenericTemplate{
TemplateBase: TemplateBase{
Type: "list",
},
Elements: []Element{},
},
TopElementStyle: "large",
}
}
// Creates a new Element (info card) to be sent as
// part of the generic template
func NewElement(title string) Element {
return Element{
Title: title,
}
}
// Creates a new Button of type `web_url`
func NewURLButton(title, url string) Button {
return Button{
Type: "web_url",
Title: title,
URL: url,
}
}
// Creates a new Button of type `postback`
func NewPostbackButton(title, postback string) Button {
return Button{
Type: "postback",
Title: title,
Payload: postback,
}
}
// Creates a new Button of type `phone_number`
func NewPhoneButton(title, pn string) Button {
return Button{
Type: "phone_number",
Title: title,
Payload: pn,
}
}
// Creates an empty Button Template
func NewButtonTemplate(text string) ButtonTemplate {
return ButtonTemplate{
TemplateBase: TemplateBase{
Type: "button",
},
Text: text,
Buttons: []Button{},
}
}
// Creates an empty Receipt Template
func NewReceiptTemplate(rname string) ReceiptTemplate {
return ReceiptTemplate{
TemplateBase: TemplateBase{
Type: "receipt",
},
RecipientName: rname,
ID: uuid.NewV4().String(),
Currency: "USD",
PaymentMethod: "",
Items: []OrderItem{},
Summary: OrderSummary{},
}
}