-----
"); $rispostadaleggere = json_decode($risposta, true); $IDChat = $rispostadaleggere[result][message][chat][id]; //print_r($rispostadaleggere[result][0][message][date]); //print_r ($rispostadaleggere); $arrdaelaborare=$rispostadaleggere[result]; foreach ($arrdaelaborare as $blocchitrovati) { $NuovoUpdate_ID=$blocchitrovati[update_id]; $IDChat=$blocchitrovati[message][chat][id]; $first_name=$blocchitrovati[message][chat][first_name]; $last_name=$blocchitrovati[message][chat][last_name]; $date=$blocchitrovati[message][date]; $Comando_Ricevuto=$blocchitrovati[message][text]; $result=mysql_query("SELECT * FROM FabKeyBot Where update_id='".$NuovoUpdate_ID."'"); $row=mysql_fetch_row($result); if ($row[0]=='') { echo $Comando_Ricevuto." - ".$first_name."
"; //Se il comando è /messaggio if ($Comando_Ricevuto=="/messaggio") { //Svuoto la tabella per iniziare tutto dall'inizio $ScriviLog_NuovoUpdate_ID=mysql_query("DELETE FROM FabKeyBot WHERE IDChat='".$IDChat."'"); $ScriviLog_NuovoUpdate_ID=mysql_query(" INSERT INTO FabKeyBot (IDChat, update_id, comando, time, messaggio, stato, first_name, last_name) VALUES ('".$IDChat."','".$NuovoUpdate_ID."','".$Comando_Ricevuto."','".$date."', '','1','".$first_name."','".$last_name."');"); //echo " INSERT INTO FabKeyBot (IDChat, update_id, comando, time, messaggio, stato, first_name, last_name) VALUES ('".$IDChat."','".$NuovoUpdate_ID."','".$Comando_Ricevuto."','".$date."', '','','".$first_name."','".$last_name."');"."
"; $messaggio="Seleziona l'utente iscritto a cui vuoi inviare il messaggio.%0a%0a"; $result=mysql_query("SELECT * FROM wp_usermeta Where meta_key='fabkey' and meta_value>0"); $row=mysql_fetch_row($result); while ($row = mysql_fetch_array($result)) { if ($row[user_id]!='') { $resultUser=mysql_query("SELECT * FROM wp_users Where ID=".$row['user_id']); $utente=mysql_fetch_row($resultUser); //print_r($utente); } if ($utente[3]!='') { $messaggio.="/".$utente[0]." ".$utente[1]."%0a"; } } //echo $messaggio."
-------------
"; $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, "https://api.telegram.org/bot243198183:AAF_6e5x3vADOuq0KSyQeSObtQAKn76tkYA/sendMessage?chat_id=".$IDChat."&text=".$messaggio); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); $risposta = curl_exec($ch); curl_close($ch); } /* fine comando messaggio */ //Se il comando non è messaggio if ($Comando_Ricevuto!="/messaggio") { $resultUser=mysql_query("SELECT * FROM wp_users Where ID='".substr($Comando_Ricevuto, 1, strlen($Comando_Ricevuto))."'"); $utente=mysql_fetch_row($resultUser); if ($utente[0]!='') { $ScriviLog_NuovoUpdate_ID=mysql_query(" INSERT INTO FabKeyBot (IDChat, update_id, comando, time, messaggio, stato, first_name, last_name) VALUES ('".$IDChat."','".$NuovoUpdate_ID."','".$Comando_Ricevuto."','".$date."', '','2','".$first_name."','".$last_name."');"); $messaggio="Bene, ora scrivi il messgio da lasciare a ".$utente[3]; } else { //cerco l'ultimo stato per il mittente e se è a 2 significa che deve inviare il messaggio. Se è a 1 utente non trovato $resultSTATO=mysql_query("SELECT * FROM FabKeyBot WHERE id = (SELECT MAX(id) FROM FabKeyBot) AND first_name='".$first_name."' AND last_name='".$last_name."' AND IDChat='".$IDChat."';"); $resultSTATO=mysql_fetch_row($resultSTATO); //print_r($resultSTATO); if ($resultSTATO[6]=='1') { $messaggio="Utente non trovato. Mi spiace, Ricomincia /messaggio"; } if ($resultSTATO[6]=='2') { $resultUser=mysql_query("SELECT * FROM wp_users Where ID='".substr($resultSTATO[3], 1, strlen($resultSTATO[3]))."'"); $utente=mysql_fetch_row($resultUser); $ScriviLog_NuovoUpdate_ID=mysql_query(" INSERT INTO FabKeyBot (IDChat, update_id, comando, time, messaggio, stato, first_name, last_name) VALUES ('".$IDChat."','".$NuovoUpdate_ID."','','".$date."', '".$Comando_Ricevuto."','3','".$first_name."','".$last_name."');"); $messaggio="Messaggio aggiunto nella casella di ".$utente[3].". Quando entrerà nel FabLab glielo farò ascoltare.%0aGrazie per aver usato questo bot."; } } $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, "https://api.telegram.org/TOKENBOT/sendMessage?chat_id=".$IDChat."&text=".$messaggio); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); $risposta = curl_exec($ch); curl_close($ch); } /* fine comando messaggio */ } } ?>