R
R
redd_i2018-10-13 13:05:56
API
redd_i, 2018-10-13 13:05:56

How to send a message to a conversation in php?

Hello. There is a code here:

<?php

function send($id , $message)
{
    $url = 'https://api.vk.com/method/messages.send';
    $params = array(
        'user_id' => $id,    // Кому отправляем
        'message' => $message,   // Что отправляем
        'access_token' => 'будет потом,  // access_token можно вбить хардкодом, если работа будет идти из под одного юзера
        'v' => '5.37',
    );

    // В $result вернется id отправленного сообщения
    $result = file_get_contents($url, false, stream_context_create(array(
        'http' => array(
            'method'  => 'POST',
            'header'  => 'Content-type: application/x-www-form-urlencoded',
            'content' => http_build_query($params)
        )
    )));
  
}

echo send(ид пользователя,'test'); 
?>

The code sends a message to the user. How to send in a conversation?
https://vk.com/dev/messages.send?params[user_id]=2... Here I read that you can use peer_id instead of user_id and write for example 2000000000111 - where 1111 is the conversation number. But why doesn't it send?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Stockholm Syndrome, 2018-10-13
@StockholmSyndrome

write for example 2000000000111 - where 1111 is the conversation number

and even better chat_idto transfer, then you can just111

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question