Connect with us

FACEBOOK

Sending Messages via WhatsApp in Your Node.js Application

Published

on

sending-messages-via-whatsapp-in-your-node.js-application

WhatsApp is one of the world’s most popular mobile messenger apps, with nearly two billion monthly active users. Businesses can leverage the WhatsApp Business Platform to communicate closely with their audiences, help boost sales, and transform the customer experience.

This article describes how the Cloud API, hosted by Meta, Meta’s integration of the WhatsApp Business Platform, can be used in a Node.js application to provide the capability to send and manage WhatsApp messages sent and received via the Cloud API.

Let’s dive in and explore how to create a Node.js web app powered with WhatsApp messaging from scratch to send a simple text-based message and then using message templates for more detailed messages. If you’d like a preview of where you’ll end up, you can download the complete application code.

Prerequisites

To send and receive messages using a test phone number, follow the Set up Developer Assets and Platform Access tutorial, making sure you complete the steps below.

First, you’ll need to download and install Node.js and npm on your machine, if you don’t have it installed already.

Advertisement
free widgets for website

Next, Register for a free account as a developer with Meta for Developers.

Enable two-factor authentication for your account.

Create a Meta App. The App ID and the App Secret will be used later in this tutorial.

Connect your Meta App with the WhatsApp product.

Then, associate your app with a Business Manager account.

Advertisement
free widgets for website

On the App Dashboard, open the WhatsApp > Get Started menu and configure a recipient phone number. Your app will need it as a recipient for the WhatsApp messages. This number will be used later on.

Create a system user for your Business Account. For a more detailed walkthrough, see our Business Manager documentation.

On the System Users page, generate a new token for your new system user. Assign your app all the available permissions. This token will be used later in this article.

On the System Users page, configure the assets to your System User, assigning your app with full control. Don’t forget to click the Save Changes button.

The App We’re Building

This small sample application will work as an online movie ticket purchase and booking service. The application will use the API to provide the user with an engaging and more personalized experience than email communication. When the users log in, they’re greeted by a WhatsApp message. Then, when they buy a movie ticket, they receive a message confirming the purchase.

Advertisement
free widgets for website

Creating a Minimal App with Node.js and Express

To get started, you need to get a new Node.js project up and running. We’ll use EJS as a lightweight JavaScript templating engine and Express, the minimalist web framework for Node.js.

Open terminal/command prompt and create a folder for your project to live in. Then execute the npm init command from the root of your project folder to initialize your project to use npm packages:

 npm init 

Create a starter application using express-generator:

 npx express-generator -v ejs 

Next, run the following command to install the packages and resolve their dependencies:

 npm install 

Finally, execute the following command to start the server and host your app locally:

Advertisement
free widgets for website
 npm start 

Now visit http://localhost:3000, and you’ll see the homepage of your Node + Express starter application:

See also  Augusta Co. supervisor takes issue over sheriff's Facebook post about funding body cameras

Creating the Sample Login Page

To start your movie ticket application, you’ll create a sample login form that will work as your homepage. You’ll need to call the render function of the Response object to render a view from a separate HTML file.

Open the routesindex.js file and replace its code with the following contents:

 var express = require('express'); var router = express.Router();  /* GET home page. */ router.get('/', function(req, res, next) {   res.render('index', { title: 'Login' }); });  module.exports = router; 

Next, open the viewsindex.ejs file and add the HTML content below. Here, you’re creating a sample form login that comes with a stand-in login and password, so that you don’t need to provide those to use the application.

For your web app front end, use Bootstrap. This popular library will help you build a consistent, lightweight UI that comes with responsive styling, allowing you to easily run your app across devices with simplified CSS rules.

Advertisement
free widgets for website
         Movie Ticket Demo for Node.js     

Movie Ticket Demo for Node.js

Login image

Then, restart the app again to see the new login page, by using CTRL+C and the command:

 npm start 

Sending Text Messages with Node.js and WhatsApp Business

Your Node.js application will need to use specific data from your Meta developer account created in the beginning of this article. For the convenience of having all of your configuration in one place, and not scattered throughout code during development, place it in a file.

