Can Twilio API send bulk messages on Whatsapp?
P粉957661544
P粉957661544 2024-01-28 22:49:42
0
1
384

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粉957661544
P粉957661544

reply all(1)
P粉757640504

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.

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!