I wrote a telegram bot with php . I want to send a text to all Members, I saved all members chat_id.
I tried to send message with this function :
function sendMessage($chatId, $message) {
$url = WEBSITE . "/sendMessage?chat_id=" . $chatId . "&text=" . urlencode($message);
file_get_contents($url);
}
and use this function for get user chatid and send message:
public function sendall($message) {
$sql = $this->con->prepare('SELECT * FROM `users`');
$sql->execute();
$res = $sql->fetchAll();
foreach ($res as $row) {
sendMessage($row['chatid'], $message);
}
exit();
}
But this is not working correctly and the message is sent to members several times and it does not stop until I clear my database.
Best Answer
The API will not allow more than ~30 messages to different users per second, Answered here.