How To Send Location Details on WhatsApp in Node JS
Time to read: 2 minutes
WhatsApp is one of the most preferred mobile messaging applications in the world with over 1.5 billion active monthly global users. Since the introduction of WhatsApp business, companies have leveraged this API to engage with their customers to send order or payment notifications, appointment reminders, and shipping alerts among others. One of the key reasons for increased adoption and trust of WhatsApp for users and businesses is the secure end-to-end encryption. Users can share user contacts, documents, locations, and different types of media such as images, audio, and videos. The Twilio API for WhatsApp recently added support for read receipts and location messages. In this tutorial, I will take you through how to send location messages using the Twilio API for WhatsApp.
Prerequisites
To complete this tutorial you will need the following:
Getting Started
In your preferred terminal, run the following commands to set up the project:
The commands above created a folder to store all of your project files named demo
. A package.json
file was created by running npm init -y
which will keep track of all the packages like axios
and dotenv
. These two packages are responsible for making HTTP requests and accessing environment variables respectively.
Activating Twilio WhatsApp Sandbox
After obtaining a free account from Twilio, create a project under the Programmable SMS product. You should be redirected to the screen below:
To activate the WhatsApp sandbox, click on Get Started and navigate to the WhatsApp Beta page. Send the indicated code to +1 415 523 8886
from your device.
In my case, I’ll send join smooth-took
to +1 415 523 8886
Using your preferred code editor, add the following lines of code inside your test.js
file.
Note: Replace To
with your actual phone number.
In your .env
file, add:
Note: Be sure to replace the above keys with their actual values. They can be obtained from the Twilio console.
Testing
In your terminal, run:
You should receive a text on your phone including geolocation.
Conclusion
In this tutorial, we have learned how to send location details via Twilio API for
WhatsApp. At the time of writing, this feature is only available via CURL and is yet to roll out to the Twilio packages and Twilio CLI. I would love to hear from you! Let’s connect on Twitter or send me an email. Happy hacking!
Related Posts
Related Resources
Twilio Docs
From APIs to SDKs to sample apps
API reference documentation, SDKs, helper libraries, quickstarts, and tutorials for your language and platform.
Resource Center
The latest ebooks, industry reports, and webinars
Learn from customer engagement experts to improve your own communication.
Ahoy
Twilio's developer community hub
Best practices, code samples, and inspiration to build communications and digital engagement experiences.