Documentation ¶
Overview ¶
Package fbot can be used to communicate with a Facebook Messenger bot. The supported API is limited to only features we use. Please open an issue for features you are missing.
Index ¶
- type Attachment
- type Button
- type Client
- func (c Client) GetProfile(id int64) (Profile, error)
- func (c Client) Send(id int64, message string, replies []Reply) error
- func (c Client) SendWithButtons(id int64, message string, replies []Reply, buttons []Button) error
- func (c Client) SetGetStartedPayload(p string) error
- func (c Client) SetGreetings(g []Greeting) error
- func (c Client) Webhook(handler func(Event), secret, verifyToken string) http.Handler
- type Config
- type Event
- type EventType
- type Greeting
- type Profile
- type Reply
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Attachment ¶
Attachment describes an attachment. Type is one of "image", "video", audio, "location", "file" or "feedback". Currently only the URL field is loaded because we only use "file". If a sticker is sent the type is "image" and Sticker != 0. For more see: https://developers.facebook.com/docs/messenger-platform/webhook-reference/message
type Button ¶
type Button interface{}
Button describes a button that can be send with a Button Template. Use URLButton or PayloadButton for initialization.
func LinkButton ¶
LinkButton returns a button that opens a URL in the browser.
func PayloadButton ¶
PayloadButton returns a button that posts a payload back to the bot.
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client can be used to communicate with a Messenger bot. Use New for initialization.
func (Client) GetProfile ¶
GetProfile fetches a user profile for an ID.
func (Client) SendWithButtons ¶
SendWithButtons sends a message with a set of buttons and quick replies to a user.
func (Client) SetGetStartedPayload ¶
SetGetStartedPayload displays a "Get Started" button for new users. When a users pushes the button, a postback with the given payload is triggered.
func (Client) SetGreetings ¶
SetGreetings sets the text displayed in the bot description. Include "default" locale as fallback for missing locales.
type Config ¶
type Config struct { Token string Secret string API string // Optional. Overwrite the Facebook API URL. }
Config is passed to New.
type Event ¶
type Event struct { // Type helps to decide how to react to an event. Type EventType // ChatID identifies the user. It's a Facebook user ID. ChatID int64 // Time describes when the event occured. Time time.Time // Text is a message a user send for EventMessage and error description for EventError. Text string // Payload is a predefined payload for a quick reply or postback sent with EventPayload. Payload string // MessageID is a unique ID for each message. MessageID string // Attachments are multiple attachment types. Attachments []Attachment // Ref contains the ref data from the URL for EventReferral. // Ref is also set for EventPayload if the Event was triggered through the Get Started button // and the user used a refferal link to get there. Ref string }
Event contains information about a user action.
type EventType ¶
type EventType int
EventType helps to distinguish the different type of events.
const ( // EventError is triggered when the webhook is called with invalid JSON content. EventError EventType = 1 + iota // EventMessage is triggered when a user sends Text, stickers or other content. // Only text is available at the moment. EventMessage // EventPayload is triggered when a quickReply or postback Payload is sent. EventPayload // EventRead is triggered when a user read a message. EventRead // EventAttachment is triggered when attachemnts are send. EventAttachment // EventReferral is triggered when referring through a link or other source. EventReferral )
type Greeting ¶
type Greeting struct { // Locale should be 5 chars, like "en_US". // For supported locales see: https://developers.facebook.com/docs/messenger-platform/messenger-profile/supported-locales Locale string `json:"locale"` // Text can be any text, but it's restricted to 160 chars. // Supports a few template strings, see: https://developers.facebook.com/docs/messenger-platform/messenger-profile/greeting-text Text string `json:"text"` }
Greeting is a localized message describing the bot.