function inviaMessaggi($bot_id, $messaggio) { //tutto il necessario per controllare i bot telegram include "../php/telegramBotController.php"; //tutto il necessario per accedere al db include "../php/Connessione.php"; $query = "SELECT BotID,ContactID FROM BOTS_CONTATTI WHERE BotID='" . $bot_id . "';"; $connSelect = new Connessione(); $link = $connSelect->getConnection(); $num = 0; if ($risultati = $link->query($query)) { if (@$risultati->num_rows > 0) { while ($row = $risultati->fetch_assoc()) { $contact_id = $row['ContactID']; $telegramBC = new TelegramBotController($bot_id); $req = $telegramBC->sendMessage($messaggio, $contact_id); $num = $num + 1; } $risultati->close(); } else { echo "NESSUN DATO"; } } $link->close(); return $num; }
while ($row = $risultati->fetch_assoc()) { $num = 0; $bot_id = $row['BotID']; $bot_des = $row['BotDescription']; $messaggio = $messag1 . $bot_des . $messag2; $telegramBC = new TelegramBotController($bot_id); $contatti = $telegramBC->updateContactCollection(); $conneInsert = new Connessione(); $linkInsert = $conneInsert->getConnection(); foreach ($contatti as $contatto) { $insert = "INSERT INTO BOTS_CONTATTI (BotID,ContactID) VALUES ("; //fai insert di bot_id e user id $insert = $insert . "'" . $bot_id . "','" . $contatto . "');"; if ($linkInsert->query($insert) === TRUE) { $num = $num + 1; $req = $telegramBC->sendMessage($messaggio, $contatto); } } $linkInsert->close(); echo "Sono stati aggiunti " . $num . " contatti sul bot " . $bot_des . "(" . $bot_id . ")"; echo "</br>"; } $risultati->close(); } else { echo "NESSUN DATO"; } } $link->close(); ?>