N
N
nastyskafomka2018-08-28 01:32:16
PHP
nastyskafomka, 2018-08-28 01:32:16

[VK BOT API] How to send multiple files with one message in response?

How to send multiple attachments with one request (messages.send)?
The $request_params
documentation does not describe how to send multiple attachments at once. Or I'm blind.

Answer the question

In order to leave comments, you need to log in

3 answer(s)
S
Stockholm Syndrome, 2018-08-28
@nastyskafomka

just list with a comma:
'photo100172_166443618,video85635407_165186811'

S
sgaynetdinov, 2018-08-28
@sgaynetdinov

Try the py-vkontakte library

import vk
api = vk.Api(VK_GROUP_TOKEN)
group = api.get_group(VK_GROUP_ID)
group.send_messages(USER_ID, image_files=[file1, file2])

N
nastyskafomka, 2018-08-29
@nastyskafomka

Issue resolved.
In order to send two attachments in one message (1 reply), you need to repeat the request to send the message. Here is an example code:

$request_params = [
            'message'      => "Текст сообщения",
            'user_id'      => $user_id,
            'attachment'  => 'Ссылка на фотографию_$token',  \\нужен для отправке фотографий, документов и тп, если они не в группе с ботом.
            'access_token' => $token,
            'v'            => $api_version
            ];
            $request_params_2 = [
              'user_id'       => $user_id,
              'attachment'    => 'Ссылка на фотографию_$token',  \\нужен для отправке фотографий, документов и тп, если они не в группе с ботом.
              'access_token'  => $token,
              'v'             => $api_version
            ];
          $get_params = http_build_query($request_params);
          file_get_contents('https://api.vk.com/method/'. $msg_send . $get_params);
          $get_params_2 = http_build_query($request_params_2);
          file_get_contents('https://api.vk.com/method/'. $msg_send . $get_params_2);

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question