Twilio Laravel Send Whatsapp Message not in same channel

Welldy Rosman

I have try to create MEssage from php(laravel) using twilio, when i send messsage and system reply it well,

but i have some problem when i want directly send message directly from system,I call my service from POSTMAN but it will always show error notif like this

Twilio\Exceptions\RestException: [HTTP 400] Unable to create record: From(whatsapp:+14155238886) and To(+6281210357927) addresses should be of the same channel. in file D:\WelldyNew\LARAVUE\pwi\vendor\twilio\sdk\src\Twilio\Version.php on line 88

is it because I call api from POSTMAN? so how I can send message with calling my api?

public function sendTest(Request $request){
    $from = $request->input('From');
    $body = $request->input('Body');
    $this->sendWhatsAppMessage($body,$from);
    return;    
}

public function sendWhatsAppMessage(string $message, string $recipient)
{
    $twilio_whatsapp_number = getenv('TWILIO_WHATSAPP_NUMBER');
    $account_sid = getenv("TWILIO_SID");
    $auth_token = getenv("TWILIO_AUTH_TOKEN");

    $client = new Client($account_sid, $auth_token);
    return $client->messages->create($recipient, array('from' => "whatsapp:$twilio_whatsapp_number", 'body' => $message));
}
yvesonline

You need to prefix your to/recipient with whatsapp: to indicate you're sending to a WhatsApp number.

Twilio is complaining that you're trying to send a message from a WhatsApp number to a normal phone number:

  • from: +123456789 -> to: whatsapp:+198765432 - not allowed
  • from: whatsapp:+123456789 -> to: +198765432 - not allowed
  • from: +123456789 -> to: +198765432 - allowed
  • from: whatsapp:+123456789 -> to: whatsapp:+198765432 - allowed

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related