Skip to content
Advertisement

Is there a bulk messaging limit in telegram bots?

I was sending messages to all my bot subscribers and when the subscribers reach about 400, my bot doesn’t send messages to all but few. my code is in php and I’ve used the sleep() function.

I tested it and found out that while sending the message if the messages aren’t sent in 1 min the sending process stops and I know there is a limit for sending messages 30 messages per second but not this.

 elseif ($text == '/send' && $chatID == 353575758){
         $sql = $c->query("SELECT * FROM corona ORDER BY id");
         $row = $sql->num_rows;
         $counter = 0;
         $sent = 0;
        while($exe = $sql->fetch_array()) {
            if($counter < 30) {

                    $counter++;
                    $sent ++;
            }
            else {

                    $sent++;
                    sleep(1);
                    $counter = 1;
                $bot->sendMessage([
                    'chat_id' => 353575758,
                    'text' => $sent,
                    'parse_mode' => 'HTML',
                ]);
                }
         }
        $bot->sendMessage([
            'chat_id' => 353575758,
            'text' => "Completed - sent for ".$sent." Users",
        ]);

    }

Advertisement

Answer

I think, the problem is caused by execution time limit in PHP. By default, the script runs for 30 seconds, but it’s possible to increase it.

ini_set('max_execution_time', '600'); // Set execution time limit of 600 seconds
ini_set('max_execution_time', '0'); // Remove execution time limit
User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement