Bot in php sends more than one message, but many, why?

<?php

if (!isset($_REQUEST)) {
return;
}

$confirmationToken = ; 

$token = ";

$secretKey = ";

$data = json_decode(file_get_contents('php://input'));

//$app->post('/', function() use($app)) {

//}

if(strcmp($data->secret, $secretKey) !== 0 && strcmp($data->type, 'confirmation') !== 0)
return;


switch ($data->type) {

 case 'confirmation':

 echo $confirmationToken;
break;


 case 'message_new':

 $from_id = $data->object->from_id;

 $peer_id = $data->object->peer_id;

 $message = $data->object->text;

 $userInfo = json_decode(file_get_contents("https://api.vk.com/method/users.get?user_ids=".$from_id."&v=5.8&access_token=".$token));

 $user_name = $userInfo->response[0]->first_name;

 $request_params = array(
 'message' => "Hello",
 'user_id' => $from_id,
 'access_token' => $token,
 'v' => '5.80'
);

 $get_params = http_build_query($request_params);

 file_get_contents('https://api.vk.com/method/messages.send?' . $get_params);
echo("Hello");
break;
}
?>


nycz1u
March 23rd 20 at 19:21
1 answer
March 23rd 20 at 19:23
Solution
The bot must be returned on request of the VC, the answer is "OK". He doesn't return, the VC will send the events in the bot, and the bot will reply to them

Find more questions by tags PHP