feat: EnableChatExtension
This commit is contained in:
parent
3dda3ecdde
commit
7dec871473
34
messenger.go
34
messenger.go
@ -20,6 +20,11 @@ const (
|
||||
ProfileFields = "first_name,last_name,profile_pic,locale,timezone,gender"
|
||||
// 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"
|
||||
)
|
||||
|
||||
// Options are the settings used when creating a Messenger client.
|
||||
@ -435,6 +440,35 @@ func (m *Messenger) Attachment(to Recipient, dataType AttachmentType, url string
|
||||
return response.Attachment(dataType, url, messagingType, tags...)
|
||||
}
|
||||
|
||||
// EnableChatExtension set the homepage url required for a chat extension.
|
||||
func (m *Messenger) EnableChatExtension(homeURL HomeURL) error {
|
||||
wrap := map[string]interface{}{
|
||||
"home_url": homeURL,
|
||||
}
|
||||
data, err := json.Marshal(wrap)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
req, err := http.NewRequest("POST", MessengerProfileURL, bytes.NewBuffer(data))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
req.Header.Set("Content-Type", "application/json")
|
||||
req.URL.RawQuery = "access_token=" + m.token
|
||||
|
||||
client := &http.Client{}
|
||||
|
||||
resp, err := client.Do(req)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
|
||||
return checkFacebookError(resp.Body)
|
||||
}
|
||||
|
||||
// classify determines what type of message a webhook event is.
|
||||
func (m *Messenger) classify(info MessageInfo, e Entry) Action {
|
||||
if info.Message != nil {
|
||||
|
@ -44,3 +44,12 @@ type CallToActionsItem struct {
|
||||
WebviewHeightRatio string `json:"webview_height_ratio,omitempty"`
|
||||
MessengerExtension bool `json:"messenger_extensions,omitempty"`
|
||||
}
|
||||
|
||||
// HomeURL is the settings for EnableChatExtension
|
||||
// https://developers.facebook.com/docs/messenger-platform/reference/messenger-profile-api/home-url
|
||||
type HomeURL struct {
|
||||
URL string `json:"url,omitempty"`
|
||||
WebviewHeightRatio string `json:"webview_height_ratio,omitempty"`
|
||||
WebviewShareButton string `json:"webview_share_button,omitempty"`
|
||||
InTest bool `json:"in_test,omitempty"`
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user