Article View: pl.comp.lang.php
Article #231335php else if
From: mattia.farinaro
Date: Wed, 27 Apr 2016 15:49
Date: Wed, 27 Apr 2016 15:49
75 lines
3499 bytes
3499 bytes
Ciao a tutti,
Sto facendo un BoT Telegram con comando PHP.
Vorrei che il BoT rispondesse con risposte automatiche solamente se la domanda presenta il "?" alla fine.
Ho creato questo file execute.php ma il BoT mi continua a dare "null" come risposta....ecco il file:
---------------------------------------------------------------------
<?php
$content = file_get_contents("php://input");
$update = json_decode($content, true);
if(!$update)
{
exit;
}
$message = isset($update['message']) ? $update['message'] : "";
$messageId = isset($message['message_id']) ? $message['message_id'] : "";
$chatId = isset($message['chat']['id']) ? $message['chat']['id'] : "";
$senderId = isset($message['chat']['id']) ? $message['chat']['id'] : "";
$firstname = isset($message['chat']['first_name']) ? $message['chat']['first_name'] : "";
$lastname = isset($message['chat']['last_name']) ? $message['chat']['last_name'] : "";
$username = isset($message['chat']['username']) ? $message['chat']['username'] : "";
$date = isset($message['date']) ? $message['date'] : "";
$text = isset($message['text']) ? $message['text'] : "";
$text=trim($text);
$text=strtolower($text);
if (!$text) {
// Verificare che l'ultimo carattere sia un punto di domanda
if (!$text[sizeof($text) - 1] == '?') {
// Da qui mandi la risposta
$answer = $answers[rand(0, sizeof($answers)-1)];
} else {
// Da qui gli mandi "ehy fammi una domanda"
$answer = "Per poterti rispondere, mi devi fare una domanda con un ? alla fine...";
}
}
$answers = array(
"Per quanto posso vedere, sì",
"È certo",
"È decisamente così",
"Molto probabilmente",
"Le prospettive sono buone",
"I segni indicano di sì",
"Senza alcun dubbio",
"Sì",
"Sì",
"Ci puoi contare",
"È difficile rispondere, prova di nuovo",
"Rifai la domanda più tardi",
"Meglio non risponderti adesso",
"Non posso predirlo ora",
"Concentrati e rifai la domanda",
"Non ci contare",
"La mia risposta è no",
"Le mie fonti dicono di no",
"Le prospettive non sono buone",
"Molto incerto"
);
header("Content-Type: application/json");
$parameters = array('chat_id' => $chatId, "text" => $answer);
$parameters["method"] = "sendMessage";
echo json_encode($parameters);
---------------------------------------------------------------------
Dove sbaglio???
Grazie in anticipo...
Technical Details
Message-ID:
<335ec8a0-1bb4-4cd2-bd40-fe84c5534cac@googlegroups.com>Path:
mbox-mo1.pugleaf.net!news-archive.icm.edu.pl!agh.edu.pl!news.agh.edu.pl!newsfeed2.atman.pl!newsfeed.atman.pl!goblin3!goblin.stu.neva.ru!news.ripco.com!news.glorb.com!7no6498844qgj.0!news-out.google.com!uv8ni8igb.0!nntp.google.com!g8no7640344igr.0!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mailShow Full Headers
Complete Article Headers
X-Received: by 10.159.36.45 with SMTP id 42mr6120847uaq.13.1461772169488; Wed, 27 Apr 2016 08:49:29 -0700 (PDT) X-Received: by 10.50.172.73 with SMTP id ba9mr517140igc.6.1461772169441; Wed, 27 Apr 2016 08:49:29 -0700 (PDT) Path: mbox-mo1.pugleaf.net!news-archive.icm.edu.pl!agh.edu.pl!news.agh.edu.pl!newsfeed2.atman.pl!newsfeed.atman.pl!goblin3!goblin.stu.neva.ru!news.ripco.com!news.glorb.com!7no6498844qgj.0!news-out.google.com!uv8ni8igb.0!nntp.google.com!g8no7640344igr.0!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mail Newsgroups: pl.comp.lang.php Date: Wed, 27 Apr 2016 08:49:28 -0700 (PDT) Complaints-To: groups-abuse@google.com Injection-Info: glegroupsg2000goo.googlegroups.com; posting-host=79.17.166.95; posting-account=GH-EqAoAAADZdXM69rT7SSYfIXMN4CTH NNTP-Posting-Host: 79.17.166.95 User-Agent: G2/1.0 MIME-Version: 1.0 Message-ID: <335ec8a0-1bb4-4cd2-bd40-fe84c5534cac@googlegroups.com> Subject: php else if From: mattia.farinaro@gmail.com Injection-Date: Wed, 27 Apr 2016 15:49:29 +0000 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit