P
P
PegasusPega2020-05-04 13:43:12
API
PegasusPega, 2020-05-04 13:43:12

How can I make it so that when I do a mailing list, the mailing list message is sent to all the people who have ever written to the group?

Just no idea how to organize it. I hope for your help.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexander Semin, 2020-11-20
@PegasusPega

const { VK, createCollectIterator, getRandomId } = require(`vk-io`);

const vk = new VK({
  token: "",
});

(async function () {
  const iterator = createCollectIterator({
    api: vk.api,
    method: "messages.getConversations",
    params: {},
    countPerRequest: 200,
  });

  for await (const chunk of iterator) {
    for (let element of chunk.items) {
      if (element.conversation.peer.type === `user`) {
        // Send message
        /*
        vk.api.messages.send({
          message: "Test",
          peer_id: element.conversation.peer.id,
          random_id: getRandomId(),
                });
                */
      }
    }
  }
})();

To get a list of all the people who have ever written to a group, you can use the messages.getConversations method.
After that, we filter it to get only people, since this method also returns conversations created by the group, and send the newsletter to these accounts in a commented block.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question