Home  >  Q&A  >  body text

Can Twilio API send bulk messages on Whatsapp?

How do I send to all clients in bulk without the foreach I did. I just want to send it to everyone in 1 message.

public function sendToMany(Request $request){

    $number = getenv('TWILIO_NUMBER'); //Twilio's number

    $sid    = getenv('TWILIO_ACCOUNT_SID');//////////////////////
    $token  = getenv('TWILIO_AUTH_TOKEN'); // API credentials  //
    $twilio = new Client($sid, $token);    //////////////////////

    $otp = $request->message;//message from the form

    $receiver = array("+xxxxxxxxxxxx", "+xxxxxxxxxxxx", "+xxxxxxxxxxxx");

    foreach ($receiver as $receiver_number){
        $message = $twilio->messages 
        ->create("whatsapp:".$receiver_number, // to 
                array( 
                    "from" => "whatsapp:".$number,    
                    "body" => $otp  //message to send
                ) 
                );
    }//end of for loop
}//end of method

P粉957661544P粉957661544239 days ago361

reply all(1)I'll reply

  • P粉757640504

    P粉7576405042024-01-29 12:15:14

    There is no bulk API for sending messages via WhatsApp using the Twilio API. We recommend that you loop over your numbers, like you've done here, or loop through and queue a background job that makes API requests independently.

    reply
    0
  • Cancelreply