M
M
Murka Murenich2017-09-13 11:17:36
PHP
Murka Murenich, 2017-09-13 11:17:36

How to properly use attachments in Callback API?

I am writing a bot for the VKontakte community. You need to make sure that the bot attaches a photo from the community album to the message.
What is the best way to write code?
Here is an example of his response:

}elseif (strpos($user_msg, 'помощь') !== false) { 
     $v->msgsend("мои команды", $uid, $token);

You need to somehow attach a photo to this message.
There are several such messages.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey Sokolov, 2017-09-13
@drobysevdanila

The documentation for the messages.send() method describes the field attachment. This field simply contains lines of the type separated by commas photo-123_456, identifying the attached pictures.
Modify your submit method:

public function msgSend($msg, $uid, $token, $attachment = '' ){	
    $request_params = array(
      'message' => $msg,
      'user_id' => $uid,
      'attachment' => $attachment,
      'access_token' => $token,
      'v' => self::API_VERSION
    );

and call it when you need to attach an image, with an additional parameter:
where substitute the values ​​for your image.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question