I made this code in my .php file where I set webHook that works good.
$token = "my token";
$website = "https://api.telegram.org/bot" . $token . "/";
$updates = file_get_contents("php://input");
$updates = json_decode($updates, true);
$text = $updates["message"]["text"];
$chatID = $updates["message"]["chat"]["id"];
switch($text){
case "/prova_gratuita":
if(check($chatID)){
sendMessage($chatID, "Are you sure? Demo is available only one time. Write confirm to continue");
switch($text){
case "confirm":
...
break;
}
}
Second switch()
does not work. Why? What can I do? I know I should update value of $text
, but I don't know how I can do it
I think that the error is how you set up the problem. Each bot input is a call to that WebHook. Then $ text can not be aggornato that way.
You should also include in the first switch of the "case" of the second.
$token = "my token";
$website = "https://api.telegram.org/bot" . $token . "/";
$updates = file_get_contents("php://input");
$updates = json_decode($updates, true);
$text = $updates["message"]["text"];
$chatID = $updates["message"]["chat"]["id"];
switch($text){
case "/prova_gratuita":
if(check($chatID)) sendMessage($chatID, "Are you sure? Demo is available only one time. Write confirm to continue");
case "confirm":
...
}
Every time you send a message to the bot, he makes a call to the WebHook. So to change the state of $updates, so even the $text the script should restart