Documentation ¶
Index ¶
- Constants
- type AccountLinking
- type AccountLinkingHandler
- type Action
- type Attachment
- type AttachmentType
- type CallToActionsItem
- type CallToActionsSetting
- type Coordinates
- type DefaultAction
- type Delivery
- type DeliveryHandler
- type Entry
- type GreetingInfo
- type GreetingSetting
- type HomeURL
- type ImageAspectRatio
- type Message
- type MessageData
- type MessageHandler
- type MessageInfo
- type MessagingType
- type Messenger
- func (m *Messenger) Attachment(to Recipient, dataType AttachmentType, url string, messagingType MessagingType, ...) error
- func (m *Messenger) CallToActionsSetting(state string, actions []CallToActionsItem) error
- func (m *Messenger) EnableChatExtension(homeURL HomeURL) error
- func (m *Messenger) GreetingSetting(text string) error
- func (m *Messenger) HandleAccountLinking(f AccountLinkingHandler)
- func (m *Messenger) HandleDelivery(f DeliveryHandler)
- func (m *Messenger) HandleMessage(f MessageHandler)
- func (m *Messenger) HandleOptIn(f OptInHandler)
- func (m *Messenger) HandlePostBack(f PostBackHandler)
- func (m *Messenger) HandleRead(f ReadHandler)
- func (m *Messenger) HandleReferral(f ReferralHandler)
- func (m *Messenger) Handler() http.Handler
- func (m *Messenger) ProfileByID(id int64, profileFields []string) (Profile, error)
- func (m *Messenger) Response(to int64) *Response
- func (m *Messenger) Send(to Recipient, message string, messagingType MessagingType, tags ...string) error
- func (m *Messenger) SendGeneralMessage(to Recipient, elements *[]StructuredMessageElement, ...) error
- func (m *Messenger) SendWithReplies(to Recipient, message string, replies []QuickReply, ...) error
- type OptIn
- type OptInHandler
- type Options
- type Payload
- type PostBack
- type PostBackHandler
- type Profile
- type QueryError
- type QueryResponse
- type QuickReply
- type Read
- type ReadHandler
- type Receive
- type Recipient
- type Referral
- type ReferralHandler
- type ReferralMessage
- type Response
- func (r *Response) Attachment(dataType AttachmentType, url string, messagingType MessagingType, ...) error
- func (r *Response) AttachmentData(dataType AttachmentType, filename string, filedata io.Reader) error
- func (r *Response) AttachmentWithReplies(attachment *StructuredMessageAttachment, replies []QuickReply, ...) error
- func (r *Response) ButtonTemplate(text string, buttons *[]StructuredMessageButton, messagingType MessagingType, ...) error
- func (r *Response) DispatchMessage(m interface{}) error
- func (r *Response) GenericTemplate(elements *[]StructuredMessageElement, messagingType MessagingType, ...) error
- func (r *Response) Image(im image.Image) error
- func (r *Response) SenderAction(action string) error
- func (r *Response) Text(message string, messagingType MessagingType, tags ...string) error
- func (r *Response) TextWithReplies(message string, replies []QuickReply, messagingType MessagingType, ...) error
- type SendMessage
- type SendSenderAction
- type SendStructuredMessage
- type Sender
- type StructuredMessageAttachment
- type StructuredMessageButton
- type StructuredMessageData
- type StructuredMessageElement
- type StructuredMessagePayload
- type TopElementStyle
Constants ¶
const ( // ProfileURL is the API endpoint used for retrieving profiles. // Used in the form: https://graph.facebook.com/v2.6/<USER_ID>?fields=<PROFILE_FIELDS>&access_token=<PAGE_ACCESS_TOKEN> ProfileURL = "https://graph.facebook.com/v2.6/" // SendSettingsURL is API endpoint for saving settings. SendSettingsURL = "https://graph.facebook.com/v2.6/me/thread_settings" // MessengerProfileURL is the API endoint where yout bot set properties that define various aspects of the following Messenger Platform features. // Used in the form https://graph.facebook.com/v2.6/me/messenger_profile?access_token=<PAGE_ACCESS_TOKEN> // https://developers.facebook.com/docs/messenger-platform/reference/messenger-profile-api/ MessengerProfileURL = "https://graph.facebook.com/v2.6/me/messenger_profile" )
const ( // SendMessageURL is API endpoint for sending messages. SendMessageURL = "https://graph.facebook.com/v2.11/me/messages" // ImageAttachment is image attachment type. ImageAttachment AttachmentType = "image" // AudioAttachment is audio attachment type. AudioAttachment AttachmentType = "audio" // VideoAttachment is video attachment type. VideoAttachment AttachmentType = "video" // FileAttachment is file attachment type. FileAttachment AttachmentType = "file" // ResponseType is response messaging type ResponseType MessagingType = "RESPONSE" // UpdateType is update messaging type UpdateType MessagingType = "UPDATE" // MessageTagType is message_tag messaging type MessageTagType MessagingType = "MESSAGE_TAG" // NonPromotionalSubscriptionType is NON_PROMOTIONAL_SUBSCRIPTION messaging type NonPromotionalSubscriptionType MessagingType = "NON_PROMOTIONAL_SUBSCRIPTION" // TopElementStyle is compact. CompactTopElementStyle TopElementStyle = "compact" // TopElementStyle is large. LargeTopElementStyle TopElementStyle = "large" // ImageAspectRatio is horizontal (1.91:1). Default. HorizontalImageAspectRatio ImageAspectRatio = "horizontal" // ImageAspectRatio is square. SquareImageAspectRatio ImageAspectRatio = "square" )
const ( // WebviewCompact opens the page in a web view that takes half the screen // and covers only part of the conversation. WebviewCompact = "compact" // WebviewTall opens the page in a web view that covers about 75% of the // conversation. WebviewTall = "tall" // WebviewFull opens the page in a web view that completely covers the // conversation, and has a "back" button instead of a "close" one. WebviewFull = "full" )
Defines the different sizes available when setting up a CallToActionsItem of type "web_url". These values can be used in the "WebviewHeightRatio" field.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type AccountLinking ¶
type AccountLinking 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:"-"` // Status represents the new account linking status. Status string `json:"status"` // AuthorizationCode is a pass-through code set during the linking process. AuthorizationCode string `json:"authorization_code"` }
type AccountLinkingHandler ¶
type AccountLinkingHandler func(AccountLinking, *Response)
AccountLinkingHandler is a handler used to react to an account being linked or unlinked.
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 advising of a successful delivery to a // previous recipient. DeliveryAction // ReadAction means that the event was a previous recipient reading their respective // messages. ReadAction // PostBackAction represents post call back PostBackAction // OptInAction represents opting in through the Send to Messenger button OptInAction // ReferralAction represents ?ref parameter in m.me URLs ReferralAction // AccountLinkingAction means that the event concerns changes in account linking // status. AccountLinkingAction )
type Attachment ¶
type Attachment struct { // 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. Payload Payload `json:"payload"` }
Attachment is a file which used in a message.
type CallToActionsItem ¶
type CallToActionsItem struct { Type string `json:"type,omitempty"` Title string `json:"title,omitempty"` Payload string `json:"payload,omitempty"` URL string `json:"url,omitempty"` WebviewHeightRatio string `json:"webview_height_ratio,omitempty"` MessengerExtension bool `json:"messenger_extensions,omitempty"` }
CallToActionsItem contains Get Started button or item of Persist Menu
type CallToActionsSetting ¶
type CallToActionsSetting struct { SettingType string `json:"setting_type"` ThreadState string `json:"thread_state"` CallToActions []CallToActionsItem `json:"call_to_actions"` }
CallToActionsSetting is the settings for Get Started and Persist Menu
type Coordinates ¶
type Coordinates struct { // Lat is latitude Lat float64 `json:"lat"` // Long is longitude Long float64 `json:"long"` }
Coordinates is a pair of latitude and longitude
type DefaultAction ¶
type DefaultAction struct { Type string `json:"type"` URL string `json:"url,omitempty"` WebviewHeightRatio string `json:"webview_height_ratio,omitempty"` MessengerExtensions bool `json:"messenger_extensions,omitempty"` FallbackURL string `json:"fallback_url,omitempty"` }
DefaultAction is a response containing default action properties
type Delivery ¶
type Delivery struct { // Mids are the IDs of the messages which were read. Mids []string `json:"mids"` // RawWatermark is the timestamp of when the delivery 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 Facebook delivers a message to the recipient.
type DeliveryHandler ¶
DeliveryHandler is a handler used for responding to a delivery 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 GreetingInfo ¶
type GreetingInfo struct {
Text string `json:"text"`
}
GreetingInfo contains greeting message
type GreetingSetting ¶
type GreetingSetting struct { SettingType string `json:"setting_type"` Greeting GreetingInfo `json:"greeting"` }
GreetingSetting is the setting for greeting message
type HomeURL ¶
type HomeURL struct { URL string `json:"url,omitempty"` WebviewHeightRatio string `json:"webview_height_ratio,omitempty"` InTest bool `json:"in_test,omitempty"` }
HomeURL is the settings for EnableChatExtension https://developers.facebook.com/docs/messenger-platform/reference/messenger-profile-api/home-url
type ImageAspectRatio ¶
type ImageAspectRatio string
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:"-"` // Message is mine IsEcho bool `json:"is_echo,omitempty"` // 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"` // Selected quick reply QuickReply *QuickReply `json:"quick_reply,omitempty"` }
Message represents a Facebook messenger message.
type MessageData ¶
type MessageData struct { Text string `json:"text,omitempty"` Attachment *StructuredMessageAttachment `json:"attachment,omitempty"` QuickReplies []QuickReply `json:"quick_replies,omitempty"` }
MessageData is a message consisting of text or an attachment, with an additional selection of optional quick replies.
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"` Read *Read `json:"read"` OptIn *OptIn `json:"optin"` ReferralMessage *ReferralMessage `json:"referral"` AccountLinking *AccountLinking `json:"account_linking"` }
MessageInfo is an event that is fired by the webhook.
type MessagingType ¶
type MessagingType string
type Messenger ¶
type Messenger struct {
// contains filtered or unexported fields
}
Messenger is the client which manages communication with the Messenger Platform API.
func (*Messenger) Attachment ¶
func (m *Messenger) Attachment(to Recipient, dataType AttachmentType, url string, messagingType MessagingType, tags ...string) error
Attachment sends an image, sound, video or a regular file to a given recipient.
func (*Messenger) CallToActionsSetting ¶
func (m *Messenger) CallToActionsSetting(state string, actions []CallToActionsItem) error
CallToActionsSetting sends settings for Get Started or Persistent Menu
func (*Messenger) EnableChatExtension ¶
EnableChatExtension set the homepage url required for a chat extension.
func (*Messenger) GreetingSetting ¶
GreetingSetting sends settings for greeting
func (*Messenger) HandleAccountLinking ¶
func (m *Messenger) HandleAccountLinking(f AccountLinkingHandler)
HandleAccountLinking adds a new AccountLinkingHandler to the Messenger
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 delivered to 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) HandleOptIn ¶
func (m *Messenger) HandleOptIn(f OptInHandler)
HandleOptIn adds a new OptInHandler to the Messenger which will be triggered once a user opts in to communicate with the bot.
func (*Messenger) HandlePostBack ¶
func (m *Messenger) HandlePostBack(f PostBackHandler)
HandlePostBack adds a new PostBackHandler to the Messenger
func (*Messenger) HandleRead ¶
func (m *Messenger) HandleRead(f ReadHandler)
HandleRead adds a new DeliveryHandler to the Messenger which will be triggered when a previously sent message is read by the recipient.
func (*Messenger) HandleReferral ¶
func (m *Messenger) HandleReferral(f ReferralHandler)
HandleReferral adds a new ReferralHandler to the Messenger
func (*Messenger) ProfileByID ¶
ProfileByID retrieves the Facebook user profile associated with that ID. According to the messenger docs: https://developers.facebook.com/docs/messenger-platform/identity/user-profile, Developers must ask for access except for some fields that are accessible without permissions.
At the time of writing (2019-01-04), these fields are - Name - First Name - Last Name - Profile Picture
func (*Messenger) Send ¶
func (m *Messenger) Send(to Recipient, message string, messagingType MessagingType, tags ...string) error
Send will send a textual message to a user. This user must have previously initiated a conversation with the bot.
func (*Messenger) SendGeneralMessage ¶
func (m *Messenger) SendGeneralMessage(to Recipient, elements *[]StructuredMessageElement, messagingType MessagingType, tags ...string) error
SendGeneralMessage will send the GenericTemplate message
func (*Messenger) SendWithReplies ¶
func (m *Messenger) SendWithReplies(to Recipient, message string, replies []QuickReply, messagingType MessagingType, tags ...string) error
SendWithReplies sends a textual message to a user, but gives them the option of numerous quick response options.
type OptInHandler ¶
OptInHandler is a handler used to handle opt-ins.
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 // AppSecret is the app secret from the Facebook Developer Portal. Used when // in the "verify" mode. AppSecret string // 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 // Mux is shared mux between several Messenger objects Mux *http.ServeMux }
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"` // Coordinates is Lat/Long pair of location pin Coordinates *Coordinates `json:"coordinates,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"` // Optional referral info Referral Referral `json:"referral"` }
PostBack represents postback callback
type PostBackHandler ¶
PostBackHandler is a handler used postback callbacks.
type Profile ¶
type Profile struct { Name string `json:"name"` FirstName string `json:"first_name"` LastName string `json:"last_name"` ProfilePicURL string `json:"profile_pic"` Locale string `json:"locale"` Timezone float64 `json:"timezone"` Gender string `json:"gender"` }
Profile is the public information of a Facebook user
type QueryError ¶
type QueryError struct { Message string `json:"message"` Type string `json:"type"` Code int `json:"code"` FBTraceID string `json:"fbtrace_id"` }
QueryError is representing an error sent back by Facebook
type QueryResponse ¶
type QueryResponse struct { Error *QueryError `json:"error,omitempty"` Result string `json:"result,omitempty"` }
QueryResponse is the response sent back by Facebook when setting up things like greetings or call-to-actions
type QuickReply ¶
type QuickReply struct { // ContentType is the type of reply ContentType string `json:"content_type,omitempty"` // Title is the reply title Title string `json:"title,omitempty"` // Payload is the reply information Payload string `json:"payload"` }
QuickReply is a file which used in a message.
type Read ¶
type Read struct { // RawWatermark is the timestamp before which all messages have been read // by the user RawWatermark int64 `json:"watermark"` // Seq is the sequence the message was sent in. Seq int `json:"seq"` }
Read represents a the event fired when a message is read by the recipient.
type ReadHandler ¶
ReadHandler is a handler used for responding to a read receipt.
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 Referral ¶
type Referral struct { // Data originally passed in the ref param Ref string `json:"ref"` // Source type Source string `json:"source"` // The identifier dor the referral Type string `json:"type"` }
Referral represents referral info
type ReferralHandler ¶
type ReferralHandler func(ReferralMessage, *Response)
ReferralHandler is a handler used postback callbacks.
type ReferralMessage ¶
type ReferralMessage struct { *Referral // Sender is the sender of the message 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:"-"` }
ReferralMessage represents referral endpoint
type Response ¶
type Response struct {
// contains filtered or unexported fields
}
Response is used for responding to events with messages.
func (*Response) Attachment ¶
func (r *Response) Attachment(dataType AttachmentType, url string, messagingType MessagingType, tags ...string) error
Attachment sends an image, sound, video or a regular file to a chat.
func (*Response) AttachmentData ¶
func (r *Response) AttachmentData(dataType AttachmentType, filename string, filedata io.Reader) error
AttachmentData sends an image, sound, video or a regular file to a chat via an io.Reader.
func (*Response) AttachmentWithReplies ¶
func (r *Response) AttachmentWithReplies(attachment *StructuredMessageAttachment, replies []QuickReply, messagingType MessagingType, tags ...string) error
AttachmentWithReplies sends a attachment message with some replies
func (*Response) ButtonTemplate ¶
func (r *Response) ButtonTemplate(text string, buttons *[]StructuredMessageButton, messagingType MessagingType, tags ...string) error
ButtonTemplate sends a message with the main contents being button elements
func (*Response) DispatchMessage ¶
DispatchMessage posts the message to messenger, return the error if there's any
func (*Response) GenericTemplate ¶
func (r *Response) GenericTemplate(elements *[]StructuredMessageElement, messagingType MessagingType, tags ...string) error
GenericTemplate is a message which allows for structural elements to be sent
func (*Response) SenderAction ¶
SenderAction sends a info about sender action
func (*Response) Text ¶
func (r *Response) Text(message string, messagingType MessagingType, tags ...string) error
Text sends a textual message.
func (*Response) TextWithReplies ¶
func (r *Response) TextWithReplies(message string, replies []QuickReply, messagingType MessagingType, tags ...string) error
TextWithReplies sends a textual message with some replies messagingType should be one of the following: "RESPONSE","UPDATE","MESSAGE_TAG","NON_PROMOTIONAL_SUBSCRIPTION" only supply tags when messagingType == "MESSAGE_TAG" (see https://developers.facebook.com/docs/messenger-platform/send-messages#messaging_types for more)
type SendMessage ¶
type SendMessage struct { MessagingType MessagingType `json:"messaging_type"` Recipient Recipient `json:"recipient"` Message MessageData `json:"message"` Tag string `json:"tag,omitempty"` }
SendMessage is the information sent in an API request to Facebook.
type SendSenderAction ¶
type SendSenderAction struct { Recipient Recipient `json:"recipient"` SenderAction string `json:"sender_action"` }
SendSenderAction is the information about sender action
type SendStructuredMessage ¶
type SendStructuredMessage struct { MessagingType MessagingType `json:"messaging_type"` Recipient Recipient `json:"recipient"` Message StructuredMessageData `json:"message"` Tag string `json:"tag,omitempty"` }
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 AttachmentType `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,omitempty"` Title string `json:"title,omitempty"` Payload string `json:"payload,omitempty"` WebviewHeightRatio string `json:"webview_height_ratio,omitempty"` MessengerExtensions bool `json:"messenger_extensions,omitempty"` FallbackURL string `json:"fallback_url,omitempty"` }
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"` ItemURL string `json:"item_url"` Subtitle string `json:"subtitle"` DefaultAction *DefaultAction `json:"default_action,omitempty"` 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,omitempty"` TopElementStyle TopElementStyle `json:"top_element_style,omitempty"` Text string `json:"text,omitempty"` ImageAspectRatio ImageAspectRatio `json:"image_aspect_ratio,omitempty"` Sharable bool `json:"sharable,omitempty"` Elements *[]StructuredMessageElement `json:"elements,omitempty"` Buttons *[]StructuredMessageButton `json:"buttons,omitempty"` Url string `json:"url,omitempty"` }
StructuredMessagePayload is the actual payload of an attachment
type TopElementStyle ¶
type TopElementStyle string