phptwiliowhatsapp

Send WhatsApp Notification using Pre-approved Template Message on Twilio


Hi I just got approved on Twilio to use it's WhatsApp messaging service. I have no problem when testing it in the sandbox, but I got trouble when I moved it into production environment.

Based on Twilio explanation, I have to start the conversation to WhatsApp customer using one of pre-approved templates. When the customer replied, we got 24 hours of window to send freeform messages.

I already did what's in the https://www.twilio.com/docs/sms/whatsapp/tutorial/send-whatsapp-notification-messages-templates but unfortunately the given example is actually for freeform message.

Here's the script:

<?php

require_once '/path/to/vendor/autoload.php';

use Twilio\Rest\Client;

$sid    = "ACxxxxxxxxxxxxxxxxxxxxx";
$token  = "your_auth_token";
$twilio = new Client($sid, $token);

$message = $twilio->messages
                  ->create("whatsapp:+14155238886", // to
                           array(
                               "from" => "whatsapp:+15005550006",
                               "body" => "Hi Joe! Thanks for placing an order with us. We’ll let you know once your order has been processed and delivered. Your order number is O12235234"
                           )
                  );

print($message->sid);

Can anyone please help me with PHP script on how to send the WhatsApp message using this pre-approved template?


Solution

  • Alright, maybe some of you got here trying to ask the similar question and here's what I got after contacting the Twilio Support:

    Thats all I can share and I hope you don't have problem just like I did. Cheers!