Home computickets How to get conversation ID using VK API?

How to get conversation ID using VK API?




I need to get the ID of a VK conversation in order to write to it from several pages. The trouble is, each has a different conversation ID for each personal page. Is there a vk api method that allows you to determine the ID of a conversation by its name or otherwise?

Answer 1

Found the right method, but it will only work if the conversation with this name is the only one or only there is activity in it. This is the messages.searchConversations () method.
In Python, it looks something like this:

import vk_api
vk_session = vk_api.VkApi (token = 'token')
vk = vk_session.get_api ()
chat_id = vk.messages.searchConversations (q = 'chat name', count = 1) ['items'] [0] ['peer'] ['local_id']

You can read more about it in the official documentation: https://vk.com/dev/messages. searchConversations

Programmers, Start Your Engines!

Why spend time searching for the correct question and then entering your answer when you can find it in a second? That's what CompuTicket is all about! Here you'll find thousands of questions and answers from hundreds of computer languages.

Recent questions