Skip to main content

WhatsApp Channel Integeration

Introduction

  • Introduction to Whatsapp : WhatsApp is a popular messaging application that allows users to send text messages, voice messages, make voice and video calls, share media files such as photos and videos, and engage in group chats. It was founded in 2009 by Brian Acton and Jan Koum and was later acquired by Facebook in 2014. WhatsApp is available on various platforms, including iOS, Android, and web browsers. It has a massive user base globally and is commonly used for personal and professional communication due to its user-friendly interface, convenience, and widespread adoption.

Prerequisites

  1. WhatsApp Business Account: You will need a WhatsApp Business Account. Follow the steps to set up one here: FB Developer Page.

  2. WhatsApp Number: Ensure you have access to a WhatsApp number that you want to use for the chatbot.

Steps to Integrate a Chatbot with WhatsApp

1. Create a WhatsApp Sandbox

  • In the Twilio Console, go to the WhatsApp Sandbox section.

  • Follow the instructions to enable the WhatsApp Sandbox for your WhatsApp Business Account. This will provide you with a sandbox phone number that you can use for testing.

2. Develop the Chatbot

  • Write the code for your chatbot using your preferred programming language. You can use Twilio's API to send and receive messages.

  • Implement the logic for your chatbot. This can include natural language processing (NLP) for understanding user messages and generating responses.

3. Configure Webhooks

  • Set up a webhook that will receive incoming messages from WhatsApp. You can use a serverless function or a web application to handle these incoming messages.

  • Configure your WhatsApp number to send incoming messages to your webhook URL.

4. Test Your Chatbot

  • Use the WhatsApp Sandbox phone number to send messages to your WhatsApp bot. Verify that your bot responds correctly.

NOTE: Same process can be done through 3rd party also like RML, Infobip etc. in that case we just need to handle things according to 3rd party and they will handle all stuffs with whatsapp.

What We Need In Env For Integration

  • whatsAppAPIUserName
  • whatsAppAPIPassword
  • base_whatsappApiUrl
  • whatsappApiToken
  • whatsappVersion=2.35
  • whatsAppType=native/non-native
  • enableWhatsappBlueTick=true/false

Types Of Messages Handled For Whatsapp

  • text
  • image
  • document
  • interactive
  • button

Size Limit Of Different Message Types Over Whatsapp

Message TypeSize
Audio Files16 MB
Documents100 MB
Images5 MB
Sticker100 KB
Video16 MB

Other features of Whatsapp

1. Whatsapp Template

What is template ?

  • A template is a pre-designed message that can be used to send structured and informative messages to WhatsApp users. These templates allow businesses to communicate with their customers in a more effective and efficient manner.
  • These are pre-approved messages that can be sent outside of the 24-hour window. Message templates need to be pre-approved by WhatsApp, and there is a fee associated with sending them.

How we upload template ?

  • Request URL: https://.oriserve.com/admin/v1/whatsappInputFileUpload
  • Here we call a function uploadWhatsappInputFile () which uploads the excel sheet on amazon S3 cloud.
  • Then we add a job into a queue, attaching a function with them.
  • While processing the job we execute the function attached with that job.
  • Here we morph data accordingly, and then send data to whatsapp or vendor in case.
  • And then we update our wa_notifications collection in db.

How we process templates in OCS ?

  • When we send the templates through OCS, we need to create the document in wa_notifications.
  • wa_notifications contains many fields like psid, phone number, type, userInfo, wa_msgId and template name, etc.
  • When we send the template to user, we set the field isInteracted as false. When the user clicks on the template, we update this field as true and add the timestamp also.
  • When the user clicks on the template, we get the msg id from request of API. Then we find this wa document and get the template name.
  • By getting the template name, we get the postback data from brand_specified_values collection.
  • By getting the template name, we get the templates button which contain the button text and relay data.

2. Whatsapp Catalogue

Catalogue Overview

Users that receive Multi and Single Product Messages can perform 3 main actions:

  1. View products: Customers can see a list of products or just one product. Whenever a user clicks on a specific item, we fetch the product's latest info and display the product in a Product Detail Page (PDP) format. Currently, PDPs only support product images —any videos and/or GIFs added to the product won’t be displayed in the PDP.
  2. Add products to a cart: A user can add a product to their cart, or amend quantities directly from the list or in the product detail page. Whenever a user adds a product to the shopping cart, we fetch the item’s latest info. If there has been a state change on any of the items, we display a dialog saying “One or more items in your cart have been updated” —See Product Updates for more information. A cart persists in a chat thread between business and customer until the cart is sent to the business —See Shopping Cart Experience for details.
  3. Send a shopping cart to the business: After adding all needed items, customers can send their cart to the business they’re messaging with. After that, businesses can define the next steps, such as requesting delivery info or giving payment options.

If a customer has Multiple devices linked to the same WhatsApp account, the Multi-Product and Single Product Messages will be synced between devices. However, the shopping cart is local to each specific device. See Shopping Cart Experience for details.

Multi-Product Messages and Single Product Messages cannot be:

  • Sent as notifications. They can only be sent as part of existing conversations.

Customers can add up to 99 units of each single catalog item to a shopping cart, but there is no limit on the number of distinct items that can be added to a cart.

The cart persists in the chat thread until it is sent to the business. Once sent, the cart is cleared.

Request Body for single products

{
messages: [
{
id: "f46923b0-f944-11ed-a886-0a58a9feac02",
from: "919991102622",
type: "order",
timestamp: "1684831005",
order: {
catalog_id: "6230562283637305",
product_items: [
{
product_retailer_id: "1234",
quantity: 1,
item_price: 84,
currency: "AED",
},
],
},
},
],
contacts: [
{
profile: {
name: "👀",
},
wa_id: "919991102622",
},
],
brand_msisdn: "919321821008",
request_id: "f46923b0-f944-11ed-a886-0a58a9feac02",
}

Request Body for multiple products

{
messages: [
{
id: "20c3b046-f946-11ed-a9a1-0a58a9feac02",
from: "919991102622",
type: "order",
timestamp: "1684831509",
order: {
catalog_id: "6230562283637305",
product_items: [
{
product_retailer_id: "drink4",
quantity: 2,
item_price: 28,
currency: "AED",
},
{
product_retailer_id: "Limit1",
quantity: 1,
item_price: 63,
currency: "AED",
},
],
},
},
],
contacts: [
{
profile: {
name: "👀",
},
wa_id: "919991102622",
},
],
brand_msisdn: "919321821008",
request_id: "20c3b046-f946-11ed-a9a1-0a58a9feac02",
}

Want to know more about Whatsapp Integration ?