Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get user's location from Facebook chatbot api

I was wondering how I could get a user's location from a Facebook messenger chatbot. What I want to accomplish is the following: the chatbot will say something like "Please send me your location", and then the user would tap the "Share Location" on the Facebook messenger app. I have figured out how to get a textual message that the user sends, but not the location. Thanks in advance!

like image 547
Daniel Smith Avatar asked Jan 21 '26 21:01

Daniel Smith


1 Answers

Location can be obtained as well as text. More precisely, as the photo. You need take message.attachments.payload.coordinates. Also you can check message.attachments.type.

example:

{
   "object": "page",
   "entry": [{
       "id": "1719442148306048",
       "time": 1466780344978,
       "messaging": [{
           "sender": {"id": "123456789"},
           "recipient": {"id": "987654321"},
           "timestamp": 1466780344847,
           "message": {
               "mid": "mid.12345698875:c80066d69b6cee1779",
               "seq": 65,
               "attachments": [{
                   "title": "Dmitry's Location",
                   "url": "Link to bing.com through facebook redirect"
                   "type": "location",
                   "payload": {"coordinates": {"lat": 55, "long": 37}}
               }]
           }
       }]
   }]
}
like image 103
Dmitry Avatar answered Jan 23 '26 11:01

Dmitry



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!