commit
b90fe59765
@ -17,7 +17,6 @@ import (
|
|||||||
const (
|
const (
|
||||||
webhooksPath = "/webhooks"
|
webhooksPath = "/webhooks"
|
||||||
loginPath = "/signin"
|
loginPath = "/signin"
|
||||||
logoutPath = "/signout"
|
|
||||||
|
|
||||||
validUsername = "john"
|
validUsername = "john"
|
||||||
validPassword = "secret"
|
validPassword = "secret"
|
||||||
|
6
go.sum
Normal file
6
go.sum
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
|
||||||
|
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||||
|
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
||||||
|
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
||||||
|
github.com/stretchr/testify v1.2.2 h1:bSDNvY7ZPG5RlJ8otE/7V6gMiyenm9RtJ7IUVIAoJ1w=
|
||||||
|
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
|
@ -19,7 +19,7 @@ const (
|
|||||||
// SendSettingsURL is API endpoint for saving settings.
|
// SendSettingsURL is API endpoint for saving settings.
|
||||||
SendSettingsURL = "https://graph.facebook.com/v2.6/me/thread_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.
|
// MessengerProfileURL is the API endpoint where you 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>
|
// 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/
|
// https://developers.facebook.com/docs/messenger-platform/reference/messenger-profile-api/
|
||||||
MessengerProfileURL = "https://graph.facebook.com/v2.6/me/messenger_profile"
|
MessengerProfileURL = "https://graph.facebook.com/v2.6/me/messenger_profile"
|
||||||
@ -192,7 +192,7 @@ func (m *Messenger) ProfileByID(id int64, profileFields []string) (Profile, erro
|
|||||||
qr := QueryResponse{}
|
qr := QueryResponse{}
|
||||||
err = json.Unmarshal(content, &qr)
|
err = json.Unmarshal(content, &qr)
|
||||||
if qr.Error != nil {
|
if qr.Error != nil {
|
||||||
err = fmt.Errorf("Facebook error : %s", qr.Error.Message)
|
err = fmt.Errorf("facebook error: %s", qr.Error.Message)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -341,7 +341,7 @@ func (m *Messenger) checkIntegrity(r *http.Request) error {
|
|||||||
func (m *Messenger) dispatch(r Receive) {
|
func (m *Messenger) dispatch(r Receive) {
|
||||||
for _, entry := range r.Entry {
|
for _, entry := range r.Entry {
|
||||||
for _, info := range entry.Messaging {
|
for _, info := range entry.Messaging {
|
||||||
a := m.classify(info, entry)
|
a := m.classify(info)
|
||||||
if a == UnknownAction {
|
if a == UnknownAction {
|
||||||
fmt.Println("Unknown action:", info)
|
fmt.Println("Unknown action:", info)
|
||||||
continue
|
continue
|
||||||
@ -478,7 +478,7 @@ func (m *Messenger) EnableChatExtension(homeURL HomeURL) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// classify determines what type of message a webhook event is.
|
// classify determines what type of message a webhook event is.
|
||||||
func (m *Messenger) classify(info MessageInfo, e Entry) Action {
|
func (m *Messenger) classify(info MessageInfo) Action {
|
||||||
if info.Message != nil {
|
if info.Message != nil {
|
||||||
return TextAction
|
return TextAction
|
||||||
} else if info.Delivery != nil {
|
} else if info.Delivery != nil {
|
||||||
|
@ -56,7 +56,7 @@ func TestMessenger_Classify(t *testing.T) {
|
|||||||
},
|
},
|
||||||
} {
|
} {
|
||||||
t.Run("action "+name, func(t *testing.T) {
|
t.Run("action "+name, func(t *testing.T) {
|
||||||
action := m.classify(test.msgInfo, Entry{})
|
action := m.classify(test.msgInfo)
|
||||||
assert.Exactly(t, action, test.expected)
|
assert.Exactly(t, action, test.expected)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@ -1,17 +1,5 @@
|
|||||||
package messenger
|
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 {
|
type passThreadControl struct {
|
||||||
Recipient Recipient `json:"recipient"`
|
Recipient Recipient `json:"recipient"`
|
||||||
TargetAppID int64 `json:"target_app_id"`
|
TargetAppID int64 `json:"target_app_id"`
|
||||||
|
@ -77,8 +77,11 @@ func checkFacebookError(r io.Reader) error {
|
|||||||
|
|
||||||
qr := QueryResponse{}
|
qr := QueryResponse{}
|
||||||
err = json.NewDecoder(r).Decode(&qr)
|
err = json.NewDecoder(r).Decode(&qr)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("json unmarshal error: %s", err)
|
||||||
|
}
|
||||||
if qr.Error != nil {
|
if qr.Error != nil {
|
||||||
err = fmt.Errorf("Facebook error : %s", qr.Error.Message)
|
err = fmt.Errorf("facebook error: %s", qr.Error.Message)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user