Y
Y
yfdqrp2017-08-23 17:42:45
PHP
yfdqrp, 2017-08-23 17:42:45

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;
}
?>

I would be grateful even for an article where you can read about it.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Artem0071, 2017-08-23
@Artem0071

The article is not needed here, everything is very well described in the documentation
One thing is immediately clear from the problems here:
the documentation says
and you have photo-133760460_456239023 (look at the dash between `photo` and user id)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question