Code Monkey home page Code Monkey logo

Comments (10)

gauravtiwari avatar gauravtiwari commented on May 18, 2024 8
require 'httparty' # (if not already required)
include HTTParty

def get_sender_profile(sender)
  request = HTTParty.get(
    "https://graph.facebook.com/v2.6/#{sender['id']}",
    query: {
      access_token: ENV['ACCESS_TOKEN'],
      fields: 'first_name,last_name,gender,profile_pic'
    }
  )

  request.parsed_response
end

# Once you have a message: 
Bot.on :message do |message|
  sender = get_sender_profile(message.sender)
  puts sender.inspect
end

I haven't tested this so, please refer to the API docs.

from facebook-messenger.

gauravtiwari avatar gauravtiwari commented on May 18, 2024 1

@alecrubin Can you not query the profile info from FB using the Sender ID? https://developers.facebook.com/docs/graph-api/reference/v2.6/user

For ex: Send a get request for this url: https://graph.facebook.com/v2.6/#{id}

See more here: https://developers.facebook.com/tools/explorer/

from facebook-messenger.

jgorset avatar jgorset commented on May 18, 2024 1

I agree with both of you; you'll want it very often, but it's not the right thing for this library to do. Let's add a bit about Graph API clients like Koala to the README.

from facebook-messenger.

gauravtiwari avatar gauravtiwari commented on May 18, 2024

Oops! guess you asked something different @alecrubin, but not very clear. You mean, to return via Payload?

from facebook-messenger.

jgorset avatar jgorset commented on May 18, 2024

Nope, I think you nailed it, @gauravtiwari! I'm closing this pending a response from @alecrubin.

from facebook-messenger.

gauravtiwari avatar gauravtiwari commented on May 18, 2024

@jgorset cool 🎉

Btw, @alecrubin you can refer to this class: https://github.com/hyperoslo/facebook-messenger-demo/blob/master/app/bots/product_bot.rb, it has a lot of implementations for Bot API (even sending serialised data via Payload).

from facebook-messenger.

zdne avatar zdne commented on May 18, 2024

@gauravtiwari any chance adding this to the library? The code is trivial but re-writting the HTTParty error handling isn't fun ..

from facebook-messenger.

gauravtiwari avatar gauravtiwari commented on May 18, 2024

Hey @zdne, Yeah we could, but this library is not intended for fetching Facebook Graph data. Adding it here would make the library heavy and violate SRP. Perhaps, you could use - Koala to interact with Graph API: https://github.com/arsduo/koala/wiki/Graph-API

Would this work?

from facebook-messenger.

zdne avatar zdne commented on May 18, 2024

Hey, thanks for the response. I get and respect your point completely. However if I could argue I'd say this is almost always one thing you want to do with the bot. In any case, I'd suggest to add your comment to the README (with link to the koala)? Just my 2cents.

from facebook-messenger.

gauravtiwari avatar gauravtiwari commented on May 18, 2024

@zdne Totally agree and it's very small thing, but just for SRP sake. Awesome! We will definitely add this to Readme, and you can totally do this too - just make a PR and we will merge it right in 👍

from facebook-messenger.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.