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
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.