M
M
mishkafrede20042022-03-29 10:23:43
Python
mishkafrede2004, 2022-03-29 10:23:43

I work with the Vkbottle framework, I can't make a callback button. What to do?

I started working with the vkbottle framework, set the task of creating a callback button. When you click on it, the following error pops up

1 validation error for MessageEvent
object -> conversation_message_id
  field required (type=value_error.missing)
Traceback (most recent call last):
  File "E:\vkbottle\main\lib\site-packages\vkbottle\dispatch\base.py", line 22, in route
    await view.handle_event(event, ctx_api, self.state_dispenser)
  File "E:\vkbottle\main\lib\site-packages\vkbottle\dispatch\views\abc\raw.py", line 46, in handle_event
    event_model = self.get_event_model(handler_basement, event)
  File "E:\vkbottle\main\lib\site-packages\vkbottle\dispatch\views\bot\raw.py", line 33, in get_event_model
    return handler_basement.dataclass(**event)
  File "pydantic\main.py", line 331, in pydantic.main.BaseModel.__init__
pydantic.error_wrappers.ValidationError: 1 validation error for MessageEvent
object -> conversation_message_id
  field required (type=value_error.missing)


Code:
from vkbottle.bot import Bot, Message
from vkbottle import GroupEventType, GroupTypes, VKAPIError, Keyboard, Callback
from vkbottle.modules import json

bot = Bot(token='///')


@bot.on.message(text="start")
async def handler(message: Message):
    keyboard = (
        Keyboard()
        .add(Callback("Click", {"cmd": "click"}))
        .add(Callback("Click 2", {"cmd": "click2"}))
    )

    await message.answer("callback button", keyboard=keyboard)


@bot.on.raw_event(GroupEventType.MESSAGE_EVENT, dataclass=GroupTypes.MessageEvent)
async def message_event_handler(event: GroupTypes.MessageEvent):
    if event.object.payload["cmd"] == "click":
        await bot.api.messages.send_message_event_answer(
            event_id=event.object.event_id,
            peer_id=event.object.peer_id,
            user_id=event.object.user_id,
            event_data=json.dumps({"type": "show_snackbar", "text": "Test message"})
        )
    else:
        await bot.api.messages.send_message_event_answer(
            event_id=event.object.event_id,
            peer_id=event.object.peer_id,
            user_id=event.object.user_id,
            event_data=json.dumps({"type": "show_snackbar", "text": "Test message 2"})
        )


@bot.on.raw_event(GroupEventType.GROUP_JOIN, dataclass=GroupTypes.GroupJoin)
async def group_join_handler(event: GroupTypes.GroupJoin):
    try:
        await bot.api.messages.send(
            peer_id=event.object.user_id,
            message="Welcome to the club, buddy!",
            random_id=0
        )
    except VKAPIError[901]:
        pass


@bot.on.raw_event(GroupEventType.GROUP_LEAVE, dataclass=GroupTypes.GroupLeave)
async def group_leave_handler(event: GroupTypes.GroupLeave):
    try:
        await bot.api.messages.send(
            peer_id=event.object.user_id,
            message="So sorry...",
            random_id=0
        )
    except VKAPIError[901]:
        pass


bot.run_forever()

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question