Answer the question
In order to leave comments, you need to log in
Why is a message not sent in the bot for VK?
Hello! I have a code for a Callback bot in PHP, I confirmed the server, but for some reason the bot does not want to respond to commands. Help me please.
The code:
<?php
$token = "REDACTED";
function vk_msg_send($peer_id,$text){
$request_params = array(
'message' => $text,
'peer_id' => $peer_id,
'access_token' => $token,
'v' => '5.87'
);
$get_params = http_build_query($request_params);
file_get_contents('https://api.vk.com/method/messages.send?'. $get_params);
}
$data = json_decode(file_get_contents('php://input'));
switch ($data->type) {
case 'confirmation':
echo "REDACTED";
break;
case 'message_new':
$message_text = $data->object->text;
$id = $data->object->peer_id;
if ($message_text == "/start"){
vk_msg_send($id, "OK");
}
echo 'ok';
break;
}
?>
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question