Bot in php infinite message sending, why?


if (!isset($_REQUEST)) {

//String to confirm the server address from the settings API Callback
$confirmationToken = ";

//Access key community
$token = ";

// Secret key
$secretKey = ";

//Get and decode the notification
$data = json_decode(file_get_contents('php://input'));

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

//Check what is in the "type"
switch ($data->type) {
 //If this notification is to confirm the server address...
 case 'confirmation':
 //...send the line to confirm the address
 echo $confirmationToken;

 //If the new message notification...
 case 'message_new':
 //...get the id of the author
 $userId = $data->object->from_id;

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

 if( $message == "Hello" ) {
 //then use users.get the data about the author
 //$userInfo = json_decode(file_get_contents("{$userId}&v=5.8"));

 //and extract from the answer of his name
 //$user_name = $userInfo->response[2]->first_name;

 //Using messages.send token of the community sent a response message
 $request_params = array(
 'message' => "Hello, how are you doing?"
 'user_id' => $userId,
 'access_token' => $token,
 'v' => '5.80'

 $get_params = http_build_query($request_params);

 file_get_contents('' . $get_params);
 return "Hello World";

 //Return "ok" server Callback API



March 23rd 20 at 19:12
2 answers
March 23rd 20 at 19:14
Maybe because in case of success api never returns "ok"
Because of applikeyshn finish the job on return "Hello World"?

And then the client probably tries several times?
all the code I posted - Ike.Hilpert26 commented on March 23rd 20 at 19:17
if( $message == "Hello" ) {
return "Hello world" at this point the script is completed - Dayna.Grady commented on March 23rd 20 at 19:20
March 23rd 20 at 19:16
apparently you have recursion going on and the bot starts to answer himself, dump $data laid out

Find more questions by tags PHP