Answer the question
In order to leave comments, you need to log in
Why is the keyboard not sent to VK_API?
I'm trying to send the keyboard via vk_api , but no matter how much I try, no matter how I change it, an error about the wrong format constantly pops up. I have already read all the documentation of VK, nothing helped. The code is below (the bot class itself wrote).
Sending a message:
keyboard = {
'one_time_': True,
'buttons': [
[{
'action': {
'type': 'text',
'label': 'BUTTON',
},
'color': 'positive',
}],
],
}
bot.send_message(event.user_id, 'MESSAGE', keyboard=keyboard)
def send_message(self, user_id, message, keyboard=None):
context = {
'user_id': user_id,
'random_id': int(random() * 10000000000000000),
'message': message,
}
if keyboard:
context.update({'keyboard': keyboard})
self.vk.method('messages.send', context)
vk_api.exceptions.ApiError: [100] One of the parameters specified was missing or invalid: keyboard contains incorrect JSON
Answer the question
In order to leave comments, you need to log in
You can use
the keyboard constructor from the vk_api library.
Yes, and your send function is very complicated, you can do it like this
def send_message(peer_id: Union[str, int], message: str = None, attachment=None, keyboard=None) -> None:
vk.messages.send(peer_id=peer_id, message=message, random_id=random.randint(-2147483648, +2147483647),
attachment=attachment, keyboard=keyboard)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question