Integrate Salesforce with WhatsApp using Twilio API

    One of my friend was having requirement to send WhatsApp from Lightning community portal. I have suggested to use Twilio API for sending message. This blog will provide complete detail about sending WhatsApp message from lightning Application, which i have suggested to my friend.

    Steps for Twilio API integration in Salesforce:

    1. Signup in Twilio 
    2. Create Sandbox environment
    3. Create Apex for consuming API
    4. Create Lightning component

    Signup in Twilio 

    Signup in Twilio for integrating it with Salesforce application.

    It will send one verification email to verify email. Verify email to continue. This will open below screen to verify phone number.

    Verify mobile/phone number to process further.  After verification and confirming some information , this popup will show. Confirm this also as it is for developers for testing Whatsapp messaging.

    Create Sandbox environment

    Developer can test WhatsApp messaging using Sandbox environment.  Setting Sandbox environment is 4 steps process and it will start after above popup is confirmed.

    First Step is to connect sandbox environment with your whatsapp number. So send message ‘join <connection code>’ to +14155238886. Connection code will be generated automatically and it will be visible on page like in below page with bold character. For my test environment it is difficult-now.

    Once you send proper message, it will link your WhatsApp number to sandbox environment.

    In next step, send any message form sandbox environment to your WhatsApp number. You can select any option to test like ‘Appointment Reminder’, ‘Order Notifications’ and ‘Verification Codes’.

    Below screen show, how message will be delivered to your number.

    After confirming that message is delivered to your WhatsApp number, you can process for next step. Next step is to send message from your WhatsApp number to verify two way communication.

    After successful communication, it will show sandbox environment detail. For testing we can only use 3 highlighted message format.

    Now our sandbox environment is setup. Let us proceed with using twilio API in apex.

    Create Apex for consuming API

    Integrate Twilio API to send WhatsApp message using Apex. Apex need your Twilio account SID and secret token. You can get these information here. If it is not available be default then click Show API Credentials in right side of the page.

    Add Twilio API Url in Remote Site Setting.

    Sending message will require three parameter.

    • From : This is sender WhatsApp number.  For sandbox environment this number will be  +14155238886.
    • To      : This is receiver WhatsApp number.  Use above WhatsApp number which you have configured in sandbox environment.
    • Body  : This is message which will be sent. For testing use format which is mentioned in sandbox page.

    Create Lightning component

    Create lightning component to send message using above apex class.

    Provide receiver WhatsApp number and message in valid format. It will send WhatsApp message to provided number.

    If you need to send WhatsApp message to other mobile number then it should be verified first. You can verify mobile no here.

    Reference : https://www.twilio.com/docs/sms/whatsapp

    September 6, 2019 2 comments
    0 Facebook Twitter Google + Pinterest