Answer the question
In order to leave comments, you need to log in
How to make the bot work in a VK conversation?
Here is my code. He responds well to messages in PM, but does not respond in conversation. Even when you contact him.
import vk_api, json
from vk_api.longpoll import VkLongPoll, VkEventType
vk_session = vk_api.VkApi(token = 'токен')
vk = vk_session.get_api()
longpol = VkLongPoll(vk_session)
def get_but(text, color):
return {
"action": {
"type": "text",
"payload": "{\"button\": \"" + "1" + "\"}",
"label": f"{text}"
},
"color": f"{color}"
}
keyboard = {
"one_time" : False,
"buttons" : [
[get_but('ДЗ', 'positive'), get_but('Пока', 'positive')],
]
}
keyboard = json.dumps(keyboard, ensure_ascii = False).encode('utf-8')
keyboard = str(keyboard.decode('utf-8'))
def sender(id, text):
vk_session.method('messages.send', {'user_id' : id, 'message' : text, 'random_id' : 0, 'keyboard' : keyboard})
def main():
for event in longpol.listen():
if event.type == VkEventType.MESSAGE_NEW:
if event.to_me:
id = event.user_id
msg = event.text.lower()
if msg == 'привет':
sender(id, msg.title())
if msg == 'дз':
fhandle = open('texto.txt')
sender(id, fhandle)
while True:
main()
Answer the question
In order to leave comments, you need to log in
Greetings.
When you click on the buttons in VKontakte conversations, the bot mentions, and after the mention writes the text of the button.
Try to make a command with a mention.
The command should look like this: [club123123|@my_bot]
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question