Documentation
¶
Index ¶
- Constants
- type Action
- type Attachment
- type Delivery
- type DeliveryHandler
- type Entry
- type Message
- type MessageData
- type MessageHandler
- type MessageInfo
- type Messenger
- type Options
- type Payload
- type PostBack
- type PostBackHandler
- type Profile
- type QuickReply
- type Receive
- type Recipient
- type Response
- func (r *Response) ButtonTemplate(text string, buttons *[]StructuredMessageButton) error
- func (r *Response) GenericTemplate(text string, elements *[]StructuredMessageElement) error
- func (r *Response) Image(im image.Image) error
- func (r *Response) Text(message string) error
- func (r *Response) TextWithReplies(message string, replies []QuickReply) error
- type SendMessage
- type SendStructuredMessage
- type Sender
- type StructuredMessageAttachment
- type StructuredMessageButton
- type StructuredMessageData
- type StructuredMessageElement
- type StructuredMessagePayload
Constants ¶
const ( // ProfileURL is the API endpoint used for retrieving profiles. // Used in the form: https://graph.facebook.com/v2.6/<USER_ID>?fields=first_name,last_name,profile_pic&access_token=<PAGE_ACCESS_TOKEN> ProfileURL = "https://graph.facebook.com/v2.6/" )
const (
// SendMessageURL is API endpoint for sending messages.
SendMessageURL = "https://graph.facebook.com/v2.6/me/messages"
)
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Action ¶
type Action int
Action is used to determine what kind of message a webhook event is.
const ( // UnknownAction means that the event was not able to be classified. UnknownAction Action = iota - 1 // TextAction means that the event was a text message (May contain attachments). TextAction // DeliveryAction means that the event was a previous recipient reading their respective // messages. DeliveryAction // PostBackAction represents post call back PostBackAction )
type Attachment ¶
type Attachment struct { // Type is what type the message is. (image, video or audio) Type string `json:"type"` // Payload is the information for the file which was sent in the attachment. Payload Payload `json:"payload"` }
Attachment is a file which used in a message.
type Delivery ¶
type Delivery struct { // Mids are the IDs of the messages which were read. Mids []string `json:"mids"` // RawWatermark is the timestamp contained in the message of when the read was. RawWatermark int64 `json:"watermark"` // Seq is the sequence the message was sent in. Seq int `json:"seq"` }
Delivery represents a the event fired when a recipient reads one of Messengers sent messages.
type DeliveryHandler ¶
DeliveryHandler is a handler used for responding to a read receipt.
type Entry ¶
type Entry struct { // ID is the ID of the batch. ID int64 `json:"id,string"` // Time is when the batch was sent. Time int64 `json:"time"` // Messaging is the events that were sent in this Entry Messaging []MessageInfo `json:"messaging"` }
Entry is a batch of events which were sent in this webhook trigger.
type Message ¶
type Message struct { // 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:"-"` // Mid is the ID of the message. Mid string `json:"mid"` // Seq is order the message was sent in relation to other messages. Seq int `json:"seq"` // Text is the textual contents of the message. Text string `json:"text"` // Attachments is the information about the attachments which were sent // with the message. Attachments []Attachment `json:"attachments"` }
Message represents a Facebook messenge message.
type MessageData ¶
type MessageData struct { Text string `json:"text,omitempty"` QuickReplies []QuickReply `json:"quick_replies,omitempty"` }
MessageData is a text message with optional replies to be sent.
type MessageHandler ¶
MessageHandler is a handler used for responding to a message containing text.
type MessageInfo ¶
type MessageInfo struct { // Sender is who the event was sent from. Sender Sender `json:"sender"` // Recipient is who the event was sent to. Recipient Recipient `json:"recipient"` // Timestamp is the true time the event was triggered. Timestamp int64 `json:"timestamp"` // Message is the contents of a message if it is a MessageAction. // Nil if it is not a MessageAction. Message *Message `json:"message"` // 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"` }
MessageInfo is an event that is fired by the webhook.
type Messenger ¶
type Messenger struct {
// contains filtered or unexported fields
}
Messenger is the client which manages communication with the Messenger Platform API.
func (*Messenger) HandleDelivery ¶
func (m *Messenger) HandleDelivery(f DeliveryHandler)
HandleDelivery adds a new DeliveryHandler to the Messenger which will be triggered when a previously sent message is read by the recipient.
func (*Messenger) HandleMessage ¶
func (m *Messenger) HandleMessage(f MessageHandler)
HandleMessage adds a new MessageHandler to the Messenger which will be triggered when a message is received by the client.
func (*Messenger) HandlePostBack ¶
func (m *Messenger) HandlePostBack(f PostBackHandler)
HandlePostBack adds a new PostBackHandler to the Messenger
type Options ¶
type Options struct { // Verify sets whether or not to be in the "verify" mode. Used for // verifying webhooks on the Facebook Developer Portal. Verify bool // VerifyToken is the token to be used when verifying the webhook. Is set // when the webhook is created. 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. Leaving the string blank implies a path of "/". WebhookURL string }
Options are the settings used when creating a Messenger client.
type Payload ¶
type Payload struct { // URL is where the attachment resides on the internet. URL string `json:"url,omitempty"` }
Payload is the information on where an attachment is.
type PostBack ¶
type PostBack struct { // 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 Payload string `json:"payload"` }
PostBack represents postback callback
type PostBackHandler ¶
PostBackHandler is a handler used postback callbacks.
type Profile ¶
type Profile struct { FirstName string `json:"first_name"` LastName string `json:"last_name"` ProfilePicURL string `json:"profile_pic"` }
Profile is the public information of a Facebook user
type QuickReply ¶
type QuickReply struct { // ContentType is the type of reply ContentType string `json:"content_type"` // Title is the reply title Title string `json:"title"` // Payload is the reply information Payload string `json:"payload"` }
QuickReply is a file which used in a message.
type Receive ¶
type Receive struct { // Object should always be `page`. (I don't quite understand why) Object string `json:"object"` // Entry is all of the different messenger types which were // sent in this event. Entry []Entry `json:"entry"` }
Receive is the format in which webhook events are sent.
type Recipient ¶
type Recipient struct {
ID int64 `json:"id,string"`
}
Recipient is who the message was sent to.
type Response ¶
type Response struct {
// contains filtered or unexported fields
}
Response is used for responding to events with messages.
func (*Response) ButtonTemplate ¶
func (r *Response) ButtonTemplate(text string, buttons *[]StructuredMessageButton) error
ButtonTemplate sends a message with the main contents being button elements
func (*Response) GenericTemplate ¶
func (r *Response) GenericTemplate(text string, elements *[]StructuredMessageElement) error
GenericTemplate is a message which allows for structural elements to be sent
func (*Response) TextWithReplies ¶
func (r *Response) TextWithReplies(message string, replies []QuickReply) error
TextWithReplies sends a textual message with some replies
type SendMessage ¶
type SendMessage struct { Recipient Recipient `json:"recipient"` Message MessageData `json:"message"` }
SendMessage is the information sent in an API request to Facebook.
type SendStructuredMessage ¶
type SendStructuredMessage struct { Recipient Recipient `json:"recipient"` Message StructuredMessageData `json:"message"` }
SendStructuredMessage is a structured message template.
type Sender ¶
type Sender struct {
ID int64 `json:"id,string"`
}
Sender is who the message was sent from.
type StructuredMessageAttachment ¶
type StructuredMessageAttachment struct { // 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"` }
StructuredMessageAttachment is the attachment of a structured message.
type StructuredMessageButton ¶
type StructuredMessageButton struct { Type string `json:"type"` URL string `json:"url"` Title string `json:"title"` }
StructuredMessageButton is a response containing buttons
type StructuredMessageData ¶
type StructuredMessageData struct {
Attachment StructuredMessageAttachment `json:"attachment"`
}
StructuredMessageData is an attachment sent with a structured message.
type StructuredMessageElement ¶
type StructuredMessageElement struct { Title string `json:"title"` ImageURL string `json:"image_url"` Subtitle string `json:"subtitle"` Buttons []StructuredMessageButton `json:"buttons"` }
StructuredMessageElement is a response containing structural elements
type StructuredMessagePayload ¶
type StructuredMessagePayload struct { // 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"` }
StructuredMessagePayload is the actual payload of an attachment