Send Whatsapp Notifications with Next.js and Novu
How to send Whatsapp Notifications with Next.js and Novu

As a business, offering the option to send transactional notifications to our users’/clients’ WhatsApp chat is a must-have. Use cases and business needs change, but the foundation is usually very similar across the majority.
As developers, we know that WhatsApp is only ONE OF the potentially required channels of communication, and being smart means not sweating too much on building staff and infrastructure, someone has already built and shared with the world. Check out Novu.
This article assumes you know what a notification workflow is and why you should use it. It also assumes you are aware of Next.js and WhatsApp chat app.
Novu recently released a new way of baking notification workflows into your apps via code.
To learn about it, visit the related documentation. You might also benefit from reading the code-first approach to managing notification workflows article.
If you prefer to get your hands dirty quickly, go ahead and clone the code repo from GitHub.
1. Initialize a new NEXT.JS Project
We will follow the [official installation guide from NEXT](https://nextjs.org/docs/getting-started/installation), open your terminal / IDE, and run the following command:
On installation, you’ll see the following prompts:
We will not use `/src` directory in this guide.
2. Integrate Novu Echo Into Our App (Notification Workflow)
1. We will install the `@novu/echo` package in the root of our NEXT app directory by running the following command:
2. We must provide an API endpoint for the Novu Dev Studio to fetch our notification workflow. (Don’t worry; we’ll guide you through all the steps.) Navigate to your app’s `app/` directory and create a new directory named `api`. Within the `api` directory, we will create one additional directory and name it `echo`.
Create a file within the `app/api/echo` directory and name it `route.ts`. Copy and paste the code snippet below:
3. Now, let’s create the instance where we will build and maintain our notification workflow:
Navigate to your `app` directory and create another directory named `echo`.
Create a file within the `app/echo` directory and name it `novu-workflow.ts`. Copy and paste the code snippet below:
In the `body` property in the code above, we can define what kind of notification (or message) the user/client will get to one’s WhatsApp client app.
We haven’t finished the article yet but have everything to build a notification workflow.
Below, we can see a bare-bone Novu echo instance to shape your desired workflow.
We can:
– Select a name for our workflow.
– Declare Workflow Steps as we see fit for our use case. It can be a single-step or multi-step workflow
– Configure what could be passed in the payload of the workflow trigger [payloadSchema].
– Configure what inputs could be passed statically via Novu Web ([inputSchema](https://docs.novu.co/echo/concepts/inputs))
Note: You can create and manage as many workflows as you wish within `app/api/echo/novu-workflow.ts`; make sure to provide each workflow with a unique name.
—
3. Adding WhatsApp Business as a provider to Novu Integrations Store
To integrate WhatsApp Business with Novu, you must create a Facebook developer app and obtain the necessary credentials.
Step 1: Create a Facebook Developer App
Visit the Facebook Developer Portal and create a new app.
Select “Other” for “What do you want your app to do?” and select “Business” for “Select an app type”.
Step 2: Setup WhatsApp Product
On the App Setup page, click on “Set Up” under the “WhatsApp” product. You must create or add a Facebook Business Account to your app.
Step 3: Send a Sandbox Message
Copy the following pieces and paste them in the Novu WhatsApp Business integration settings:
– Temporary Access Token – Access API token Field
– Phone Number ID – Phone Number Identification Field

Note: It’s important to note that the test Whatsapp credentials cannot be used in production and will expire in 24 hours.
You will need to submit your app for review to obtain production credentials.
Step 4: Add a Test Phone Number
You can add a test phone number to the sandbox by clicking on the “Add Phone Number” button.
This number can be used to test your integration with Novu before submitting it for review.
Step 5: Creating a WhatsApp Template (Optional / For Production)
For test credentials, we can only use pre-approved templates. So you can skip this step if you don’t want to wait for the approval of your template and mainly test the functionality.
Here is an example of how a notification is sent to the `RECIPIENT` by passing the approved template as a `template.name` property and calling Meta’s API endpoint:
Learn more about how to create and manage WhatsApp templates.
5.1 Register a Business Phone Number
To go live you will need to add a real business phone number and submit your app for review.
Follow the Facebook Instructions on how to proceed.
5.2 Generate a permanent access token
Follow the Facebook Instructions on how to generate a permanent access token.
Depending on your use case.
5.3 Creating a WhatsApp Template
We must create a WhatsApp Template to send notifications to your customers. Create a template in the Business Manager and submit it for review.
After your template is approved, we can use the `template_name` to send notifications to your customers.
—
4. Launching The Dev Studio
Now that everything in our notification workflow is configured and the WhatsApp provider is already integrated into the Novu Integration Store, it’s time to see a visual representation of what we have built.
1. If you haven’t run the development environment for your NEXT app, now is the time.
2. Do you remember that we exposed an echo API endpoint in our app for Dev Studio to catch? This is where it happens.
Run the following command in a separate terminal:
If you’ve followed this post, you should see this:

Here is where our exact API endpoint goes. If our application runs on a different port, we should change the URL manually to point Dev Studio in the right direction.

Also, if we have configured everything correctly, we should see that Dev Studio sees our workflow identifier (Workflow unique name).

3. We press the “View Workflow” button in the Dev Studio to see our workflow.
We should see the following:

4. Press on the workflow step node called “send-chat.” We should see a preview of our chat body and the `Step Input` and `Payload` variables we have configured in the workflow schemas.

5. Feel free to adjust the chat text, step input schema, or define the properties we anticipate in the payload. This UI shows a live representation of everything. You can add more steps like In-App, SMS, and Email in code and it will be shown visually in the Dev Studio.
—
5. Syncing our workflow to Novu Cloud
Having completed crafting, designing, and modifying our notification workflow to suit our requirements, we’re ready to push it to Novu Cloud. There, it will handle the heavy lifting and seamlessly execute all the steps we’ve configured whenever we trigger the workflow.
1. Click on the “Sync to Cloud” button on the top right.

2. We will need to create a local tunnel that the Novu Cloud environment can reach for local experimentation purposes.

On a separate terminal, run the following command:
We should get something like:

3. Click on the “Create Diff” button. To push (merge) the workflow code to the cloud, an API Key from our Novu account should be added to our echo instance.

Let’s navigate to `../app/echo/novu-workflow.ts` file and add our Novu API Key.
We will now click the “Create Diff” button again.

This is where you can review all the changes made to the workflow. Once you have verified that everything is in order, click the “Deploy Changes” button.

—
6. Testing Our Notification Workflow
There are many ways to test and trigger our workflow, but we’ll make a `cURL` API call to Novu Cloud from our terminal in this article.
If we don’t have any subscribers or users in our database or within our Novu Cloud organization, we’ll send the test to ourselves for simplicity.
– In the `subscriberId` key, input a random number or even our email address (as long as we do not try to assign the same ID key to another subscriber, we should be good).
– For the `phone` key, we will need to insert a valid phone number so we can actually receive the message.
Note: Learn more about the structure of subscriber properties.
We can leave the payload empty or add properties aligned with the `payloadSchema` we established in the echo notification workflow instance.
This is how it’s going to look like in Novu Cloud workflow editor.


Once we run the trigger the workflow, we will get some sort of indication about the execution.

If we have done everything correctly, we should get a Whatsapp message.

Additional resources:
– How to send WhatsApp Business notifications with Novu
– Meta For Developers: Template Messages
– Sample message templates for your WhatsApp Business account