admin管理员组文章数量:1295901
I am building a Node.js application that receives messages from WhatsApp via Twilio. Sending text messages is not a problem, but when I try to send the current location from the users WhatsApp account I cannot find the coordinates in the request object sent to the server.
This is what I am doing to see what is being sent to the app from Twilio.
app.post('/ining', (req, res) => {
var iningMessage = req.body.Body;
console.log(iningMessage); });
When I share my current location with the app, the request body is empty.
Can anyone shed any light on this or explain how WhatsApp shares a users location within the app?
Thanks.
I am building a Node.js application that receives messages from WhatsApp via Twilio. Sending text messages is not a problem, but when I try to send the current location from the users WhatsApp account I cannot find the coordinates in the request object sent to the server.
This is what I am doing to see what is being sent to the app from Twilio.
app.post('/ining', (req, res) => {
var iningMessage = req.body.Body;
console.log(iningMessage); });
When I share my current location with the app, the request body is empty.
Can anyone shed any light on this or explain how WhatsApp shares a users location within the app?
Thanks.
Share Improve this question edited Sep 23, 2019 at 2:10 swifft asked Sep 21, 2019 at 15:24 swifftswifft 1211 gold badge2 silver badges7 bronze badges7 Answers
Reset to default 3Twilio developer evangelist here.
Update: since 12th Nov 2019 Twilio does support location in WhatsApp messages
When a user sends a location message to your Twilio enabled WhatsApp number, Twilio will send on the details as parameters in the webhook request to your application. The parameters are: Latitude
, Longitude
and optionally Label
and Address
if the user sent a specific place.
In your Node application you are able to read these from the request's body like this:
app.post('/ining', (req, res) => {
const longitude = req.body.Longitude;
const latitude = req.body.Latitude;
console.log(`The user sent this from ${longitude}, ${latitude}`);
// do something with the location data
})
Check out these blog posts on how to use location data from WhatsApp to search nearby restaurants or how to build a location aware weather bot with the Twilio API for WhatsApp.
Original answer from September 23rd 2019:
The Twilio API for WhatsApp doesn't currently support sending or receiving location coordinates.
At the moment it is possible to send to the user some location but you can't get user location directly through twilio whatsapp api. https://www.twilio./blog/send-location-details-whatsapp-node-js.
Here it says is it possible to recieve location data on the Body: https://www.twilio./docs/whatsapp/api#location-messages-with-whatsapp
You can also receive inbound location messages with the Twilio API for WhatsApp. Locations will not show up in the Twilio Console at this time. However, your web application will receive the location data in the POST request that Twilio sends. Below is a sample payload containing location information. Please note that the
Body={name}
parameter is not required for inbound messages.
Latitude=37.7879277&Longitude=-122.3937508&Address=375+Beale+St%2C+San+Francisco%2C+CA+94105&SmsMessageSid=SMxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx&NumMedia=0&SmsSid=SMxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx&Label=Twilio+Inc&Body=&To=whatsapp%3A%2B14155238886&NumSegments=1&MessageSid=SMxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx&AccountSid=ACxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx&From=whatsapp%3A%2B12345678900&ApiVersion=2010-04-01
Update your code with:
var iningMessage = req.body;
Twilio supporting both sending and receiving location. The below one is the response of the location when a user sends from his WhatsApp to the Twilio WhatsApp.
{
"Latitude": "24.7969323",
"Longitude": "46.6301663",
"SmsMessageSid": "xxxxxxxxxxxxxxxxxxxxxx",
"NumMedia": "0",
"SmsSid": "xxxxxxxxxxxxxxxxxxxxxx",
"SmsStatus": "received",
"Body": "",
"To": "whatsapp:+1415xxxxxxx",
"NumSegments": "1",
"MessageSid": "xxxxxxxxxxxxxxxxxxxxxx",
"AccountSid": "xxxxxxxxxxxxxxxxxxxxxx",
"From": "whatsapp:+966xxxxxxxxxxxxxxxxxxxxxx",
"ApiVersion": "2010-04-01"
}
Here you can see the Latitude and Longitude of the user.
I solved the issue by installing Google Earth on the same phone. Then I clicked the WhatsApp location share, and opened it with Google Earth.
Google Earth showed the coordinates in geographic degrees, minutes and seconds.
Go to Your Phone Menu.
Find WhatsApp.
Tap on the WhatsApp Icon.
Make Sure That, You Are on the Chats Tab.
Tap on the “Group” or “Individual Chat” Where You Want to Share Your Live Location.
Tap on the “Attach Icon”.
Tap on the “Location”.
Tap on the “Share Live Location
Simply prompt user to open a pany webpage that contains Javascript that capture user's location You can read more detail in here: https://ma-zamroni.medium./workaround-for-whatsapp-business-api-to-get-customers-current-location-392c63b4b365
本文标签: javascriptHow can I retrieve the location coordinates from a WhatsApp location shareStack Overflow
版权声明:本文标题:javascript - How can I retrieve the location coordinates from a WhatsApp location share? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741627773a2389179.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论