# Mautic Integration with Twilio to send message to Whatsapp

**URL:** <https://forum.mautic.org/t/mautic-integration-with-twilio-to-send-message-to-whatsapp/14596>\
**Category:** Product Support\
**Created:** [June 1, 2020, 11:30pm UTC](https://forum.mautic.org/t/mautic-integration-with-twilio-to-send-message-to-whatsapp/14596 "2020-06-01T23:30:31Z")\
**Posts on this page:** 2\
**Page:** 2

<div class="post-metadata">

**Author:** ![jpgiron](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/jpgiron/32/1751_2.png) [@jpgiron](https://forum.mautic.org/u/jpgiron)\
**Post date:** [June 6, 2023, 2:05pm UTC](https://forum.mautic.org/t/mautic-integration-with-twilio-to-send-message-to-whatsapp/14596/22 "2023-06-06T14:05:17Z")

</div>

Hello to all

My Mautic Version: 2.15.2  
My PHP Version: 7.1.32

I made my mautic installation work with Twilio to send Whatsapp Template Message

I go to app/bundles/SmsBundle/Api/TwilioApi.php

Search on the line 88

```auto
 public function sendSms(Lead $lead, $content)
    {
        $number = $lead->getLeadPhoneNumber();

        if ($number === null) {
            return false;
        }

        try {

            $this->client->account->messages->sendMessage(
                $this->sendingPhoneNumber,
                $this->sanitizeNumber($number),
                $content
            );

            return true;
        } catch (\Services_Twilio_RestException $e) {
            $this->logger->addWarning(
                $e->getMessage(),
                ['exception' => $e]
            );

```

and reemplace with this:

```auto
public function sendSms(Lead $lead, $content)
    {
        $number = $lead->getLeadPhoneNumber();

        if ($number === null) {
            return false;
        }

        try {

/ **********************Add Support to Whatsapp*************************** /
	    $prefix = 'whatsapp:';

            $this->client->account->messages->sendMessage(
                $prefix.$this->sendingPhoneNumber,
                $prefix.$this->sanitizeNumber($number),
                $content
            );

/*******se adiciono $prefix a $this->sanitizeNumber($number)****************/

           return true;
        } catch (\Services_Twilio_RestException $e) {
            $this->logger->addWarning(
                $e->getMessage(),
                ['exception' => $e]
            );

```

also remmber the international format of the contact phones, mautic format the phone by defect with US format, by this add automatically +1 to all phone number before send to twilio. This is because this lines

search the line 74

```auto
    protected function sanitizeNumber($number)
    {
        $util = PhoneNumberUtil::getInstance();
        $parsed = $util->parse($number, 'US');

        return $util->format($parsed, PhoneNumberFormat::E164);
    }

```

change to the country you want to send whatsapp message the line

` $parsed = $util->parse($number, 'US');`

for example for Peru

` $parsed = $util->parse($number, 'PE')`

and with this mautic automatically put +51 to the contact mobile phone that are store in mautic. Also remember put the sending phone number in the twilio plugin with no spaces and with international format.

With this change my mautic can send trought twilio service, as is send an sms. Remember you need to have an Twilio acount and a sender number activate.

---

<div class="post-metadata">

**Author:** ![jpgiron](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mautic.org/jpgiron/32/1751_2.png) [@jpgiron](https://forum.mautic.org/u/jpgiron)\
**Post date:** [April 19, 2024, 5:04pm UTC](https://forum.mautic.org/t/mautic-integration-with-twilio-to-send-message-to-whatsapp/14596/23 "2024-04-19T17:04:42Z")

</div>

in reply to this message:

> [@Mautic Integration with Twilio to send message to Whatsapp](https://forum.mautic.org/t/mautic-integration-with-twilio-to-send-message-to-whatsapp/14596/2):
>
> hi [jpgiron](https://forum.mautic.org/u/jpgiron) The Twilio integration with Mautic works only for SMS. if you want to send whatsapp messages through mautic to Twilio you need a different approach. You should use a webhook action in a campaign that send the the payload to a Twilio endpoint that is intended to handle messages for WhatsApp the paramters are as follows: Twilio endpoint for whatsapp messaging: [https://api.twilio.com/2010-04-01/Accounts/xxxxxxxxxxxxxxx/Messages.json](https://api.twilio.com/2010-04-01/Accounts/xxxxxxxxxxxxxxx/Messages.json) (xxxxxxxxxxxxxxx is your Twilio client i…

there is a change on twilio

The weebhook need to be updated

The FROM parameter now its not a number, twilio give you an ID for it  
The BODY parameter change to CONTENSID, twilio give you an ID for it  
And you need to add the CONTENTVARIABLES parameter to send the variables you put in your message.

 ![image](https://us1.discourse-cdn.com/flex020/uploads/mautic/original/2X/b/be4c0c12a573e3cf2a8e0faf83d470c8adda3b30.png)

[Previous page](https://forum.mautic.org/t/mautic-integration-with-twilio-to-send-message-to-whatsapp/14596.md?page=1)
