F
F
Febel2018-08-30 19:25:18
Python
Febel, 2018-08-30 19:25:18

How to make the bot see conversation messages?

I have my own VK bot.
VK added the ability to add a community to conversations. My bot is in the community. All messages that come to the community - he answers them.
But the messages from the conversation, he does not even see them.
If you open the messages of the group, you will not see these conversations there either.
What to do?
How can a solution be found?

import requests
import vk_api
import vk
from random import randint
from vk_api.longpoll import VkLongPoll, VkEventType

hello = ['Доброго времени суток!','Ну привет.','Приветствую!','Приветули!','Здарова']
bye = ['Пока.','Бай-бай','До новых встреч!','Досвидания!','Пока-пока.']


vk = vk_api.VkApi(token='MYTOKEN')
vk._auth_token()


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})
def write_group(chat_id,s):
    vk.method('messages.send', {'chat_id': chat_id, 'message': s})

  

def main():

    longpoll = VkLongPoll(vk)

    for event in longpoll.listen():

        if event.type == VkEventType.MESSAGE_NEW:

            if event.from_user:

                response = vk.method('messages.getConversations', values)

                if response['items'] and response['items'][0]['last_message']['from_id'] > 0:

                    response = response['items'][0]

                    if event.text.lower() == 'привет'т or event.text.lower() =='приветик':
                        write_msg(response['conversation']['peer']['id'], hello[randint(0, len(hello) - 1)])

                    elif response['last_message']['text'].lower() == 'пока':
                        write_msg(response['conversation']['peer']['id'], bye[randint(0, len(bye) - 1)])
                 
                    else:
                        # write_msg(response['conversation']['peer']['id'], 'Я не знаю что тебе ответить.')
                        continue



            elif event.from_chat:

                response = vk.method('messages.getConversations', values)

                if response['items'] and response['items'][0]['last_message']['from_id'] > 0:
                    response = response['items'][0]
          
                    if event.text.lower() == 'привет' or event.text.lower() =='приветик':
                        write_group(event.chat_id,hello[randint(0, len(hello) - 1)])

                    elif event.text.lower() == 'пока':
                        write_group(event.chat_id,bye[randint(0, len(bye) - 1)])

                    else:
                        continue

if __name__ == '__main__':

Answer the question

In order to leave comments, you need to log in

1 answer(s)
H
Helow19274, 2018-08-30
@Febel

https://vk.com/dev/bots_longpoll
Implemented here: https://github.com/python273/vk_api

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question