E
E
egorlisss2019-04-18 15:54:38
JavaScript
egorlisss, 2019-04-18 15:54:38

How to change the name of a conversation after a certain period of time?

It is necessary to change the name of the conversation once a day.
It turned out something like this, but not what you need.

setInterval(function(){
  vk.updates.on('message', async (context) => {
  await vk.api.messages.editChat({
          chat_id: 3,
          title: (`test`)
  })});
  }, 1000);

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vladlen Hellsite, 2019-04-18
@egorlisss

Would this option work?

const conversations = new Map([
    [3, 'test']
]);

async function updateChatTitle() {
    for (const [chatId, title] of conversations) {
        try {
            await vk.api.messages.editChat({
                chat_id: chatId,
                title: title
            });
        } catch (error) {
            console.error(`Could not update conversation name ${chatId}`, error);
        } 
    }

    setTimeout(updateChatTitle, 1000);
}

updateChatTitle();

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question