Answer the question
In order to leave comments, you need to log in
Why does the inline button callback not work via vk_api?
The documentation has already been read hundreds of times. Everything is normally called - the button itself is there. It is clickable, but then no action. Infinite loading and nothing more
import json
import vk_api, vk
from vk_api.keyboard import VkKeyboard, VkKeyboardColor
from vk_api.utils import get_random_id
from vk_api.bot_longpoll import VkBotLongPoll, VkBotEventType
vk_session = vk_api.VkApi(token='token')
from vk_api.bot_longpoll import VkBotLongPoll, VkBotEventType
longpoll = VkBotLongPoll(vk_session, 'groupid')
vk = vk_session.get_api()
from vk_api.longpoll import VkLongPoll, VkEventType
keyboard_1 = VkKeyboard(one_time=False, inline=True)
keyboard_1.add_callback_button(
label="Кнопка",
color=VkKeyboardColor.SECONDARY,
payload={"type": "show_snackbar", "text": "Это исчезающее сообщение на экране"}
)
for event in longpoll.listen():
if event.type == VkBotEventType.MESSAGE_NEW:
if event.object.message['text'] == 'Кнопка':
if event.from_chat:
vk.messages.send(
keyboard = keyboard_1.get_keyboard(),
key = ('key'),
server = ('server'),
ts=('1'),
message = 'Кнопка:',
)
Answer the question
In order to leave comments, you need to log in
Everything turned out to be much easier. There is a button, but there was no reaction to the answer, so we write:
elif event.type == VkBotEventType.MESSAGE_EVENT:
vk.messages.sendMessageEventAnswer(
event_id=event.object.event_id,
user_id=event.object.user_id,
peer_id=event.object.peer_id,
event_data=json.dumps(event.object.payload)
)
Lay out the code, only then it will be possible to help, most likely your condition is written by type
if a == 'привет':
wtitemessage(id,'Приветик')
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question