Comments (10)
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.
@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.
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.
Oops! guess you asked something different @alecrubin, but not very clear. You mean, to return via Payload?
from facebook-messenger.
Nope, I think you nailed it, @gauravtiwari! I'm closing this pending a response from @alecrubin.
from facebook-messenger.
@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.
@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.
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.
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.
@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)
- Message tag field name discrepancy? HOT 2
- Multiple bots HOT 3
- How to find password HOT 1
- global "include Facebook::Messenger" bad style and possibly dangerous? HOT 1
- https://jsbin.com/ihunin/edit?html,js,output
- `hexdigest': no implicit conversion of nil into String (TypeError) HOT 1
- webhook OK 200 response
- Help
- Instagram Messenger support
- Dynamic graph api version
- Dynamic graph api version HOT 1
- (#283) Requires manage_pages permission to manage the object
- (#100) Cannot set persistent menu because your app is not set as the primary app for the page. HOT 1
- Messenger
- Lol
- To subscribe to the feed field, one of these permissions is needed: pages_manage_metadata HOT 1
- Messengers
- typo in instruction
- Not support event feed ?
- You
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from facebook-messenger.