Skip to content
This repository has been archived by the owner on Jan 1, 2023. It is now read-only.

Commit

Permalink
Fix styling
Browse files Browse the repository at this point in the history
  • Loading branch information
paked committed May 4, 2016
1 parent 09dbfd4 commit 036b286
Show file tree
Hide file tree
Showing 5 changed files with 73 additions and 71 deletions.
2 changes: 1 addition & 1 deletion actions.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@ const (
// DeliveryAction means that the event was a previous recipient reading their respective
// messages.
DeliveryAction
// PostBackAction represents post call back
// PostBackAction represents post call back
PostBackAction
)
4 changes: 2 additions & 2 deletions message.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,13 @@ type Delivery struct {

// PostBack represents postback callback
type PostBack struct {
// Sender is who the message was sent from.
// Sender is who the message was sent from.
Sender Sender `json:"-"`
// Recipient is who the message was sent to.
Recipient Recipient `json:"-"`
// Time is when the message was sent.
Time time.Time `json:"-"`
// PostBack ID
// PostBack ID
Payload string `json:"payload"`
}

Expand Down
44 changes: 22 additions & 22 deletions messenger.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ type Options struct {
VerifyToken string
// Token is the access token of the Facebook page to send messages from.
Token string
// WebhookURL is where the Messenger client should listen for webhook events.
// WebhookURL is where the Messenger client should listen for webhook events.
WebhookURL string
}

Expand All @@ -41,7 +41,7 @@ type Messenger struct {
mux *http.ServeMux
messageHandlers []MessageHandler
deliveryHandlers []DeliveryHandler
postBackHandlers []PostBackHandler
postBackHandlers []PostBackHandler
token string
verifyHandler func(http.ResponseWriter, *http.Request)
}
Expand Down Expand Up @@ -143,26 +143,26 @@ func (m *Messenger) dispatch(r Receive) {
}

switch a {
case TextAction:
for _, f := range m.messageHandlers {
message := *info.Message
message.Sender = info.Sender
message.Recipient = info.Recipient
message.Time = time.Unix(info.Timestamp, 0)
f(message, resp)
}
case DeliveryAction:
for _, f := range m.deliveryHandlers {
f(*info.Delivery, resp)
}
case PostBackAction:
for _, f := range m.postBackHandlers {
message := *info.PostBack
message.Sender = info.Sender
message.Recipient = info.Recipient
message.Time = time.Unix(info.Timestamp, 0)
f(message, resp)
}
case TextAction:
for _, f := range m.messageHandlers {
message := *info.Message
message.Sender = info.Sender
message.Recipient = info.Recipient
message.Time = time.Unix(info.Timestamp, 0)
f(message, resp)
}
case DeliveryAction:
for _, f := range m.deliveryHandlers {
f(*info.Delivery, resp)
}
case PostBackAction:
for _, f := range m.postBackHandlers {
message := *info.PostBack
message.Sender = info.Sender
message.Recipient = info.Recipient
message.Time = time.Unix(info.Timestamp, 0)
f(message, resp)
}
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion receiving.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ type MessageInfo struct {
// Delivery is the contents of a message if it is a DeliveryAction.
// Nil if it is not a DeliveryAction.
Delivery *Delivery `json:"delivery"`

PostBack *PostBack `json:"postback"`
}

Expand Down
92 changes: 47 additions & 45 deletions response.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,22 +97,23 @@ func (r *Response) Image(im image.Image) error {
return nil
}

// ButtonTemplate sends a message with the main contents being button elements
func (r *Response) ButtonTemplate(text string, buttons *[]StructuredMessageButton) error {
m := SendStructuredMessage {
m := SendStructuredMessage{
Recipient: r.to,
Message: StructuredMessageData {
Attachment: StructuredMessageAttachment {
Type: "template",
Payload: StructuredMessagePayload {
TemplateType: "button",
Text: text,
Buttons: buttons,
Elements: nil,
},
},
Message: StructuredMessageData{
Attachment: StructuredMessageAttachment{
Type: "template",
Payload: StructuredMessagePayload{
TemplateType: "button",
Text: text,
Buttons: buttons,
Elements: nil,
},
},
},
}

data, err := json.Marshal(m)
if err != nil {
return nil
Expand All @@ -130,25 +131,26 @@ func (r *Response) ButtonTemplate(text string, buttons *[]StructuredMessageButto

resp, err := client.Do(req)
defer resp.Body.Close()

return err
}

// GenericTemplate is a message which allows for structural elements to be sent
func (r *Response) GenericTemplate(text string, elements *[]StructuredMessageElement) error {
m := SendStructuredMessage {
m := SendStructuredMessage{
Recipient: r.to,
Message: StructuredMessageData {
Attachment: StructuredMessageAttachment {
Type: "template",
Payload: StructuredMessagePayload {
TemplateType: "generic",
Buttons: nil,
Elements: elements,
},
},
Message: StructuredMessageData{
Attachment: StructuredMessageAttachment{
Type: "template",
Payload: StructuredMessagePayload{
TemplateType: "generic",
Buttons: nil,
Elements: elements,
},
},
},
}

data, err := json.Marshal(m)
if err != nil {
return nil
Expand All @@ -166,7 +168,7 @@ func (r *Response) GenericTemplate(text string, elements *[]StructuredMessageEle

resp, err := client.Do(req)
defer resp.Body.Close()

return err
}

Expand All @@ -181,45 +183,45 @@ type MessageData struct {
Text string `json:"text,omitempty"`
}

// SendStructuredMessage is a structured message template
// SendStructuredMessage is a structured message template.
type SendStructuredMessage struct {
Recipient Recipient `json:"recipient"`
Recipient Recipient `json:"recipient"`
Message StructuredMessageData `json:"message"`
}

// StructuredMessageData is an attachment sent with a structured message.
type StructuredMessageData struct {
Attachment StructuredMessageAttachment `json:"attachment"`
}

// StructuredMessageAttachment is the attachment of a structured message.
type StructuredMessageAttachment struct {
// Template allways
// Type must be template
Type string `json:"type"`
// Payload is the information for the file which was sent in the attachment.
Payload StructuredMessagePayload `json:"payload"`
}

// StructuredMessagePayload is the actual payload of an attachment
type StructuredMessagePayload struct {
// button, generic, receipt
TemplateType string `json:"template_type"`
Text string `json:"text,omitempty"`
Elements *[]StructuredMessageElement `json:"elements,omitempty"`
Buttons *[]StructuredMessageButton `json:"buttons,omitempty"`
// TemplateType must be button, generic or receipt
TemplateType string `json:"template_type"`
Text string `json:"text,omitempty"`
Elements *[]StructuredMessageElement `json:"elements,omitempty"`
Buttons *[]StructuredMessageButton `json:"buttons,omitempty"`
}

// StructuredMessageElement - Generic Template
// StructuredMessageElement is a response containing structural elements
type StructuredMessageElement struct {
Title string `json:"title"`
ImageURL string `json:"image_url"`
Subtitle string `json:"subtitle"`
Buttons []StructuredMessageButton `json:"buttons"`
Title string `json:"title"`
ImageURL string `json:"image_url"`
Subtitle string `json:"subtitle"`
Buttons []StructuredMessageButton `json:"buttons"`
}

// StructuredMessageButton - Button Template
// StructuredMessageButton is a response containing buttons
type StructuredMessageButton struct {
Type string `json:"type"`
URL string `json:"url"`
Title string `json:"title"`
Type string `json:"type"`
URL string `json:"url"`
Title string `json:"title"`
}



0 comments on commit 036b286

Please sign in to comment.