DEV Community

Cover image for Laravel 12 WhatsApp Twilio Integration Example
itstuffsolutions
itstuffsolutions

Posted on

Laravel 12 WhatsApp Twilio Integration Example

In this Laravel 12 tutorial, you’ll learn how to send WhatsApp messages using the Twilio API. We'll cover setting up Twilio, installing the SDK, and creating a simple form in Laravel to send text messages (including emojis) via WhatsApp. You can also extend it to send media like images or documents. Twilio makes integrating real-time messaging easy with its scalable communication platform. Perfect for adding WhatsApp support to your Laravel apps!

Steps for WhatsApp API integration in Laravel 12

  • Step 1: Set Up a New Laravel 12 Project
  • Step 2: Register Twilio Account
  • Step 3: Install the Twilio SDK via Composer
  • Step 4: Create a Controller
  • Step 5: Define a Route
  • Step 6: Create a Blade
  • Step 7: Run the Laravel Application

Step 1: Set Up a New Laravel 12 Project

If your project is already in place, you may skip this step. Use the command below to create a new Laravel project:

composer create-project laravel/laravel laravel-send-whatsapp-message-using-twilio

Enter fullscreen mode Exit fullscreen mode

Step 2: Register Twilio Account

Create an account on Twilio.com. After registering, you’ll be able to access your Account SID, Auth Token, and Twilio WhatsApp-enabled number. Refer to the images below for guidance.

Follow These Steps to Set Up Your Twilio Account:

Create an Account inside Twilio

Create an Account inside Twilio

Credentials

From your Twilio Console Dashboard, you will get the following details:

  • Account SID
  • Auth Token
  • Twilio Phone Number

credentials

Connect to WhatsApp Sandbox

send join code to twilio whatsapp number

Send Recieve Whatsapp Message

Step 3: Install the Twilio SDK via Composer

Now, switch to your Laravel project directory and install the Twilio SDK:

cd laravel-send-whatsapp-message-using-twilio

composer require twilio/sdk
Enter fullscreen mode Exit fullscreen mode

Copy the necessary credentials—Account SID, Auth Token, and WhatsApp number from your Twilio dashboard, and add them to your .env file as demonstrated in the code snippet below.

TWILIO_SID="INSERT YOUR TWILIO SID HERE"
TWILIO_AUTH_TOKEN="INSERT YOUR TWILIO TOKEN HERE"
TWILIO_WHATSAPP_NUMBER="INSERT YOUR TWILIO WHATSAPP NUMBER IN [E.164] FORMAT eg.+14

Enter fullscreen mode Exit fullscreen mode

Step 4: Create a Controller

Now, let’s create a controller to handle the WhatsApp message sending logic using Twilio's API. This controller will include a method to send messages based on user input from the form.

Read Also : How to Send SMS to Mobile Number in Laravel 12 Using Twilio API

We’ll also configure everything to make the process smooth and beginner-friendly.
📖 For complete code and detailed instructions, read the full blog post on my website:👉 https://itstuffsolutiotions.io

Top comments (0)