Documentation
¶
Index ¶
- Constants
- type Action
- type Attachment
- type Delivery
- type Entry
- type Message
- type MessageData
- type MessageInfo
- type Messenger
- func (m *Messenger) OnDelivery(f OnDeliveryFunc)
- func (m *Messenger) OnGetPageToken(f OnGetPageTokenFunc)
- func (m *Messenger) OnMessage(f OnMessageFunc)
- func (m *Messenger) ProfileByID(pageToken string, id int64) (Profile, error)
- func (m *Messenger) VerifyWebhook(w http.ResponseWriter, r *http.Request)
- func (m *Messenger) Webhook(w http.ResponseWriter, r *http.Request)
- type OnDeliveryFunc
- type OnGetPageTokenFunc
- type OnMessageFunc
- type Payload
- type Profile
- type Receive
- type Recipient
- type Response
- type SendMessage
- type Sender
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 )
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 Entry ¶
type Entry struct { // ID is the ID of the batch. ID int64 `json:"id"` // 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 { PageToken string `json:"-"` // 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"`
}
MessageData is a text message to be sent.
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"` }
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) OnDelivery ¶
func (m *Messenger) OnDelivery(f OnDeliveryFunc)
HandleDelivery adds a new DeliveryHandler to the Messenger which will be triggered when a previously sent message is read by the recipient.
func (*Messenger) OnGetPageToken ¶
func (m *Messenger) OnGetPageToken(f OnGetPageTokenFunc)
func (*Messenger) OnMessage ¶
func (m *Messenger) OnMessage(f OnMessageFunc)
HandleMessage adds a new MessageHandler to the Messenger which will be triggered when a message is received by the client.
func (*Messenger) ProfileByID ¶
ProfileByID retrieves the Facebook user associated with that ID
func (*Messenger) VerifyWebhook ¶
func (m *Messenger) VerifyWebhook(w http.ResponseWriter, r *http.Request)
VerifyWebhook facebook will send GET method to verify the webhook with verify token
type OnDeliveryFunc ¶
DeliveryHandler is a handler used for responding to a read receipt.
type OnGetPageTokenFunc ¶
type OnMessageFunc ¶
MessageHandler is a handler used for responding to a message containing text.
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 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 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"`
}
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.
type SendMessage ¶
type SendMessage struct { Recipient Recipient `json:"recipient"` Message MessageData `json:"message"` }
SendMessage is the information sent in an API request to Facebook.