ability to specify send api version
This commit is contained in:
parent
da2c3ee447
commit
c4c6c4faa3
13
messenger.go
13
messenger.go
@ -48,6 +48,8 @@ type Options struct {
|
|||||||
WebhookURL string
|
WebhookURL string
|
||||||
// Mux is shared mux between several Messenger objects
|
// Mux is shared mux between several Messenger objects
|
||||||
Mux *http.ServeMux
|
Mux *http.ServeMux
|
||||||
|
// SendAPIVersion is a Send API version
|
||||||
|
SendAPIVersion string
|
||||||
}
|
}
|
||||||
|
|
||||||
// MessageHandler is a handler used for responding to a message containing text.
|
// MessageHandler is a handler used for responding to a message containing text.
|
||||||
@ -86,6 +88,7 @@ type Messenger struct {
|
|||||||
verifyHandler func(http.ResponseWriter, *http.Request)
|
verifyHandler func(http.ResponseWriter, *http.Request)
|
||||||
verify bool
|
verify bool
|
||||||
appSecret string
|
appSecret string
|
||||||
|
sendAPIVersion string
|
||||||
}
|
}
|
||||||
|
|
||||||
// New creates a new Messenger. You pass in Options in order to affect settings.
|
// New creates a new Messenger. You pass in Options in order to affect settings.
|
||||||
@ -99,12 +102,17 @@ func New(mo Options) *Messenger {
|
|||||||
token: mo.Token,
|
token: mo.Token,
|
||||||
verify: mo.Verify,
|
verify: mo.Verify,
|
||||||
appSecret: mo.AppSecret,
|
appSecret: mo.AppSecret,
|
||||||
|
sendAPIVersion: mo.SendAPIVersion,
|
||||||
}
|
}
|
||||||
|
|
||||||
if mo.WebhookURL == "" {
|
if mo.WebhookURL == "" {
|
||||||
mo.WebhookURL = "/"
|
mo.WebhookURL = "/"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if m.sendAPIVersion == "" {
|
||||||
|
m.sendAPIVersion = DefaultSendAPIVersion
|
||||||
|
}
|
||||||
|
|
||||||
m.verifyHandler = newVerifyHandler(mo.VerifyToken)
|
m.verifyHandler = newVerifyHandler(mo.VerifyToken)
|
||||||
m.mux.HandleFunc(mo.WebhookURL, m.handle)
|
m.mux.HandleFunc(mo.WebhookURL, m.handle)
|
||||||
|
|
||||||
@ -368,6 +376,7 @@ func (m *Messenger) dispatch(r Receive) {
|
|||||||
resp := &Response{
|
resp := &Response{
|
||||||
to: Recipient{info.Sender.ID},
|
to: Recipient{info.Sender.ID},
|
||||||
token: m.token,
|
token: m.token,
|
||||||
|
sendAPIVersion: m.sendAPIVersion,
|
||||||
}
|
}
|
||||||
|
|
||||||
switch a {
|
switch a {
|
||||||
@ -429,6 +438,7 @@ func (m *Messenger) Response(to int64) *Response {
|
|||||||
return &Response{
|
return &Response{
|
||||||
to: Recipient{to},
|
to: Recipient{to},
|
||||||
token: m.token,
|
token: m.token,
|
||||||
|
sendAPIVersion: m.sendAPIVersion,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -442,6 +452,7 @@ func (m *Messenger) SendGeneralMessage(to Recipient, elements *[]StructuredMessa
|
|||||||
r := &Response{
|
r := &Response{
|
||||||
token: m.token,
|
token: m.token,
|
||||||
to: to,
|
to: to,
|
||||||
|
sendAPIVersion: m.sendAPIVersion,
|
||||||
}
|
}
|
||||||
return r.GenericTemplate(elements, messagingType, metadata, tags...)
|
return r.GenericTemplate(elements, messagingType, metadata, tags...)
|
||||||
}
|
}
|
||||||
@ -451,6 +462,7 @@ func (m *Messenger) SendWithReplies(to Recipient, message string, replies []Quic
|
|||||||
response := &Response{
|
response := &Response{
|
||||||
token: m.token,
|
token: m.token,
|
||||||
to: to,
|
to: to,
|
||||||
|
sendAPIVersion: m.sendAPIVersion,
|
||||||
}
|
}
|
||||||
|
|
||||||
return response.TextWithReplies(message, replies, messagingType, metadata, tags...)
|
return response.TextWithReplies(message, replies, messagingType, metadata, tags...)
|
||||||
@ -461,6 +473,7 @@ func (m *Messenger) Attachment(to Recipient, dataType AttachmentType, url string
|
|||||||
response := &Response{
|
response := &Response{
|
||||||
token: m.token,
|
token: m.token,
|
||||||
to: to,
|
to: to,
|
||||||
|
sendAPIVersion: m.sendAPIVersion,
|
||||||
}
|
}
|
||||||
|
|
||||||
return response.Attachment(dataType, url, messagingType, metadata, tags...)
|
return response.Attachment(dataType, url, messagingType, metadata, tags...)
|
||||||
|
13
response.go
13
response.go
@ -23,10 +23,12 @@ type TopElementStyle string
|
|||||||
type ImageAspectRatio string
|
type ImageAspectRatio string
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
// DefaultSendAPIVersion is a default Send API version
|
||||||
|
DefaultSendAPIVersion = "v2.11"
|
||||||
// SendMessageURL is API endpoint for sending messages.
|
// SendMessageURL is API endpoint for sending messages.
|
||||||
SendMessageURL = "https://graph.facebook.com/v2.11/me/messages"
|
SendMessageURL = "https://graph.facebook.com/%s/me/messages"
|
||||||
// ThreadControlURL is the API endpoint for passing thread control.
|
// ThreadControlURL is the API endpoint for passing thread control.
|
||||||
ThreadControlURL = "https://graph.facebook.com/v2.6/me/pass_thread_control"
|
ThreadControlURL = "https://graph.facebook.com/%s/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 is managed by facebook for secondary pass to inbox features: https://developers.facebook.com/docs/messenger-platform/handover-protocol/pass-thread-control
|
||||||
InboxPageID = 263902037430900
|
InboxPageID = 263902037430900
|
||||||
|
|
||||||
@ -112,6 +114,7 @@ func getFacebookQueryResponse(r io.Reader) (QueryResponse, error) {
|
|||||||
type Response struct {
|
type Response struct {
|
||||||
token string
|
token string
|
||||||
to Recipient
|
to Recipient
|
||||||
|
sendAPIVersion string
|
||||||
}
|
}
|
||||||
|
|
||||||
// SetToken is for using DispatchMessage from outside.
|
// SetToken is for using DispatchMessage from outside.
|
||||||
@ -249,7 +252,7 @@ func (r *Response) AttachmentData(dataType AttachmentType, filename string, file
|
|||||||
multipartWriter.WriteField("recipient", fmt.Sprintf(`{"id":"%v"}`, r.to.ID))
|
multipartWriter.WriteField("recipient", fmt.Sprintf(`{"id":"%v"}`, r.to.ID))
|
||||||
multipartWriter.WriteField("message", fmt.Sprintf(`{"attachment":{"type":"%v", "payload":{}}}`, dataType))
|
multipartWriter.WriteField("message", fmt.Sprintf(`{"attachment":{"type":"%v", "payload":{}}}`, dataType))
|
||||||
|
|
||||||
req, err := http.NewRequest("POST", SendMessageURL, &body)
|
req, err := http.NewRequest("POST", fmt.Sprintf(SendMessageURL, r.sendAPIVersion), &body)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return qr, err
|
return qr, err
|
||||||
}
|
}
|
||||||
@ -365,7 +368,7 @@ func (r *Response) DispatchMessage(m interface{}) (QueryResponse, error) {
|
|||||||
return res, err
|
return res, err
|
||||||
}
|
}
|
||||||
|
|
||||||
req, err := http.NewRequest("POST", SendMessageURL, bytes.NewBuffer(data))
|
req, err := http.NewRequest("POST", fmt.Sprintf(SendMessageURL, r.sendAPIVersion), bytes.NewBuffer(data))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return res, err
|
return res, err
|
||||||
}
|
}
|
||||||
@ -397,7 +400,7 @@ func (r *Response) PassThreadToInbox() error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
req, err := http.NewRequest("POST", ThreadControlURL, bytes.NewBuffer(data))
|
req, err := http.NewRequest("POST", fmt.Sprintf(ThreadControlURL, r.sendAPIVersion), bytes.NewBuffer(data))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user