Support for passThreadControl
This commit is contained in:
parent
faf2432c8f
commit
241e864fb3
2
.gitignore
vendored
2
.gitignore
vendored
@ -25,3 +25,5 @@ _testmain.go
|
||||
|
||||
# Configuration
|
||||
cmd/bot/config.json
|
||||
|
||||
.idea
|
||||
|
19
pass_thread_control.go
Normal file
19
pass_thread_control.go
Normal file
@ -0,0 +1,19 @@
|
||||
package messenger
|
||||
|
||||
import "encoding/json"
|
||||
|
||||
func unmarshalPassThreadControl(data []byte) (passThreadControl, error) {
|
||||
var r passThreadControl
|
||||
err := json.Unmarshal(data, &r)
|
||||
return r, err
|
||||
}
|
||||
|
||||
func (r *passThreadControl) marshal() ([]byte, error) {
|
||||
return json.Marshal(r)
|
||||
}
|
||||
|
||||
type passThreadControl struct {
|
||||
Recipient Recipient `json:"recipient"`
|
||||
TargetAppID int64 `json:"target_app_id"`
|
||||
Metadata string `json:"metadata"`
|
||||
}
|
35
response.go
35
response.go
@ -23,6 +23,10 @@ type ImageAspectRatio string
|
||||
const (
|
||||
// SendMessageURL is API endpoint for sending messages.
|
||||
SendMessageURL = "https://graph.facebook.com/v2.11/me/messages"
|
||||
// ThreadControlURL is the API endpoint for passing thread control.
|
||||
ThreadControlURL = "https://graph.facebook.com/v2.6/me/pass_thread_control"
|
||||
// InboxPageID is managed by facebook for secondary pass to inbox features: https://developers.facebook.com/docs/messenger-platform/handover-protocol/pass-thread-control
|
||||
InboxPageID = 263902037430900
|
||||
|
||||
// ImageAttachment is image attachment type.
|
||||
ImageAttachment AttachmentType = "image"
|
||||
@ -320,6 +324,37 @@ func (r *Response) DispatchMessage(m interface{}) error {
|
||||
return checkFacebookError(resp.Body)
|
||||
}
|
||||
|
||||
// PassThreadToInbox Uses Messenger Handover Protocol for live inbox
|
||||
// https://developers.facebook.com/docs/messenger-platform/handover-protocol/#inbox
|
||||
func (r *Response) PassThreadToInbox() error {
|
||||
p := passThreadControl{
|
||||
Recipient: r.to,
|
||||
TargetAppID: InboxPageID,
|
||||
Metadata: "Passing to inbox secondary app",
|
||||
}
|
||||
|
||||
data, err := json.Marshal(p)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
req, err := http.NewRequest("POST", ThreadControlURL, bytes.NewBuffer(data))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
req.Header.Set("Content-Type", "application/json")
|
||||
req.URL.RawQuery = "access_token=" + r.token
|
||||
|
||||
resp, err := http.DefaultClient.Do(req)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
|
||||
return checkFacebookError(resp.Body)
|
||||
}
|
||||
|
||||
// SendMessage is the information sent in an API request to Facebook.
|
||||
type SendMessage struct {
|
||||
MessagingType MessagingType `json:"messaging_type"`
|
||||
|
Loading…
Reference in New Issue
Block a user