Mobile ApplicationSolutions

How to Integrate WhatsApp Sandbox API with Twilio?


This is the age of social media. Almost every single person who is having a smartphone is using social media. To talk to their families, have fun chatting with friends, and also to promote their business, social media is widely used. This article will teach you how to integrate WhatsApp sandbox API with Twilio so customers can also connect in real-time.

If you are running a business like any fashion brand or any food delivery shop, then social media could help to market your product to a large number of customers. In particular, WhatsApp is a widely used social media app nowadays.

Many businesses use WhatsApp to reach their customers. In today’s social media world, customers want to interact with businesses the way they interact with their friends and families on WhatsApp.

Advantages of Using WhatsApp API for your Business

1. Interactive Communication with the Customers

Today’s generation wants everything at their fingertips and to get available with minimum effort. For this WhatsApp comes in very handy for sending product information, delivery alerts, or delay notifications to your customers. Customers can also connect with real-time agents and discuss their queries.

2. Secure Messaging 

On WhatsApp every business profile is unique and WhatsApp verified every business account. Also, WhatsApp uses end-to-end encryptions and 2FA to secure users’  messages. With end-to-end encryption, even WhatsApp can not read the conversation between customers and businesses. this also reduces the risk of customers coming across fake business. 

All these points help any business to reach their customers easily. 

See also  Why Customers Prefer Travel Chatbots Over Agents?

The Process to Integrate WhatsApp Sandbox API with Twilio

The Twilio Sandbox for WhatsApp is a pre-configured environment that is available through the Twilio Console. in this console you can send outbound messages, can reply to incoming messages, and you can configure things like message delivery callbacks. Until you get your mobile number verified by Twilio, you can check your functionality with this sandbox account easily.

The Sandbox provides a pre-configured phone number (+1-XXX-XXX-XXXX) which is common for all sandbox users. You don’t need to worry about this common number because other users don’t receive your messages although they are using the same sandbox number. Only those who receive the message who opt into your sandbox account.

Here we are going to integrate WhatsApp API with a sandbox account in NodeJs. let’s see how we can do that.

Step 1: How to join sandbox Twilio

First of all, you need a Twilio account. After that, you need to send a WhatsApp message to the given number. As you can see in my case sandbox number is +1 XXX XXX XXXX and the message is joined wore-death. This message will be unique for every user. You can stop this anytime by sending stop. Note that the sandbox will expire after 3 days. so you need to re-join to continue testing.

How to join sandbox API Twilio

Step 2: Send your first message with Nodejs

1. Install the “twillio” package in your package.

2. Get your account sid and auth token from your Twilio account to connect with Twilio.

3. You can send WhatsApp messages with NestJs like:

import { Controller, Get } from '@nestjs/common';
import { AppService } from './app.service';
const accountSid = 'xxxxxxxxxxxxxxxxxxxxxxxxxx';
const authToken = 'xxxxxxxxxxxxxxxxxxxxxxxx';
const client = require('twilio')(accountSid, authToken);
export class AppController {
 constructor(private readonly appService: AppService) {} 
 async sendMessage(){
     from: 'whatsapp:+1xxxxxxxx',
     body: 'Hello there!',
     to: 'whatsapp:+91xxxxxxxx',
  .then(message => console.log(message));

when you run this route, you will get responses like:

  body: 'Hello there!',
  numSegments: '1',
  direction: 'outbound-API,
  from: 'whatsapp:+1xxxxxxxxxx',
  to: 'whatsapp:+1xxxxxxxxxx',
  dateUpdated: 2022-07-31T06:39:00.000Z,
  price: null,
  errorMessage: null,
  uri: '/2010-04-01/Accounts/ACaab0e2c6bb7c0b7a685743dec5083c15/Messages/SM27276d00975d417cb076687c8f1fe8f8.json',
  accountSid: 'xxxxxxxxxxxxxxxxxxxxxxxxxxx',
  numMedia: '0',
  status: 'queued',
  messagingServiceSid: null,
  sid: 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxx',
  dateSent: null,
  dateCreated: 2022-07-31T06:39:00.000Z,
  errorCode: null,
  priceUnit: null,
  apiVersion: '2010-04-01'  

You can also send media like images, audio, documents, etc to your users. So this is how you can integrate WhatsApp sandbox API with Twilio in Nodejs.

See also  A Complete Guide to Hire Dedicated Developers in 2024
lets start your project

Related Articles