Skip to content
This repository has been archived by the owner on Jan 1, 2023. It is now read-only.

Commit

Permalink
Merge pull request #51 from OAyomide/master
Browse files Browse the repository at this point in the history
remove default profile fields; fix minor typo
  • Loading branch information
paked authored Jan 4, 2019
2 parents 8a7cca0 + 5184626 commit ca367dc
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 25 deletions.
2 changes: 1 addition & 1 deletion examples/basic/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ func main() {
client.HandleMessage(func(m messenger.Message, r *messenger.Response) {
fmt.Printf("%v (Sent, %v)\n", m.Text, m.Time.Format(time.UnixDate))

p, err := client.ProfileByID(m.Sender.ID)
p, err := client.ProfileByID(m.Sender.ID, []string{"name", "first_name", "last_name", "profile_pic"})
if err != nil {
fmt.Println("Something went wrong!", err)
}
Expand Down
2 changes: 1 addition & 1 deletion examples/extension/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ func main() {
client.HandleMessage(func(m messenger.Message, r *messenger.Response) {
fmt.Printf("%v (Sent, %v)\n", m.Text, m.Time.Format(time.UnixDate))

p, err := client.ProfileByID(m.Sender.ID)
p, err := client.ProfileByID(m.Sender.ID, []string{"name", "first_name", "last_name", "profile_pic"})
if err != nil {
fmt.Println("Something went wrong!", err)
}
Expand Down
2 changes: 1 addition & 1 deletion examples/linked-account/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ func main() {
client.HandleMessage(func(m messenger.Message, r *messenger.Response) {
log.Printf("%v (Sent, %v)\n", m.Text, m.Time.Format(time.UnixDate))

p, err := client.ProfileByID(m.Sender.ID)
p, err := client.ProfileByID(m.Sender.ID, []string{"name", "first_name", "last_name", "profile_pic"})
if err != nil {
log.Println("Failed to fetch user profile:", err)
}
Expand Down
2 changes: 1 addition & 1 deletion message.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package messenger

import "time"

// Message represents a Facebook messenge message.
// Message represents a Facebook messenger message.
type Message struct {
// Sender is who the message was sent from.
Sender Sender `json:"-"`
Expand Down
32 changes: 11 additions & 21 deletions messenger.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,6 @@ const (
MessengerProfileURL = "https://graph.facebook.com/v2.6/me/messenger_profile"
)

var (
// NOTE: If you change this slice you should update the comment on the ProfileByID function below too.
defaultProfileFields = []string{"first_name", "last_name", "profile_pic", "locale", "timezone", "gender"}
)

// Options are the settings used when creating a Messenger client.
type Options struct {
// Verify sets whether or not to be in the "verify" mode. Used for
Expand Down Expand Up @@ -154,17 +149,16 @@ func (m *Messenger) Handler() http.Handler {
return m.mux
}

// ProfileByID retrieves the Facebook user profile associated with that ID
// when no profile fields are specified it uses some sane defaults.
//
// These default fields are:
// - First name
// - Last name
// - Profile picture
// - Locale
// - Timezone
// - Gender
func (m *Messenger) ProfileByID(id int64, profileFields ...string) (Profile, error) {
// ProfileByID retrieves the Facebook user profile associated with that ID.
// According to the messenger docs: https://developers.facebook.com/docs/messenger-platform/identity/user-profile,
// Developers must ask for access except for some fields that are accessible without permissions.
//
// At the time of writing (2019-01-04), these fields are
// - Name
// - First Name
// - Last Name
// - Profile Picture
func (m *Messenger) ProfileByID(id int64, profileFields []string) (Profile, error) {
p := Profile{}
url := fmt.Sprintf("%v%v", ProfileURL, id)

Expand All @@ -173,10 +167,6 @@ func (m *Messenger) ProfileByID(id int64, profileFields ...string) (Profile, err
return p, err
}

if len(profileFields) == 0 {
profileFields = defaultProfileFields
}

fields := strings.Join(profileFields, ",")

req.URL.RawQuery = "fields=" + fields + "&access_token=" + m.token
Expand Down Expand Up @@ -242,7 +232,7 @@ func (m *Messenger) GreetingSetting(text string) error {
return checkFacebookError(resp.Body)
}

// CallToActionsSetting sends settings for Get Started or Persist Menu
// CallToActionsSetting sends settings for Get Started or Persistent Menu
func (m *Messenger) CallToActionsSetting(state string, actions []CallToActionsItem) error {
d := CallToActionsSetting{
SettingType: "call_to_actions",
Expand Down
1 change: 1 addition & 0 deletions profile.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package messenger

// Profile is the public information of a Facebook user
type Profile struct {
Name string `json:"name"`
FirstName string `json:"first_name"`
LastName string `json:"last_name"`
ProfilePicURL string `json:"profile_pic"`
Expand Down

0 comments on commit ca367dc

Please sign in to comment.