Answer the question
In order to leave comments, you need to log in
Sending media attachments via community messages?
Good afternoon. I am writing a bot for the community and due to lack of knowledge of php I am dumb. I understood how to teach the bot to respond to different messages with different text, but now I can’t figure out how to make sure that pictures are also embedded in these different messages. I know that this is "attachment", but how to combine it with "message" is already xs. Tried 2 days myself - did not work.
Below is a working snippet from the code. (I'm not loading the image from a third party server)
<?php
$data = json_decode(file_get_contents('php://input'));
switch ($data->type){
case 'confirmation':
echo $confirmation_token;
break;
case 'message_new':
$message = $data->object->body;
$messages_array = [
'1' => "картинка 1",
'2' => "картинка 2",
];
foreach($messages_array as $k => $v){
if($message == $k){$otwet = $v;}
}
$request_params = [
'attachment' => 'photo-133760460_456239023',
'message' => $otwet,
'user_id' => $user_id,
'access_token' => $token,
'v' => '5.67'
];
$get_params = http_build_query($request_params);
file_get_contents('https://api.vk.com/method/messages.send?'. $get_params);
echo('ok');
break;
return false;
}
?>
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