Documentation ¶
Index ¶
- Constants
- Variables
- type APIResponse
- type Action
- type Attachment
- type AttachmentPayload
- type BotAPI
- func (bot *BotAPI) MakeRequest(b *bytes.Buffer) (APIResponse, error)
- func (bot *BotAPI) Send(u User, c interface{}, notif string) (APIResponse, error)
- func (bot *BotAPI) SendFile(u User, path string) (APIResponse, error)
- func (bot *BotAPI) SetGStarted(text string) error
- func (bot *BotAPI) SetGreeting(text string) error
- func (bot *BotAPI) SetMenu(bts []Button) error
- func (bot *BotAPI) SetSettings(b *bytes.Buffer) error
- func (bot *BotAPI) SetWebhook(pattern string) (<-chan Callback, *http.ServeMux)
- type Button
- type ButtonTemplate
- type Callback
- type Element
- type Entry
- type ErrorResponse
- type FilePayload
- type GStarted
- type GenericTemplate
- type Greeting
- type InputAttachPayload
- type InputAttachment
- type InputCoords
- type InputDelivery
- type InputMessage
- type InputOptin
- type InputPostback
- type InputQRPayload
- type ListTemplate
- type Message
- type OrderAddress
- type OrderAdjustment
- type OrderItem
- type OrderSummary
- type Page
- type QR
- type ReceiptTemplate
- type Request
- type Response
- type TemplateBase
- type ThreadSetting
- type User
Constants ¶
const ( RegularNotif = "REGULAR" SilentNotif = "SILENT_PUSH" NoNotif = "NO_PUSH" TypingON = "typing_on" TypingOFF = "typing_off" MarkSeen = "mark_seen" )
const (
APIEndpoint = "https://graph.facebook.com/v2.6/me/messages?access_token=%s"
)
const (
SettingsEndpoint = "https://graph.facebook.com/v2.6/me/thread_settings?access_token=%s"
)
Variables ¶
var ( ErrTitleTooLong = errors.New("Template Title exceeds the 25 character limit") ErrSubtitleTooLong = errors.New("Template Subtitle exceeds the 80 character limit") ErrButtonsLimitExceeded = errors.New("Max 3 buttons allowed on GenericTemplate") ErrBubblesLimitExceeded = errors.New("Max 10 bubbles allowed on GenericTemplate") )
Functions ¶
This section is empty.
Types ¶
type APIResponse ¶
type APIResponse struct { RID int64 `json:"recipient_id,string"` MID string `json:"message_id"` Error ErrorResponse `json:"error"` }
type Attachment ¶
type Attachment struct { Type string `json:"type"` Payload AttachmentPayload `json:"payload"` }
type AttachmentPayload ¶
type AttachmentPayload interface{}
type BotAPI ¶
type BotAPI struct { Token string VerifyToken string AppSecret string Debug bool Client *http.Client }
This defines a bot Set Debug to true for debugging
func NewBotAPI ¶
This helps create a BotAPI instance with token, verify_token By default Debug is set to false
func (*BotAPI) MakeRequest ¶
func (bot *BotAPI) MakeRequest(b *bytes.Buffer) (APIResponse, error)
This helps send request (send messages to users) It takes Request struct encoded into a buffer of json bytes The APIResponse contains the error from FB if any Should NOT be directly used, Use Send / SendFile
func (*BotAPI) Send ¶
func (bot *BotAPI) Send(u User, c interface{}, notif string) (APIResponse, error)
This function helps send messages to users It takes Message / GenericTemplate / ButtonTemplate / ReceiptTemplate and sends it to the user
func (*BotAPI) SendFile ¶
func (bot *BotAPI) SendFile(u User, path string) (APIResponse, error)
This helps to send local images (currently) to users TODO: not tested yet!
func (*BotAPI) SetGStarted ¶
func (*BotAPI) SetGreeting ¶
func (*BotAPI) SetWebhook ¶
This function registers the handlers for - webhook verification - all callbacks made on the webhhoks It loops over all entries in the callback and pushes to the Callback channel This also return a *http.ServeMux which can be used to listenAndServe
type Button ¶
type Button struct { Type string `json:"type"` Title string `json:"title,omitempty"` URL string `json:"url,omitempty"` Payload string `json:"payload,omitempty"` }
func NewPhoneButton ¶
Creates a new Button of type `phone_number`
func NewPostbackButton ¶
Creates a new Button of type `postback`
func NewURLButton ¶
Creates a new Button of type `web_url`
type ButtonTemplate ¶
type ButtonTemplate struct { TemplateBase Text string `json:"text,omitempty"` Buttons []Button `json:"buttons,omitempty"` }
Used as payload for type template(button)
func NewButtonTemplate ¶
func NewButtonTemplate(text string) ButtonTemplate
Creates an empty Button Template
func (*ButtonTemplate) AddButton ¶
func (b *ButtonTemplate) AddButton(bt ...Button)
type Callback ¶
type Callback struct { Sender User `json:"sender"` Recipient Page `json:"recipient"` Timestamp int64 `json:"timestamp"` Optin InputOptin `json:"optin"` Message InputMessage `json:"message,omitempty"` Postback InputPostback `json:"postback,omitempty"` Delivery InputDelivery `json:"delivery,omitempty"` }
This represents the content of the message sent by the user Various kinds of callbacks from user are - OptinCallback MessageCallback PostbackCallback DeliveryCallback
TODO: Create a way to identify the type of callback
func (Callback) IsDelivery ¶
func (Callback) IsPostback ¶
type Element ¶
type Element struct { Title string `json:"title"` URL string `json:"item_url,omitempty"` ImageURL string `json:"image_url,omitempty"` Subtitle string `json:"subtitle,omitempty"` Buttons []Button `json:"buttons,omitempty"` }
func NewElement ¶
Creates a new Element (info card) to be sent as part of the generic template
type Entry ¶
type Entry struct { PageID int64 `json:"id"` Time int64 `json:"time"` Messaging []Callback `json:"messaging"` }
This defines an Entry in the payload by webhook
type ErrorResponse ¶
type FilePayload ¶
type FilePayload struct {
URL string `json:"url"`
}
Used as payload for type image/audio/video/file
type GenericTemplate ¶
type GenericTemplate struct { TemplateBase Elements []Element `json:"elements"` }
Used as payload for type template(generic)
func NewGenericTemplate ¶
func NewGenericTemplate() GenericTemplate
Creates an empty generic template
func (*GenericTemplate) AddElement ¶
func (g *GenericTemplate) AddElement(e ...Element)
func (GenericTemplate) Validate ¶
func (g GenericTemplate) Validate() error
type InputAttachPayload ¶
type InputAttachPayload struct { URL string `json:"url,omitempty"` Coords InputCoords `json:"coordinates,omitempty"` }
type InputAttachment ¶
type InputAttachment struct { Type string `json:"type"` Payload InputAttachPayload `json:"payload"` }
Represents an attachement The types are image/audio/video/location
type InputCoords ¶
type InputDelivery ¶
type InputDelivery struct { MIDs []string `json:"mids"` Watermark int64 `json:"watermark"` Seq int64 `json:"seq"` }
This contains delivery reports for batch of messages(mids)
type InputMessage ¶
type InputMessage struct { MID string `json:"mid"` Seq int64 `json:"seq"` Text string `json:"text"` Attachments []InputAttachment `json:"attachments,omitempty"` QuickReply InputQRPayload `json:"quick_reply,omitempty"` }
This represents a Message from user If text message only Text field exists If media message Attachments fields contains an array of attachmensts sent
type InputOptin ¶
type InputOptin struct {
Ref string `json:"ref"`
}
Ref contains the `data-ref` set for message optin for the bot
type InputPostback ¶
type InputPostback struct {
Payload string `json:"payload"`
}
Represents a postback sent by clicking on Postback Button
type InputQRPayload ¶
type InputQRPayload struct {
Payload string `json:"payload"`
}
Represents a quick reply payload
type ListTemplate ¶
type ListTemplate struct { GenericTemplate TopElementStyle string `json:"top_element_style"` // compact or large(default) }
type Message ¶
type Message struct { Text string `json:"text,omitempty"` Attachment *Attachment `json:"attachment,omitempty"` QuickReply []QR `json:"quick_replies,omitempty"` }
func NewAudioFromURL ¶
Creates a Message with audio attachment to be sent by bot
func NewFileFromURL ¶
Creates a Message with file attachment to be sent by bot
func NewImageFromURL ¶
Creates a Message with image attachment to be sent by bot
func NewMessage ¶
Creates a Message with given text to be sent by bot
func NewVideoFromURL ¶
Creates a Message with video attachment to be sent by bot
type OrderAddress ¶
type OrderAdjustment ¶
type OrderSummary ¶
type QR ¶
type QR struct { Type string `json:"content_type"` Title string `json:"title"` Payload string `json:"payload"` }
func NewQuickReply ¶
Creates a quick reply Takes two parameters: - title(string) - postback_payload(string)
type ReceiptTemplate ¶
type ReceiptTemplate struct { TemplateBase RecipientName string `json:"recipient_name"` ID string `json:"order_number"` Currency string `json:"currency"` PaymentMethod string `json:"payment_method"` Timestamp int64 `json:"timestamp,omitempty"` URL string `json:"order_url,omitempty"` Items []OrderItem `json:"elements"` Address *OrderAddress `json:"address,omitempty"` Summary OrderSummary `json:"summary"` Adjustments []OrderAdjustment `json:"adjustments,omitempty"` }
Used as payload for type template(receipt)
func NewReceiptTemplate ¶
func NewReceiptTemplate(rname string) ReceiptTemplate
Creates an empty Receipt Template
type Response ¶
Payload received by the webhook The Object field is always set to `page` Contains bacthed entries
type TemplateBase ¶
type TemplateBase struct {
Type string `json:"template_type"`
}