Your software
My Mautic version is: 2.16.2
My PHP version is: 7.0.31
Your problem
My problem is:
I have mautic installation that work with twilio for send sms. Works fine. But I want to send message through whatsapp. I change in the mautic plugin the sender number and include the “whatsaap:” follow with the number sender approved on twilio. But when I send it show me an error message on Mautic.
[HTTP 400] Unable to create record: The ‘From’ number whatsapp:+15089805226 is not a valid phone number, shortcode, or alphanumeric sender ID.
But when I put only the number it work fine +15089805226. I made the validation process on Twilio and they approved to me send whatsapp message, and give instruction of change this on the send number.
I think that the library or the SDK of the plug in of twilio on mautic its too old? can you help to me?
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
(xxxxxxxxxxxxxxx is your Twilio client id - same one you use in Mautic)
Method is POST Headers:
autorization: basic twilioclientid:twilioclientsecret (twilio credentials (along with “:”) should be encoded in base64. you can do it here https://www.base64encode.org)
content-type: application/x-www-form-urlencoded
Data
From: your number (whatsapp+number)
To: number of recepient
Body: content of message
all Data fields support mautic tokens for fields (as you can see from screenshot)
I find your approach helpful so I did a bit of digging in the Twilio integration code so here’s what I did (this might be a bit of a hack and not upgrade safe but hopefully helps):
Find this file: /app/bundles/SmsBundle/Integration/Twilio/TwilioTransport.php
Then change the sendSms() method with the following:
Hello, i made this modification, but give me the same error.
Último error de ejecución: [HTTP 400] Unable to create record: The ‘From’ number whatsapp:+15089805226 is not a valid phone number, shortcode, or alphanumeric sender ID.
Hi @jpgiron, you should set your ‘From’ number as +15089805226 and not whatsapp:+15089805226. If you applied the code block above, it should automatically prepend the ‘whatsapp:’ prefix to your ‘From’ number.
In our case, we have the same twilio number for sending SMS and sending via WhatsApp. If the Contact’s number has a ‘whatsapp:’ prefixed to it, then the code above will prepend ‘whatsapp:’ to the ‘From’ number and sends via WhatsApp, else, it will use the ‘From’ number as is then sends the message as SMS.
Hello, i tried with whatsapp and get the error and without it didn’t work .
I checked why and found that for some reason my mautic installation did not capture the sms answers of text message when the user reply with something. Searching on google, I found that this issue
and check each change on each files. The majority of the changes its on mautic, but some files doesn’t have this changes. As this:
does not have, this line, that call to the file you indicate i need change.
use Mautic\SmsBundle\Integration\Twilio\TwilioTransport;
with this, the change you indicate, now work. Also work when mautic get the answer of sms and/or whatsapp, and execute the instructions on a campaign! Now i can get also replied on whatsapp that execute campaign conditionals.
Very Thanks for your help! I think this work great now!
Yes, now works as a basic bot on whatsapp. Capture the answers and execute the campaign for send text message for example, basis on the conditional you put. Now i want to capture some answer and put as a contact field, because all answer get in the history interaction of mautic, but i want to capture some of them to store with the contact and send to another application. Do you have some idea of how to do that?
Hello, I have this working, now I get the answer from Twilio and obviously I can’t send the message because is a free message form and not a WhatsApp template.
The question is: How do I use the variables?
I mean, for example, my message template is:
Welcome to the team ring {{1}}, in this link www.xxxxx.xxx you will be able to see login to your account and access to the company services and the education platform. We love to see you in here.
So, let’s say WhatsApp already approved that Message template
How do I configure it in the “Body” field and how do I insert the user name (contactfield=firstname) to replace the {{1}} variable in the WhatsApp template.