L
L
leonardo jethro2021-05-13 14:23:06
In contact with
leonardo jethro, 2021-05-13 14:23:06

How to display new messages from the VK group using the vk-io library?

I have been trying for several days now to figure out how to display messages from the VK group (not mine).
If you help, I will be grateful.

Answer the question

In order to leave comments, you need to log in

3 answer(s)
M
MrZillaGold, 2021-05-14
@clown1

The include method checks for the presence of the same value in the array, for any new object (which it is after receiving a response from the API), this property will always be false, check for the presence of an object in the array by other values, for example, by a link {owner_id}_{id}ordate

P
Puma Thailand, 2021-05-13
@opium

And what's the problem get vol get and withdraw

L
leonardo jethro, 2021-05-13
@clown1

const { VK } = require('vk-io')
const vk = new VK({token: 'тут токен'});
let array = [];


setInterval( async function () {
  let response = await vk.api.wall.get({owner_id: -тут id группы, count: 1})
  if (response.count === 0) return;

  
  if (array.includes(response.items[0]) === false) {

    
     await console.log(response.items[0])
     array.push(response.items[0])
  } 
}, 1000);

What is the code error? It floods the console with a message.
609d79db3d6c6183581884.png
And if, for example, you get to the picture, it will still flood with a link to it
response.items[0].attachments[0].photo.sizes[0].url
But if you display the post ID instead of the picture, it will not flood. And when you send a new message to the VK group, it will not flood either.
Already tried to throw a link into a json file and output from it, the same thing
, and yes, when you display a photo, there are different links. they say with a different image size (pixels), I have already done what he would choose from all the links with the best quality. But this link is still flooding, but not different, namely the one with the best quality

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question