O
O
ojiekcahdp2021-10-24 20:57:20
Java
ojiekcahdp, 2021-10-24 20:57:20

How to get new messages in vk api conversation?

How many I try to understand - nothing. Here is the groups.getLongPollServer method, but it is not clear how to get messages out of it. Another thing is with the same method, only in messages, but there I receive only private messages, but I need it from a conversation.

TransportClient transportClient = HttpTransportClient.getInstance();
        VkApiClient vk = new VkApiClient(transportClient);
        GroupActor groupActor = new GroupActor(айди, "токен");
        Integer ts = vk.messages().getLongPollServer(groupActor).execute().getTs();
        while (true){
            MessagesGetLongPollHistoryQuery historyQuery = vk.messages().getLongPollHistory(groupActor).ts(ts);
            List<Message> messages = historyQuery.execute().getMessages().getItems();
            if (!messages.isEmpty()){
                messages.forEach(message -> {
                    System.out.println(message.toString());
                });
            }
            ts = vk.messages().getLongPollServer(groupActor).execute().getTs();
            Thread.sleep(500);
        }

I use the official sdk from vk. I will be glad to help

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question