Documentation
¶
Index ¶
- Constants
- Variables
- type APIError
- type Button
- type ButtonType
- type CallButton
- type Client
- func (c *Client) DeleteIceBreakers(ctx context.Context) (*DeleteIceBreakersResponse, error)
- func (c *Client) GetIceBreakers(ctx context.Context) (*GetIceBreakersResponse, error)
- func (c *Client) GetUserProfile(ctx context.Context, instagramUserID string) (*GetUserProfileResponse, error)
- func (c *Client) SendMessage(ctx context.Context, recipient string, message Message) (*SendMessageResponse, error)
- func (c *Client) SetIceBreakers(ctx context.Context, iceBreakers []*IceBreaker) (*SetIceBreakersResponse, error)
- type ClientOption
- type DeleteIceBreakersResponse
- type ErrorResponse
- type GenericTemplateElement
- type GenericTemplateElementOption
- type GenericTemplateMessage
- type GetIceBreakersResponse
- type GetUserProfileResponse
- type IceBreaker
- type IceBreakers
- type ImageMessage
- type InstaBot
- type LogInButton
- type LogOutButton
- type MediaShareMessage
- type Message
- type MessageType
- type PostBackButton
- type ProductTemplateElement
- type ProductTemplateMessage
- type QuickReply
- type QuickReplyType
- type Recipient
- type SendMessageResponse
- type Sender
- type SetIceBreakersResponse
- type StickerMessage
- type StickerType
- type Template
- type TemplateDefaultAction
- type TemplateType
- type TextMessage
- type TextMessageOption
- type URLButton
Constants ¶
const ( Platform string = "instagram" APIVersion string = "v11.0" )
instabot const values.
Variables ¶
var ( APIEndpointBase = "https://graph.facebook.com" APIEndpointSendMessage = fmt.Sprintf("/%s/me/messages", APIVersion) APIEndpointMessengerProfile = fmt.Sprintf("/%s/me/messenger_profile", APIVersion) GetAPIEndpointUserProfile = func(instagramUserID string) string { return fmt.Sprintf("/%s/%s", APIVersion, instagramUserID) } )
instagram messaging api endpoints.
var ( // ErrMissingPageAccessToken happens when instantiating instabot // with empty page access token. ErrMissingPageAccessToken = errors.New("missing page access token") )
Functions ¶
This section is empty.
Types ¶
type APIError ¶
type APIError struct { Message string `json:"message"` Type string `json:"type"` Code int32 `json:"code"` SubCode int32 `json:"error_subcode"` FbTraceID string `json:"fbtrace_id"` }
APIError defines error received from the api.
type ButtonType ¶
type ButtonType string
ButtonType defines button type.
const ( ButtonTypeURL ButtonType = ButtonType("web_url") ButtonTypePostBack ButtonType = ButtonType("postback") ButtonTypeCall ButtonType = ButtonType("phone_number") ButtonTypeLogin ButtonType = ButtonType("account_link") ButtonTypeLogOut ButtonType = ButtonType("account_unlink") ButtonTypeGamePlay ButtonType = ButtonType("game_play") )
all button type. https://developers.facebook.com/docs/messenger-platform/send-messages/buttons
type CallButton ¶
type CallButton struct { Title string PhoneNumber string // contains filtered or unexported fields }
CallButton defines call button. https://developers.facebook.com/docs/messenger-platform/send-messages/buttons#call
func NewCallButton ¶
func NewCallButton(title string, PhoneNumber string) *CallButton
NewCallButton returns a new call button.
func (*CallButton) MarshalJSON ¶
func (b *CallButton) MarshalJSON() ([]byte, error)
MarshalJSON returns json of the button.
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client defines instabot.
func New ¶
func New(pageAccessToken string, options ...ClientOption) (*Client, error)
New returns a new bot client instance.
func (*Client) DeleteIceBreakers ¶
func (c *Client) DeleteIceBreakers(ctx context.Context) (*DeleteIceBreakersResponse, error)
DeleteIceBreakers deletes ice breakers. https://developers.facebook.com/docs/messenger-platform/instagram/features/ice-breakers#deleting-icebreakers
func (*Client) GetIceBreakers ¶
func (c *Client) GetIceBreakers(ctx context.Context) (*GetIceBreakersResponse, error)
GetIceBreakers fetches ice breakers. https://developers.facebook.com/docs/messenger-platform/instagram/features/ice-breakers#getting-ice-breakers
func (*Client) GetUserProfile ¶
func (c *Client) GetUserProfile(ctx context.Context, instagramUserID string) (*GetUserProfileResponse, error)
GetUserProfile fetches user profile by instagram user id. https://developers.facebook.com/docs/messenger-platform/instagram/features/user-profile#user-profile-api
func (*Client) SendMessage ¶
func (c *Client) SendMessage(ctx context.Context, recipient string, message Message) (*SendMessageResponse, error)
SendMessage sends message by calling instagram api. https://developers.facebook.com/docs/messenger-platform/instagram/features/send-message#send-api
func (*Client) SetIceBreakers ¶
func (c *Client) SetIceBreakers(ctx context.Context, iceBreakers []*IceBreaker) (*SetIceBreakersResponse, error)
SetIceBreakers sets a instagram account ice breakers. https://developers.facebook.com/docs/messenger-platform/instagram/features/ice-breakers#setting-ice-breakers
type ClientOption ¶
ClientOption defines optional argument for new client construction.
func WithEndpointBase ¶
func WithEndpointBase(endpointBase string) ClientOption
WithEndpointBase sets client base endpoint.
func WithHTTPClient ¶
func WithHTTPClient(c *http.Client) ClientOption
WithHTTPClient sets client http client.
type DeleteIceBreakersResponse ¶
type DeleteIceBreakersResponse struct {
Result string `json:"result"`
}
DeleteIceBreakersResponse defines delete ice breaker api success response.
type ErrorResponse ¶
type ErrorResponse struct { StatusCode int `json:"status_code,omitempty"` APIError APIError `json:"error"` }
ErrorResponse defines error response received from instagram api.
type GenericTemplateElement ¶
type GenericTemplateElement struct { Title string Subtitle string ImageURL string DefaultAction *TemplateDefaultAction Buttons []Button }
GenericTemplateElement defines generic template element. https://developers.facebook.com/docs/messenger-platform/instagram/features/generic-template#elements
func NewGenericTemplateElement ¶
func NewGenericTemplateElement(title string, opts ...GenericTemplateElementOption) *GenericTemplateElement
NewGenericTemplateElement returns new GenericTemplateElement.
func (*GenericTemplateElement) MarshalJSON ¶
func (e *GenericTemplateElement) MarshalJSON() ([]byte, error)
MarshalJSON marshal generic template element to JSON.
type GenericTemplateElementOption ¶
type GenericTemplateElementOption func(*GenericTemplateElement)
GenericTemplateElementOption defines new GenericTemplateElement instantiation optional argument.
func WithTemplateButtons ¶
func WithTemplateButtons(buttons []Button) GenericTemplateElementOption
WithTemplateButtons sets buttons of a GenericTemplateElement, a maximum of 3 buttons per element is supported.
func WithTemplateDefaultAction ¶
func WithTemplateDefaultAction(URL string) GenericTemplateElementOption
WithTemplateDefaultAction sets default action of a GenericTemplateElement.
func WithTemplateImageURL ¶
func WithTemplateImageURL(imageURL string) GenericTemplateElementOption
WithTemplateImageURL sets image url of a GenericTemplateElement.
func WithTemplateSubtitle ¶
func WithTemplateSubtitle(subtitle string) GenericTemplateElementOption
WithTemplateSubtitle sets subtitle of a GenericTemplateElement.
type GenericTemplateMessage ¶
type GenericTemplateMessage struct { Elements []*GenericTemplateElement // contains filtered or unexported fields }
GenericTemplateMessage defines generic template message. A generic template message could have maximum of 10 elements.
func NewGenericTemplateMessage ¶
func NewGenericTemplateMessage(elements []*GenericTemplateElement) *GenericTemplateMessage
NewGenericTemplateMessage returns generic template element. A generic template message could have maximum of 10 elements.
func (*GenericTemplateMessage) MarshalJSON ¶
func (m *GenericTemplateMessage) MarshalJSON() ([]byte, error)
MarshalJSON returns json of the message.
func (*GenericTemplateMessage) TemplateType ¶
func (m *GenericTemplateMessage) TemplateType() TemplateType
TemplateType returns template type.
func (*GenericTemplateMessage) Type ¶
func (m *GenericTemplateMessage) Type() MessageType
Type returns message type.
type GetIceBreakersResponse ¶
type GetIceBreakersResponse struct {
Data []IceBreakers `json:"data"`
}
GetIceBreakersResponse defines get ice breaker api success response.
type GetUserProfileResponse ¶
type GetUserProfileResponse struct { ID string `json:"id"` Name string `json:"name"` ProfilePic string `json:"profile_pic"` }
GetUserProfileResponse defines instagram get user profile response.
type IceBreaker ¶
IceBreaker defines Ice Breaker. frequently asked question. https://developers.facebook.com/docs/messenger-platform/instagram/features/ice-breakers
func NewIceBreaker ¶
func NewIceBreaker(question string, payload string) *IceBreaker
NewIceBreaker returns a ice breaker.
func (*IceBreaker) MarshalJSON ¶
func (i *IceBreaker) MarshalJSON() ([]byte, error)
MarshalJSON returns json of the ice breaker.
type IceBreakers ¶
type IceBreakers struct {
IceBreakers []IceBreaker `json:"ice_breakers"`
}
IceBreakers holds list of ice breakers.
type ImageMessage ¶
type ImageMessage struct { ImageURL string // contains filtered or unexported fields }
ImageMessage defines image message.
func NewImageMessage ¶
func NewImageMessage(imageURL string) *ImageMessage
NewImageMessage returns a new image message.
func (*ImageMessage) MarshalJSON ¶
func (m *ImageMessage) MarshalJSON() ([]byte, error)
MarshalJSON returns json of the message.
type InstaBot ¶
type InstaBot interface { SendMessage(ctx context.Context, recipient string, message Message) (*SendMessageResponse, error) SetIceBreakers(ctx context.Context, iceBreakers []*IceBreaker) (*SetIceBreakersResponse, error) GetIceBreakers(ctx context.Context) (*GetIceBreakersResponse, error) DeleteIceBreakers(ctx context.Context) (*DeleteIceBreakersResponse, error) GetUserProfile(ctx context.Context, instagramUserID string) (*GetUserProfileResponse, error) }
InstaBot defines InstaBot client interface.
type LogInButton ¶
type LogInButton struct { URL string // contains filtered or unexported fields }
LogInButton defines log in button. https://developers.facebook.com/docs/messenger-platform/send-messages/buttons#login
func NewLogInButton ¶
func NewLogInButton(URL string) *LogInButton
NewLogInButton returns a new log in button.
func (*LogInButton) MarshalJSON ¶
func (b *LogInButton) MarshalJSON() ([]byte, error)
MarshalJSON returns json of the button.
type LogOutButton ¶
type LogOutButton struct {
// contains filtered or unexported fields
}
LogOutButton defines log out button. https://developers.facebook.com/docs/messenger-platform/send-messages/buttons#logout
func NewLogOutButton ¶
func NewLogOutButton() *LogOutButton
NewLogOutButton returns a new log out button.
func (*LogOutButton) MarshalJSON ¶
func (b *LogOutButton) MarshalJSON() ([]byte, error)
MarshalJSON returns json of the button.
type MediaShareMessage ¶
type MediaShareMessage struct { // contains filtered or unexported fields }
MediaShareMessage defines media share message.
func NewMediaShareMessage ¶
func NewMediaShareMessage(mediaID string) *MediaShareMessage
NewMediaShareMessage returns new media share message.
func (*MediaShareMessage) MarshalJSON ¶
func (m *MediaShareMessage) MarshalJSON() ([]byte, error)
MarshalJSON returns json of the message.
func (*MediaShareMessage) Type ¶
func (m *MediaShareMessage) Type() MessageType
Type returns message type.
type MessageType ¶
type MessageType string
MessageType defines instagram message type.
const ( MessageTypeText MessageType = MessageType("text") MessageTypeImage MessageType = MessageType("image") MessageTypeSticker MessageType = MessageType("sticker") MessageTypeReacton MessageType = MessageType("reaction") MessageTypeTemplate MessageType = MessageType("template") )
all message type. https://developers.facebook.com/docs/messenger-platform/instagram/features/send-message#supported-messages
type PostBackButton ¶
type PostBackButton struct { Title string Payload string // contains filtered or unexported fields }
PostBackButton defines post back button. https://developers.facebook.com/docs/messenger-platform/send-messages/buttons#postback
func NewPostBackButton ¶
func NewPostBackButton(title string, payload string) *PostBackButton
NewPostBackButton returns a new post back button.
func (*PostBackButton) MarshalJSON ¶
func (b *PostBackButton) MarshalJSON() ([]byte, error)
MarshalJSON returns json of the button.
type ProductTemplateElement ¶
type ProductTemplateElement struct {
ProductID string
}
ProductTemplateElement defines product template element. https://developers.facebook.com/docs/messenger-platform/send-messages/template/product
func NewProductTemplateElement ¶
func NewProductTemplateElement(productID string) *ProductTemplateElement
NewProductTemplateElement returns a new product template element.
func (*ProductTemplateElement) MarshalJSON ¶
func (e *ProductTemplateElement) MarshalJSON() ([]byte, error)
MarshalJSON marshal product template element to JSON.
type ProductTemplateMessage ¶
type ProductTemplateMessage struct { Elements []*ProductTemplateElement // contains filtered or unexported fields }
ProductTemplateMessage defines product template message. A product template message could have maximum of 10 elements.
func NewProductTemplateMessage ¶
func NewProductTemplateMessage(elements []*ProductTemplateElement) *ProductTemplateMessage
NewProductTemplateMessage returns product template element. A product template message could have maximum of 10 elements.
func (*ProductTemplateMessage) MarshalJSON ¶
func (m *ProductTemplateMessage) MarshalJSON() ([]byte, error)
MarshalJSON returns json of the message.
func (*ProductTemplateMessage) TemplateType ¶
func (m *ProductTemplateMessage) TemplateType() TemplateType
TemplateType returns template type.
func (*ProductTemplateMessage) Type ¶
func (m *ProductTemplateMessage) Type() MessageType
Type returns message type.
type QuickReply ¶
QuickReply defines quick reply. quick reply is only supported for text message on instagram platform. https://developers.facebook.com/docs/messenger-platform/instagram/features/quick-replies
func NewTextQuickReply ¶
func NewTextQuickReply(title string, payload string) *QuickReply
NewTextQuickReply returns Text type quick reply.
func (*QuickReply) MarshalJSON ¶
func (q *QuickReply) MarshalJSON() ([]byte, error)
MarshalJSON returns json of the quick reply item.
type QuickReplyType ¶
type QuickReplyType string
QuickReplyType defines quick reply content type.
const (
QuickReplyTypeText QuickReplyType = QuickReplyType("text")
)
all quick reply content type. Only text type quick reply is supported for instagram.
type Recipient ¶
type Recipient struct {
ID string `json:"id"`
}
Recipient defines instagram user with instagram_user_id. Recipient of a message or action.
type SendMessageResponse ¶
type SendMessageResponse struct { RecipientID string `json:"recipient_id"` MessageID string `json:"message_id"` }
SendMessageResponse send message api success response.
type Sender ¶
type Sender struct {
ID string `json:"id"`
}
Sender defines instagram user with instagram_user_id. Sender of a message or action.
type SetIceBreakersResponse ¶
type SetIceBreakersResponse struct {
Result string `json:"result"`
}
SetIceBreakersResponse defines set ice breaker api success response.
type StickerMessage ¶
type StickerMessage struct { Sticker StickerType // contains filtered or unexported fields }
StickerMessage defines sticker message.
func NewStickerMessage ¶
func NewStickerMessage(sticker StickerType) *StickerMessage
NewStickerMessage returns sticker message.
func (*StickerMessage) MarshalJSON ¶
func (m *StickerMessage) MarshalJSON() ([]byte, error)
MarshalJSON returns json of the message.
func (*StickerMessage) Type ¶
func (m *StickerMessage) Type() MessageType
Type returns message type.
type StickerType ¶
type StickerType string
StickerType defines sticker type.
const (
StickerTypeHeart StickerType = StickerType("like_heart")
)
all sticker type.
type TemplateDefaultAction ¶
type TemplateDefaultAction struct { URL string // contains filtered or unexported fields }
TemplateDefaultAction template default action.
func NewTemplateDefaultAction ¶
func NewTemplateDefaultAction(URL string) *TemplateDefaultAction
NewTemplateDefaultAction returns new TemplateDefaultAction.
func (*TemplateDefaultAction) MarshalJSON ¶
func (d *TemplateDefaultAction) MarshalJSON() ([]byte, error)
MarshalJSON returns json of the button.
type TemplateType ¶
type TemplateType string
TemplateType defines available template type.
const ( TemplateTypeProduct TemplateType = TemplateType("product") TemplateTypeGeneric TemplateType = TemplateType("generic") )
all template type. generic, product template are available on instagram.
type TextMessage ¶
type TextMessage struct { Text string // contains filtered or unexported fields }
TextMessage defines text message.
func NewTextMessage ¶
func NewTextMessage(text string, options ...TextMessageOption) *TextMessage
NewTextMessage returns a new text message.
func (*TextMessage) AttachQuickReplies ¶
func (m *TextMessage) AttachQuickReplies(quickReplies []*QuickReply)
AttachQuickReplies attach quick reply items to text message
func (*TextMessage) MarshalJSON ¶
func (m *TextMessage) MarshalJSON() ([]byte, error)
MarshalJSON returns json of the message.
type TextMessageOption ¶
type TextMessageOption func(*TextMessage)
TextMessageOption defines optional argument for new text message construction.
func WithQuickReplies ¶
func WithQuickReplies(quickReplyItems []*QuickReply) TextMessageOption
WithQuickReplies adds quick reply items to text message. Quick reply is only supported with text message.
type URLButton ¶
URLButton defines URL button. https://developers.facebook.com/docs/messenger-platform/send-messages/buttons#url
func NewURLButton ¶
NewURLButton returns a new url button.
func (*URLButton) MarshalJSON ¶
MarshalJSON returns json of the button.