I want my bot to receive the user's response to a question made by the bot itself and continue with the execution of that function without starting the execution again when receiving a message.
The command I send is / vehicle route to call this function
The code I tried was this:
$mensaje_dir = "¿Cuál es la dirección desde la que quiere partir?";
sendMessage($chatId,$mensaje_dir);
$update1 = file_get_contents('php://input');
$update1 = json_decode($update1,TRUE);
$chatId1 = $update1["message"]["chat"]["id"];
$chatType1 = $update1["message"]["chat"]["type"];
$direccion1 = $update1["message"]["text"];
$dir1=str_replace(' ', '+', $direccion1);
sleep(20);
$mensaje_dir = "¿Hacia qué dirección va?";
sendMessage($chatId,$mensaje_dir);
$update2 = file_get_contents('php://input');
$update2 = json_decode($update2,TRUE);
$chatId2 = $update2["message"]["chat"]["id"];
$chatType2 = $update2["message"]["chat"]["type"];
$direccion2 = $update2["message"]["text"];
$dir2=str_replace(' ', '+', $direccion2);
sleep(20);
$url = "https://maps.googleapis.com/maps/api/directions/json?origin=".$dir1."&destination=".$dir2."®ion=es&language=es&key=CLAVE_API";
sendMessage($chatId,$url);
$ruta_d = "<b>- Inicio: </b>".$array_d['routes'][0]['legs'][0]['start_address']."<b> \n- Fin: </b>".$array_d['routes'][0]['legs'][0]['end_address']."\n\n<b>- Distancia: </b>".$array_d['routes'][0]['legs'][0]['distance']['text']."\n<b>- Duración: </b>".$array_d['routes'][0]['legs'][0]['duration']['text'];
sendMessage($chatId,$ruta_d);
The problem is that the URL appears like this:
maps.googleapis.com/maps/api/directions/json?origin= / route + vehicle & destination = / route + vehicle & region = en & language = en & key = CLAVE_API
Instead of receiving the address that I send you by message, take as a message the command that I sent you previously. How can I get the response in the function without starting a new execution of the script?