@@ -97,22 +97,23 @@ func (r *Response) Image(im image.Image) error {
97
97
return nil
98
98
}
99
99
100
+ // ButtonTemplate sends a message with the main contents being button elements
100
101
func (r * Response ) ButtonTemplate (text string , buttons * []StructuredMessageButton ) error {
101
- m := SendStructuredMessage {
102
+ m := SendStructuredMessage {
102
103
Recipient : r .to ,
103
- Message : StructuredMessageData {
104
- Attachment : StructuredMessageAttachment {
105
- Type : "template" ,
106
- Payload : StructuredMessagePayload {
107
- TemplateType : "button" ,
108
- Text : text ,
109
- Buttons : buttons ,
110
- Elements : nil ,
111
- },
112
- },
104
+ Message : StructuredMessageData {
105
+ Attachment : StructuredMessageAttachment {
106
+ Type : "template" ,
107
+ Payload : StructuredMessagePayload {
108
+ TemplateType : "button" ,
109
+ Text : text ,
110
+ Buttons : buttons ,
111
+ Elements : nil ,
112
+ },
113
+ },
113
114
},
114
115
}
115
-
116
+
116
117
data , err := json .Marshal (m )
117
118
if err != nil {
118
119
return nil
@@ -130,25 +131,26 @@ func (r *Response) ButtonTemplate(text string, buttons *[]StructuredMessageButto
130
131
131
132
resp , err := client .Do (req )
132
133
defer resp .Body .Close ()
133
-
134
+
134
135
return err
135
136
}
136
137
138
+ // GenericTemplate is a message which allows for structural elements to be sent
137
139
func (r * Response ) GenericTemplate (text string , elements * []StructuredMessageElement ) error {
138
- m := SendStructuredMessage {
140
+ m := SendStructuredMessage {
139
141
Recipient : r .to ,
140
- Message : StructuredMessageData {
141
- Attachment : StructuredMessageAttachment {
142
- Type : "template" ,
143
- Payload : StructuredMessagePayload {
144
- TemplateType : "generic" ,
145
- Buttons : nil ,
146
- Elements : elements ,
147
- },
148
- },
142
+ Message : StructuredMessageData {
143
+ Attachment : StructuredMessageAttachment {
144
+ Type : "template" ,
145
+ Payload : StructuredMessagePayload {
146
+ TemplateType : "generic" ,
147
+ Buttons : nil ,
148
+ Elements : elements ,
149
+ },
150
+ },
149
151
},
150
152
}
151
-
153
+
152
154
data , err := json .Marshal (m )
153
155
if err != nil {
154
156
return nil
@@ -166,7 +168,7 @@ func (r *Response) GenericTemplate(text string, elements *[]StructuredMessageEle
166
168
167
169
resp , err := client .Do (req )
168
170
defer resp .Body .Close ()
169
-
171
+
170
172
return err
171
173
}
172
174
@@ -181,45 +183,45 @@ type MessageData struct {
181
183
Text string `json:"text,omitempty"`
182
184
}
183
185
184
- // SendStructuredMessage is a structured message template
186
+ // SendStructuredMessage is a structured message template.
185
187
type SendStructuredMessage struct {
186
- Recipient Recipient `json:"recipient"`
188
+ Recipient Recipient `json:"recipient"`
187
189
Message StructuredMessageData `json:"message"`
188
190
}
189
191
192
+ // StructuredMessageData is an attachment sent with a structured message.
190
193
type StructuredMessageData struct {
191
194
Attachment StructuredMessageAttachment `json:"attachment"`
192
195
}
193
196
197
+ // StructuredMessageAttachment is the attachment of a structured message.
194
198
type StructuredMessageAttachment struct {
195
- // Template allways
199
+ // Type must be template
196
200
Type string `json:"type"`
197
201
// Payload is the information for the file which was sent in the attachment.
198
202
Payload StructuredMessagePayload `json:"payload"`
199
203
}
200
204
205
+ // StructuredMessagePayload is the actual payload of an attachment
201
206
type StructuredMessagePayload struct {
202
- // button, generic, receipt
203
- TemplateType string `json:"template_type"`
204
- Text string `json:"text,omitempty"`
205
- Elements * []StructuredMessageElement `json:"elements,omitempty"`
206
- Buttons * []StructuredMessageButton `json:"buttons,omitempty"`
207
+ // TemplateType must be button, generic or receipt
208
+ TemplateType string `json:"template_type"`
209
+ Text string `json:"text,omitempty"`
210
+ Elements * []StructuredMessageElement `json:"elements,omitempty"`
211
+ Buttons * []StructuredMessageButton `json:"buttons,omitempty"`
207
212
}
208
213
209
- // StructuredMessageElement - Generic Template
214
+ // StructuredMessageElement is a response containing structural elements
210
215
type StructuredMessageElement struct {
211
- Title string `json:"title"`
212
- ImageURL string `json:"image_url"`
213
- Subtitle string `json:"subtitle"`
214
- Buttons []StructuredMessageButton `json:"buttons"`
216
+ Title string `json:"title"`
217
+ ImageURL string `json:"image_url"`
218
+ Subtitle string `json:"subtitle"`
219
+ Buttons []StructuredMessageButton `json:"buttons"`
215
220
}
216
221
217
- // StructuredMessageButton - Button Template
222
+ // StructuredMessageButton is a response containing buttons
218
223
type StructuredMessageButton struct {
219
- Type string `json:"type"`
220
- URL string `json:"url"`
221
- Title string `json:"title"`
224
+ Type string `json:"type"`
225
+ URL string `json:"url"`
226
+ Title string `json:"title"`
222
227
}
223
-
224
-
225
-
0 commit comments