V
V
Valery Kovalev2019-05-02 18:46:21
In contact with
Valery Kovalev, 2019-05-02 18:46:21

How to delete messages in a VK conversation through the VK API?

What api method in VK erases all conversation messages on behalf of the conversation admin for all users? That is, no one should see the old messages

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Stockholm Syndrome, 2019-05-02
@StockholmSyndrome

there is no such method, but we do not despair and do this:
using messages.getHistory and execute we get all the messages of the conversation at 5000 per request, the
code for execute will be something like this (it is better to minify for speed):

var peer_id = 2000000001; // идентификатор беседы
var results = [];
var i = 0; 
var offset = 0; 
while (i < 25) {
  results.push(API.messages.getHistory({peer_id: peer_id, count: 200, offset: offset}));
  i = i + 1;
  offset = offset + 200;
}
return [email protected];

the result will be an array of 25 arrays of message objects
, with each request you need to increase the offset by 5000
, then iterate over these arrays of objects, and if the from_id field is equal to the conversation admin identifier, then add the id field to some message_ids array
when all message_ids are collected, just we send them to the messages.delete method with the delete_for_all=1
parameter, you need to send execute requests until the length of the arrays becomes zero
PS forgot to break it off - the message can be deleted for everyone only within 24 hours after writing, alas ...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question