Answer the question
In order to leave comments, you need to log in
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);
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question