1
0
mirror of synced 2024-11-22 04:46:05 +03:00

Merge pull request #60 from ahmdaeyz/master

Adding missing json fields and list template method
This commit is contained in:
Harrison Shoebridge 2019-04-17 10:49:06 +10:00 committed by GitHub
commit 19ba0ed851
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 33 additions and 3 deletions

View File

@ -92,6 +92,8 @@ type Recipient struct {
// Attachment is a file which used in a message.
type Attachment struct {
Title string `json:"title,omitempty"`
URL string `json:"url,omitempty"`
// Type is what type the message is. (image, video, audio or location)
Type string `json:"type"`
// Payload is the information for the file which was sent in the attachment.
@ -111,7 +113,7 @@ type QuickReply struct {
// Payload is the information on where an attachment is.
type Payload struct {
// URL is where the attachment resides on the internet.
URL string `json:"url,omitempty"`
URL string `json:"url,omitempty"`
// Coordinates is Lat/Long pair of location pin
Coordinates *Coordinates `json:"coordinates,omitempty"`
}
@ -119,7 +121,7 @@ type Payload struct {
// Coordinates is a pair of latitude and longitude
type Coordinates struct {
// Lat is latitude
Lat float64 `json:"lat"`
Lat float64 `json:"lat"`
// Long is longitude
Long float64 `json:"long"`
}

View File

@ -289,6 +289,32 @@ func (r *Response) GenericTemplate(elements *[]StructuredMessageElement, messagi
return r.DispatchMessage(&m)
}
// ListTemplate sends a list of elements
func (r *Response) ListTemplate(elements *[]StructuredMessageElement, messagingType MessagingType, tags ...string) error {
var tag string
if len(tags) > 0 {
tag = tags[0]
}
m := SendStructuredMessage{
MessagingType: messagingType,
Recipient: r.to,
Message: StructuredMessageData{
Attachment: StructuredMessageAttachment{
Type: "template",
Payload: StructuredMessagePayload{
TopElementStyle: "compact",
TemplateType: "list",
Buttons: nil,
Elements: elements,
},
},
},
Tag: tag,
}
return r.DispatchMessage(&m)
}
// SenderAction sends a info about sender action
func (r *Response) SenderAction(action string) error {
m := SendSenderAction{
@ -386,7 +412,9 @@ type StructuredMessageData struct {
// StructuredMessageAttachment is the attachment of a structured message.
type StructuredMessageAttachment struct {
// Type must be template
Type AttachmentType `json:"type"`
Title string `json:"title,omitempty"`
URL string `json:"url,omitempty"`
Type AttachmentType `json:"type"`
// Payload is the information for the file which was sent in the attachment.
Payload StructuredMessagePayload `json:"payload"`
}