Answer the question
In order to leave comments, you need to log in
Chatbot for VK. How to read messages from a conversation?
How can I read messages from a conversation?
Trained on other sites.
The bot works in group messages.
If you go through authorization through the VK page, then only personal messages are read, and the bot does not perceive conversations.
So far my code is this:
values = {'out': 0, 'count': 100, 'offset': 0}
response=vk.method('messages.getConversations', values)
def write_msg(user_id, s):
vk.method('messages. send', {'user_id':user_id, 'message':s})
while True:
response=vk.method('messages.getConversations', values)
if response['items'] and response['items'][0 ]['last_message']['from_id']>0:
response=response['items'][0]
if response['last_message']['text'].lower()=='hello':
write_msg(response ['conversation']['peer']['id'], hello[randint(0, len(hello)-1)])
elif response['last_message']['text'].lower()=='/help':
write_msg(response['conversation']['peer']['id'], info)
time.sleep(1)
hello is a sheet that consists of different Strings
Answer the question
In order to leave comments, you need to log in
you must use Bots LongPoll API or Callback API to get messages instantly
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question