Create a .env file at the project root with the following configurations:

APP_ID=<> APP_SECRET=<> RECIPIENT_WAID=<> VERSION=v13.0 PHONE_NUMBER_ID=<> ACCESS_TOKEN=<>

Note: Replace each of the above settings with data from your WhatsApp Business account Dashboard.

Your login form action tells the app to POST to the /welcome route. So, you’ll need a new router to:

  • Handle the “welcome” HTTP POST request.
  • Obtain the configuration needed for the welcome message.
  • Send a welcome message via the API.
  • Redirect the app to the homepage once the message is sent

Next, create a new routeswelcome.js file with the following code:

 var express = require('express'); var router = express.Router(); var bodyParser = require('body-parser'); require('dotenv').config() const { sendMessage, getTextMessageInput } = require("../messageHelper");  router.use(bodyParser.json());  router.post('/', function(req, res, next) {   var data = getTextMessageInput(process.env.RECIPIENT_WAID, 'Welcome to the Movie Ticket Demo App for Node.js!');      sendMessage(data)     .then(function (response) {       res.redirect('/);       res.sendStatus(200);       return;     })     .catch(function (error) {       console.log(error);       console.log(error.response.data);       res.sendStatus(500);       return;     }); });  module.exports = router; 

Next, you’ll need the function to encapsulate the code that sends basic text messages via the API. Create a new messageHelper.js file at the project root with the following code:

Advertisement
free widgets for website
 var axios = require('axios');  function sendMessage(data) {   var config = {     method: 'post',     url: `https://graph.facebook.com/${process.env.VERSION}/${process.env.PHONE_NUMBER_ID}/messages`,     headers: {       'Authorization': `Bearer ${process.env.ACCESS_TOKEN}`,       'Content-Type': 'application/json'     },     data: data   };    return axios(config) }  function getTextMessageInput(recipient, text) {   return JSON.stringify({     "messaging_product": "whatsapp",     "preview_url": false,     "recipient_type": "individual",     "to": recipient,     "type": "text",     "text": {         "body": text     }   }); }  module.exports = {   sendMessage: sendMessage,   getTextMessageInput: getTextMessageInput }; 

The code above makes an HTTP POST request to the /messages endpoint on the Meta Graph API at graph.facebook.com, passing:

  • The Cloud API version you’re working with
  • The test phone number that will receive the message (you’ve already configured that)
  • The access token you generated for your System User

Also, note that the getTextMessageInput function returns a specific data structure required for sending basic text messages.

Moving on, open the app.js file and create a router variable for the /welcome route:

 var welcomeRouter = require('./routes/welcome'); 

Then enable the app to use the new welcomeRouter variable:

 app.use('/welcome', welcomeRouter); 

Finally, restart the app again to see the new login page, by using CTRL+C and the command:

 > npm start 

When the login screen loads, click the Login button. You’ll see the WhatsApp notification popping up on your screen:

Advertisement
free widgets for website

Click the notification that appears to open WhatsApp and view the basic text message sent by the Node.js application:

So far, you’ve sent simple messages using WhatsApp. Next, you’ll send more complex messages using templates.

Creating the Movie Ticket Catalog Page

The next step is to create a catalog of available movies and their details so that online customers can buy tickets. This data will be stored in a separate file.

Create a new file at publicjavascriptsmovies.js with the following content:

 var movies = [{   id: 1,   title: 'Airborne 404',   thumbnail: 'https://www.social-ping.com/wp-content/uploads/2022/10/localimages/war-469503__480.jpg',   license: 'https://pixabay.com/photos/war-soldiers-parachutes-469503/',   licenseDetails: 'Pixabay License / Free for commercial use / No attribution required',   time: 'October 23, 2022 - 8:00 PM',   venue: 'Cinema Daily' }, {   id: 2,   title: 'Storm in the Pacific',   thumbnail: 'https://www.social-ping.com/wp-content/uploads/2022/10/localimages/ship-2202910__340.jpg',   license: 'https://pixabay.com/photos/ship-strom-sea-night-fantasy-red-2202910/',   licenseDetails: 'Pixabay License / Free for commercial use / No attribution required',   time: 'October 24, 2022 - 7:30 PM',   venue: 'Famous Studios' }, {   id: 3,   title: 'Alienzz Game - The Movie',   thumbnail: 'https://www.social-ping.com/wp-content/uploads/2022/10/localimages/illustration-1736462__340.png',   license: 'https://pixabay.com/vectors/illustration-videogame-graphics-1736462/',   licenseDetails: 'Pixabay License / Free for commercial use / No attribution required',   time: 'October 24, 2022 - 10:30 PM',   venue: 'FilmStreamNow' }, {   id: 4,   title: 'Captain Doctor Angel II',   thumbnail: 'https://www.social-ping.com/wp-content/uploads/2022/10/localimages/doctor-3410941__340.jpg',   license: 'https://pixabay.com/photos/doctor-physician-angel-care-3410941/',   licenseDetails: 'Pixabay License / Free for commercial use / No attribution required',   time: 'October 25, 2022 - 9:30 PM',   venue: 'Uptown Studio' }];  if (exports ) {   exports.movies = movies; } 

You now need a new route for users to access the movie catalog page.

Advertisement
free widgets for website

Create a new file at routescatalog.js with the following content to render the catalog page with the movies data:

 var express = require('express'); const { movies } = require("../public/javascripts/movies"); var router = express.Router();  /* GET home page. */ router.post('/', function(req, res, next) {   res.render('catalog', { title: 'Movie Ticket Demo for Node.js', movies: movies }); });  router.get('/', function(req, res, next) {   res.render('catalog', { title: 'Movie Ticket Demo for Node.js', movies: movies }); });  module.exports = router; 

Now create a new file at viewscatalog.ejs with the following content, which renders the movie data using the EJS template syntax:

         <%= title %>                     

<%= title %>

Welcome to <%= title %>

<% movies.forEach(function(movie,index) { %>
<%=movie.title %>
<%= movie.title %>

<%= movie.time %>

<%= movie.venue %>

Advertisement
free widgets for website
<% }) %>

Now you have to make the welcome endpoint redirect to the catalog page once the welcome message is sent to the user. Open the routeswelcome.js file and modify the redirect to the /catalog route :

 sendMessage(data)     .then(function (response) {       res.redirect('/catalog'); 

Next, open the app.js file and create a router variable for the catalog route:

 var catalogRouter = require('./routes/catalog'); 

Then enable the app to use the new catalogRouter variable:

 app.use('/catalog', catalogRouter); 

Finally, restart the app again to see the new login page, by using CTRL+C and the command:

 > npm start 

Now click the Login button. This will send your WhatsApp number a welcome message and redirect you to the catalog view:

Advertisement
free widgets for website

Note that there’s a button to buy the ticket for each movie displayed on the screen above. Next, you need to configure the application to process the ticket purchase.

Sending Templated Messages with Node.js and WhatsApp Business

A message template is required to start a business-initiated conversation. These conversations can be customer care messages or appointment reminders, payment or shipping updates, alerts, and more.

Create new router code at routesbuyTicket.js:

 var express = require('express'); var router = express.Router(); var bodyParser = require('body-parser'); require('dotenv').config() var { movies } = require('../public/javascripts/movies'); const { sendMessage, getTemplatedMessageInput } = require("../messageHelper");  router.use(bodyParser.json());  router.post('/', function(req, res, next) {   var movie = movies.filter((v,i) => v.id == req.body.id)[0];    var data = getTemplatedMessageInput(process.env.RECIPIENT_WAID, movie, req.body.seats);      sendMessage(data)     .then(function (response) {       res.redirect('/catalog');       res.sendStatus(200);       return;     })     .catch(function (error) {       console.log(error);       res.sendStatus(500);       return;     }); });  module.exports = router; 

The following code to send the ticket purchase message is similar to what you did for the welcome message. Open the messageHelper.js file and add the getTemplatedMessageInput function:

 function getTemplatedMessageInput(recipient, movie, seats) {   return JSON.stringify({     "messaging_product": "whatsapp",     "to": recipient,     "type": "template",     "template": {       "name": "sample_movie_ticket_confirmation",       "language": {         "code": "en_US"       },       "components": [         {           "type": "header",           "parameters": [             {               "type": "image",               "image": {                 "link": movie.thumbnail               }             }           ]         },         {           "type": "body",           "parameters": [             {               "type": "text",               "text": movie.title             },             {               "type": "date_time",               "date_time": {                 "fallback_value": movie.time               }             },             {               "type": "text",               "text": movie.venue             },             {               "type": "text",               "text": seats             }           ]         }       ]     }   }   ); }  module.exports = {   sendMessage: sendMessage,   getTextMessageInput: getTextMessageInput,   getTemplatedMessageInput: getTemplatedMessageInput }; 

Note that we are using the sample_movie_ticket_confirmation template above, where you provided the movie thumbnail, the movie title, the date/time, the location, and the number of the seats. You can experiment with other available templates or create new ones, by visiting the Message Templates page.

Advertisement
free widgets for website

Now open the app.js file and create a router variable for the buyTicket route:

 var buyTicketRouter = require('./routes/buyTicket); 

Then make the app use the new welcomeRouter:

 app.use('/buyTicket', buyTicketRouter'); 

Finally, restart the app again to see the new login page, by using CTRL+C and the command:

 > npm start 

From the ticket screen, select three seats under a movie card:

Then click the Buy button. This will cause your app to send a template message to your test phone number via

Advertisement
free widgets for website

WhatsApp:

Now, open WhatsApp to see the template message.

That’s it!

As you can see, sending messages from Node.js code is straightforward. However, here are some tips and best practices for integrating WhatsApp into applications:

  • Even if you’re automating your app messages, make sure that communication with customers doesn’t feel robotic. People expect a more personal experience, so try sending personalized messages.
  • Explore a more relaxed and informal tone.
  • Keep your text messages clear and to the point.
  • When using templates, provide rich context information by using links to documents, videos, or images such as those above, where we depicted the movies related to the tickets.

Conclusion

This article demonstrated how to add messaging capability to a Node.js app by integrating it with a WhatsApp Business account.

First, you created a simple Node.js application from scratch. Then, you added a sample login page and configured the application to send basic welcome messages to users via the API. Finally, you added a catalog page and configured it to send template messages with movie ticket details to customers.

Advertisement
free widgets for website

But this is only the tip of the iceberg. You can explore our documentation to see how you can get the most out of the Cloud API.

First seen at developers.facebook.com

Continue Reading
Advertisement free widgets for website
Click to comment

Leave a Reply

Your email address will not be published.

FACEBOOK

Now people can share directly to Instagram Reels from some of their favorite apps

Published

on

By

now-people-can-share-directly-to-instagram-reels-from-some-of-their-favorite-apps

More people are creating, sharing and watching Reels than ever before. We’ve seen the creator community dive deeply into video content – and use it to connect with their communities. We’re running a limited alpha test that lets creators share video content directly from select integrated apps to Instagram Reels. Now, creators won’t be interrupted in their workflow, making it easier for them share share and express themselves on Reels.

“With the shift to video happening across almost all online platforms, our innovative tools and services empower creativity and fuel the creator economy and we are proud to be able to offer a powerful editing tool like Videoleap that allows seamless content creation, while partnering with companies like Meta to make sharing content that much easier.”- Zeev Farbman, CEO and co-founder of Lightricks.

Starting this month, creators can share short videos directly to Instagram Reels from some of their favorite apps, including Videoleap, Reface, Smule, VivaVideo, SNOW, B612, VITA and Zoomerang, with more coming soon. These apps and others also allow direct sharing to Facebook , which is available for any business with a registered Facebook App to use.

We hope to expand this test to more partners in 2023. If you’re interested in being a part of that beta program, please fill out this form and we will keep track of your submission. We do not currently have information to share about general availability of this integration.

Learn more here about sharing Stories and Reels to Facebook and Instagram and start building today.

Advertisement
free widgets for website

FAQs

Q. What is the difference between the Instagram Content Publishing API and Instagram Sharing to Reels?

See also  Facebook Live: The Coronavirus Gender Gap

A: Sharing to Reels is different from the Instagram Content Publishing API, which allows Instagram Business accounts to schedule and publish posts to Instagram from third-party platforms. Sharing to Reels is specifically for mobile apps to display a ‘Share to Reels’ widget. The target audience for the Share to Reels widget is consumers, whereas the Content Publishing API is targeted towards businesses, including third-party publishing platforms such as Hootsuite and Sprout Social that consolidate sharing to social media platforms within their third-party app.

Q: Why is Instagram partnering with other apps?

A: Creators already use a variety of apps to create and edit videos before uploading them to Instagram Reels – now we’re making that experience faster and easier. We are currently doing a small test of an integration with mobile apps that creators know and love, with more coming soon.

Q: How can I share my video from another app to Reels on Instagram?

Advertisement
free widgets for website

A: How it works (Make sure to update the mobile app you’re using to see the new Share to Reels option):

  • Create and edit your video in one of our partner apps
  • Once your video is ready, tap share and then tap the Instagram Reels icon
  • You will enter the Instagram Camera, where you can customize your reel with audio, effects, Voiceover and stickers. Record any additional clips or swipe up to add an additional clip from your camera roll.
  • Tap ‘Next’ to add a caption, hashtag, location, tag others or use the paid partnerships label.
  • Tap ‘Share’. Your reel will be visible where you share reels today, depending on your privacy settings.
See also  Paytm to Go Public; Facebook Pledge $1bn to Content Creators

Q: How were partners selected?

A. We are currently working with a small group of developers that focus on video creation and editing as early partners. We’ll continue to expand to apps with other types of creation experiences.

Q: When will other developers be able to access Sharing to Reels on Instagram?

A: We do not currently have a date for general availability, but are planning to expand further in 2023.

Q: Can you share to Facebook Reels from other apps?

Advertisement
free widgets for website

A: Yes, Facebook offers the ability for developers to integrate with Sharing to Reels. For more information on third-party sharing opportunities, check out our entire suite of sharing offerings .

First seen at developers.facebook.com

Continue Reading

FACEBOOK

What to know about Presto SQL query engine and PrestoCon

Published

on

By

what-to-know-about-presto-sql-query-engine-and-prestocon

The open source Presto SQL query engine is used by a diverse set of companies to navigate increasingly large data workflows. These companies are using Presto in support of e-commerce, cloud, security and other areas. Not only do many companies use Presto, but individuals from those companies are also active contributors to the Presto open source community.

In support of that community, Presto holds meetups around the world and has an annual conference, PrestoCon, where experts and contributors gather to exchange knowledge. This year’s PrestoCon, hosted by the Linux Foundation, takes place December 7-8 in Mountain View, CA. This blog post will explore some foundational elements of Presto and what to expect at this year’s PrestoCon.

What is Presto?

Presto is a distributed SQL query engine for data platform teams. Presto users can perform interactive queries on data where it lives using ANSI SQL across federated and diverse sources. Query engines allow data scientists and analysts to focus on building dashboards and utilizing BI tools so that data engineers can focus on storage and management, all while communicating through a unified connection layer.

In short, the scientist does not have to consider how or where data is stored, and the engineer does not have to optimize for every use case for the data sources they manage. You can learn more about Presto in a recent ELI5 video below.

Caption: Watch the video by clicking on the image above.

Advertisement
free widgets for website

Presto was developed to solve the problem of petabyte-scale, multi-source data queries taking hours or days to return. These resources and time constraints make real-time analysis impossible. Presto can return results from those same queries in less than a second in most cases, allowing for interactive data exploration.

See also  Facebook Isn't Scandal-Proof - The New York Times

Not only is it highly scalable, but it’s also extensible, allowing you to build your own connector for any data source Presto does not already support. At a low level, Presto also supports a wide range of file types for query processing. Presto was open sourced by Meta and later donated to the Linux Foundation in September of 2019.

Here are some Presto resources for those who are new to the community:

What is PrestoCon?

PrestoCon is held annually in the Bay Area and hosted by the Linux Foundation. This year, the event takes place December 7-8 at the Computer History Museum. You can register here. Each year at PrestoCon, you can hear about the latest major evolutions of the platform, how different organizations use Presto and what plans the Technical Steering Committee has for Presto in the coming year.

Presto’s scalability is especially apparent as every year we hear from small startups, as well as industry leaders like Meta and Uber, who are using the Presto platform for different use cases, whether those are small or large. If you’re looking to contribute to open source, PrestoCon is a great opportunity for networking as well as hearing the vision that the Technical Steering Committee has for the project in the coming year.

Advertisement
free widgets for website

Explore what’s happening at PrestoCon 2022:

Where is Presto used?

Since its release in November of 2013, Presto has been used as an integral part of big data pipelines within Meta and other massive-scale companies, including Uber and Twitter.

The most common use case is connecting business intelligence tools to vast data sets within an organization. This enables crucial questions to be answered faster and data-driven decision-making can be more efficient.

How does Presto work?

First, a coordinator takes your statement and parses it into a query. The internal planner generates an optimized plan as a series of stages, which are further separated into tasks. Tasks are then assigned to workers to process in parallel.

Workers then use the relevant connector to pull data from the source.

Advertisement
free widgets for website

The output of each task is returned by the workers, until the stage is complete. The stage’s output is returned by the final worker towards the next stage, where another series of tasks must be executed.

The results of stages are combined, eventually returning the final result of the original statement to the coordinator, which then returns to the client.

How do I get involved?

To start using Presto, go to prestodb.io and click Get Started.

We would love for you to join the Presto Slack channel if you have any questions or need help. Visit the community page on the Presto website to see all the ways you can get involved and find other users and developers interested in Presto.

If you would like to contribute, go to the GitHub repository and read over the Contributors’ Guide.

Advertisement
free widgets for website

Where can I learn more?

To learn more about Presto, check out its website for installation guides, user guides, conference talks and samples.

Make sure you check out previous Presto talks, and attend the annual PrestoCon event if you are able to do so.

To learn more about Meta Open Source, visit our open source site, subscribe to our YouTube channel, or follow us on Twitter, Facebook and LinkedIn.

First seen at developers.facebook.com

Advertisement
free widgets for website
Continue Reading

FACEBOOK

How to Interpret Webhook Components in the WhatsApp Business Platform

Published

on

By

how-to-interpret-webhook-components-in-the-whatsapp-business-platform

The ways customers want to connect are changing. The WhatsApp Business Platform gives businesses an integrated way to communicate with customers right where they are. In order to integrate properly when using the Cloud API, hosted by Meta, you’ll need to leverage webhooks so applications have a way to respond to events. Webhooks allow your application to monitor three primary events on WhatsApp so you can react with different functionality depending on your goals.

This article looks at these three components, goes through the information they carry, and provides some use-case scenarios to give you an idea of the possibilities.

Interpreting Different Webhook Components

To send and receive messages on WhatsApp, it’s critical to keep track of statuses and errors to help ensure you’re communicating effectively with your customers, which you can do with webhooks.

With webhooks, the WhatsApp Business Platform monitors events and sends notifications when one occurs. These events are one of three components: messages, statuses, and errors.

Let’s explore each of these and examine examples of how you can use them.

Advertisement
free widgets for website

Messages

The messages component is the largest of the three event types and contains two core objects:

  • Contacts — which contain information about the message’s sender.

  • Messages — which provide information about a message’s type and contents.

These two event types allow your application to manage and respond to people that interact with your application. The contacts object contains two pieces of information: name and WhatsApp Id. The contact’s name allows your application to use their name without further lookups. In contrast, the contact’s WhatsApp ID lets you keep track of these contacts or use the contacts/ endpoint to add additional functionality.

For instance, you can verify the customer and start the opt-in process within the customer-initiated conversation, which allows you to message them outside the initial 24-hour response window. It’s important to note that only the text, contacts, and location message types provide contact information.

The message object is where the bulk of the information is stored, including the message contents, type of message, and other relevant information. Depending on the message type, the actual payload of the message component can vary widely. It’s crucial to determine the message type to understand the potential payload. Message types include:

  • Text: a standard text-only message

  • Contact: contains a user’s full contact details

  • Location: address, latitude, and longitude

  • Unknown: unsupported messages from users, which usually contain errors.

  • Ephemeral: disappearing messages

  • Media message types: contain information for the specified media file. These types include:

    • Document

    • Image

    • Audio

    • Video

    • Voice

These different data types can have very different uses, from reviewing images and screenshots from concerned customers to collecting information about where to ship goods and send services. To use these different data types most effectively, you can create applications to handle different forms of communication, with functionalities such as:

Advertisement
free widgets for website
  • Ask your customers to provide a shipping or mailing address. You can use the location-based message feature to capture your users’ location to determine where to send their goods and services.

  • Show customers products and communicate product details through a message. You can use the referred_product field within messages to offer your users specific product details. Using this field develops a more personal, conversational shopping experience and customer interactions.

  • Build support functionality that allows customers to take and send images and videos of product concerns, and submit those for a support case. Once the user has submitted a support ticket, the app can track the case — including steps taken towards resolution and conversations between support teams and the customer through WhatsApp — using a unique case identifier.

These are just some potential features you can build using the interactivity provided by webhooks and the message object. These features extend your current communication channels and provide additional options for customers.

Statuses

Where the messages component provides your application with insight into events that originate directly from your customers, the statuses component keeps track of the results of messages you send and the conversation history. There are six status components:

  • Sent: the application sent your message and is in transit.
  • Delivered: the user’s device successfully received the message.
  • Read: the user has read your message.
  • Deleted: a user deleted a message that you sent.
  • Warning: a message sent by your application contains an item that isn’t available or doesn’t exist.
  • Failed: a message sent by your application failed to arrive.

Status components also contain information on the recipient ID, the conversation, and the pricing related to the current conversation. Conversations on WhatsApp are a grouping of messages within a 24-hour window that are either user-initiated or business-initiated. Keeping track of these conversations is vital, as a new conversation occurs when you send additional responses after the 24-hour period ends.

Some functionality you may want to add to your application based on status events includes:

  • Ensuring your application has sent generated messages, they arrived, and the recipient potentially read them by using a combination of these status types and timestamps within the status object. This information allows your application to follow up with customers if they didn’t engage.
  • Keep analytical information about your application’s messages, especially regarding business-initiated conversations. For example, if your application uses a WhatsApp customer contact list to send offer messages, the status component helps you understand how many were sent, delivered, read, responded to, or failed to measure your campaign’s success.

Errors

Finally, the errors component allows your application to receive any out-of-band errors within WhatsApp that affect your platform. These errors don’t stop your application from compiling or working but are typically caused when your application is misusing specific functionality. The following are some typical errors.

Error Code 368, Temporarily Blocked for Policy Violations

If your application violates WhatsApp Business Messaging or Commerce policy, your account may be temporarily banned. You can monitor this and pause your application while troubleshooting.

Error 506, Duplicate Post

If your workflows unintentionally generate duplicate messages, you can monitor this to find the source.

Advertisement
free widgets for website

Error 131043, Message Expired

Sometimes, messages are not sent during their time to live (TTL) duration. Use this code to know which messages to schedule for resending if needed.

Error handling is a broad, complex subject, and there are many other use cases for which you should be implementing error handling. The errors component helps extend your error handling on the WhatsApp Business Platform for greater consistency.

Conclusion

This article took a high-level look at messages, statuses, and errors returned by webhooks and explored ways you can use these three components to expand your application’s functionality.

Messages provide information on customer interactions, statuses give insight into messages your app sends, and error notices enable you to increase your application’s resilience. Webhooks are critical to ensuring your app interacts with customers seamlessly.

The WhatsApp Business Platform’s webhooks provide your applications with real-time data, enabling you to build better experiences as you interact with customers. Ready to know more? Dive deeper into everything the WhatsApp Business Platform has to offer.

Advertisement
free widgets for website

First seen at developers.facebook.com

See also  WEHOville Facebook page hijacked by former publisher
Continue Reading

Trending