Я пытаюсь сделать BOT для телеграммы с использованием PHP-кода.
Обычно пользователю приходится выбирать между вставкой: 1) имя 2) фамилия 3) адрес
выбор фамилии онЯ должен написать свою фамилию, и я хочу сохранить ее в переменной, но, если я использую $update = file_get_contents('php://input')
, я всегда читаю "фамилию" (это ввод пользователя)
Так что я думаю, что моя проблемаявляется: как изменить содержание file_get_contents('php://input')
в частичный «момент» моей программы?
Пожалуйста, прочитайте мой код для более подробной информации, большое спасибо !!!
<?php
$botToken = "MYTOKEN"; //token
$website = "https://api.telegram.org/bot".$botToken;
$update = file_get_contents('php://input'); //updates from telegram (JSON format)
$update = json_decode($update, TRUE);
$chatId = $update['message']['from']['id'];
$text = $update['message']['text'];
switch($text)
{
case "name";
sendMessage ($chatId,"You write name");
break;
case "surname";
sendMessage ($chatId,"You write surname");
sendMessage ($chatId,"Insert your surname");
/* here is my problem: what i have to do to "read" what the
user write now? i want to store his surname into a new
variable*/
break;
case "address";
sendMessage ($chatId,"You write address");
break;
default;
sendMessage ($chatId,"You don't write a valid command");
break;
}
function sendMessage($chatId,$text)
{
$url = $GLOBALS[website]."/sendMessage?
chat_id=$chatId&text=".urlencode($text);
file_get_contents($url);
}
?>