V
V
vkcoinbote12020-06-30 03:07:29
In contact with
vkcoinbote1, 2020-06-30 03:07:29

I can’t normally output SMS when joining the VK BOT group?

THERE IS php CODE for version 5.0, you can throw off the code for version 5.103 (so that SMS is displayed when subscribing and unsubscribing)
case 'group_join':

//...получаем id нового участника
        $user_id = $data->object->user_id; 
    //затем с помощью users.get получаем данные об авторе 
    $user_info = json_decode(file_get_contents("https://api.vk.com/method/users.get?user_ids={$user_id}&access_token={$token}&v=5.0"));


//и извлекаем из ответа его имя
        $user_name = $user_info->response[0]->first_name;

        //С помощью messages.send и токена сообщества отправляем ответное сообщение
        $request_params = array(
            'message' => "Добро пожаловать в наше сообщество, {$user_name}!",
            'user_id' => $user_id,
            'access_token' => $token,
            'v' => '5.0'
        );

Answer the question

In order to leave comments, you need to log in

1 answer(s)
N
Nikita Davydov, 2020-06-30
@vkcoinbote1

First, you are passing the parameter 'v' => '5.0', although the minimum should be 5.50.
You must pass the API version you are using, not the PHP version.
Secondly, I would recommend updating your PHP version to something faster than 5.0.
Thirdly, in the line: "$user_info = json_decode(file_get_contents(" https://api.vk.com/method/users.get?user_ids={$use... "));" no line ending though )); there is. Hmm, maybe you just copied this code from somewhere, but we don't care.
Just replace this line with:

$user_info = json_decode(file_get_contents("https://api.vk.com/method/users.get?user_ids={$user_id}&access_token={$token}&v=5.103"));

Потом... строчку 'v' => '5.0'
Замените на 'v' => '5.103'

В настройках группы, замените в разделе "Работа с API" -> "Callback API" -> "Настройка сервера" версию API на 5.103.
А в разделе  "Работа с API" -> "Callback API" -> "Типы запросов" поставьте галочки "Вступление в сообщество", и если нужно то "Выход из сообщества".

And also your code ends with:
//С помощью messages.send и токена сообщества отправляем ответное сообщение
$request_params = array(
'message' => "Добро пожаловать в наше сообщество, {$user_name}!",
'user_id' => $user_id,
'access_token' => $token,
'v' => '5.0'
);

Although, in this case, you must also send it.
Add at the end
$get_params = http_build_query($request_params);
file_get_contents(' https://api.vk.com/method/messages.send? '. $get_params);
echo('ok'); (If not)
break; (If not)
Also, if you need help setting it up, and if you do not understand anything from my text, then write to me on VK.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question