Salesforce And WhatsApp Integration using Twilio API

By Samir Sahare 01-Feb-2023

Introduction

Salesforce and WhatsApp integration using Twilio API is a process of connecting Salesforce with the popular messaging app WhatsApp, allowing businesses to communicate with their customers in real-time through a unified platform. Twilio API enables businesses to send and receive messages, images, and documents, track conversation history and automate workflows. This integration can enhance customer engagement and support, as well as streamline business processes.

Tips:

Salesforce and WhatsApp integration using Twilio API is a powerful tool for businesses to streamline communication and boost customer engagement. Here are some tips to ensure a successful integration:

  1. Determine your use case and objectives for integrating Salesforce with WhatsApp.
  2. Familiarize yourself with Twilio API and its capabilities.
  3. Use a reliable integration platform or consult with an experienced integration specialist.
  4. Configure your workflows and message templates for efficient and effective communication.
  5. Test the integration thoroughly before going live to ensure smooth operation. By following these tips, you can make the most of Salesforce and WhatsApp integration using Twilio API and enhance your business communication strategy.

Use Case: –

When a lead is created in Salesforce, we would like to send the confirmation to the particular client/customer. Using this integration, we can go a little ahead in the market race. Generally, we send the lead confirmation email notification to the client/customer but sending a message on WhatsApp makes it more engaging.

Integrating Salesforce with WhatsApp using Twilio API can boost your communication strategy. This article provides a step-by-step guide for seamless implementation.

Step to follow to achieve the functionality.

  • Sign Up in Twilio
  • Create Sandbox Environment
  • Create Apex class for consuming API
  • Create Lightning web component.
1. Sign Up in Twilio: –

The first step to achieve this functionality we need create a free Twilio trial account. Here we need to provide the following details Name, Email, and Password.

After signing up we need to verify email through a verification email as below

Getting your Phone Number verified and confirmation of all information you will be redirected to the Twilio console page.

In this way, Your Twilio account got created and verified. Now next step is as follows

2.Create Sandbox Environment: –

Being Developers, we can test WhatsApp messaging using a sandbox environment. It is a four-step process to set up a sandbox that gets started after pop-up confirmation. So, the first step is to get a trial number (The trial number is the number that you need to send a WhatsApp to the Customer) and your sandbox environment will be connected to your WhatsApp Number.

In the first step send a message join to +14155238886. Automatically a connection code generated and will appear as will bold character on the page like above.
After sending a proper message, your WhatsApp Number and sandbox environment will be linked.

To proceed to the next step any message from the sandbox environment can be sent to WhatsApp Number. We can select any one of the above options like ‘Appointment Reminders’, ‘Order Notification’, or ‘Verification codes’.

For processing the next step, you can send a message from your WhatsApp Number to verify two-way communication.

Post successful communication, sandbox environment details will be displayed. We Message format for testing.

Now our sandbox environment is set up is ready. Now we can proceed to write the apex class in salesforce and call Twilio API over there.

3. Create Apex class for Using Twilio API: –

We can integrate Twilio API to send WhatsApp messages using apex where we need to supply Twilio account SID and secret token to apex and TwiliotrialNumber.

for reference you can use this apex class WhatsAppMessageService.

Three parameters are required to send message:

  • From: It is sender WhatsApp Number. This number will be +1 415 523 8886 for sandbox environments.
  • To: Use this receiver WhatsApp Number to configure in a sandbox environment.
  • Body: It is the message which will be sent. For testing use the format which is mentioned in a sandbox page.
4. Create Lightning web component: –

This lightning web component can be created to send a message with help of the above apex class

Whtapp_Integration.html

Whtapp_Integration.js

Whtapp_Integration-meta.xml

After the lead is created in salesforce, we can send a WhatsApp Message to the lead phone Number.

After the message is sent successfully the screen appears below

To confirm the delivery status of the message to the customer/client we can check from Twilio logs available in the monitor block.

In this way, we send WhatsApp Messages to customers/clients for engagement through salesforce.

Reference:- Send WhatsApp Message from Salesforce | SalesforceCodex

Conclusion

Integrating WhatsApp with Salesforce through Twilio API is a powerful tool for improving communication and enhancing customer experience. By following the steps outlined in this guide, businesses can streamline their messaging process and efficiently manage their interactions with customers. With this integration, organizations can create a more connected and responsive customer service experience, leading to increased customer satisfaction and loyalty.

About the Author