import vk_api
from vk_api.bot_longpoll import VkBotEventType, VkBotLongPoll
import json
vk = vk_api.VkApi(token="токен")
vk._auth_token()
vk.get_api()
keyboard = {
"one_time": False,
"buttons": [
[{
"action": {
"type": "text",
"payload": "{\"button\": \"1\"}",
"label": "верхняя левая кнопка"
},
"color": "negative"
},
{
"action": {
"type": "text",
"payload": "{\"button\": \"1\"}",
"label": "верхняя правая кнопка"
},
"color": "positive"
},
{
"action": {
"type": "text",
"payload": "{\"button\": \"2\"}",
"label": "нижняя левая кнопка"
},
"color": "primary"
},
{
"action": {
"type": "text",
"payload": "{\"button\": \"3\"}",
"label": "Нижняя правая"
},
"color": "secondary"
}
]
]
}
keyboard = json.dumps(keyboard, ensure_ascii=False).encode('utf-8')
keyboard = str(keyboard.decode('utf-8'))
longpoll = VkBotLongPoll(vk, айди сообщ-ва)
while True:
for event in longpoll.listen():
if event.type == VkBotEventType.MESSAGE_NEW:
if event.object.text.lower() == "новые кнопки":
vk.method("messages.send", {"peer_id": event.object.peer_id, "message": "Новые кнопки", "random_id": 0,
"keyboard": keyboard})
if "Negative" in event.object.text:
vk.method("messages.send", {"peer_id": event.object.peer_id, "message": "Красная кнопка", "random_id": 0
})
if "Positive" in event.object.text:
vk.method("messages.send", {"peer_id": event.object.peer_id, "message": "Зелёная кнопка", "random_id": 0
})
if "Primary" in event.object.text:
vk.method("messages.send", {"peer_id": event.object.peer_id, "message": "Синяя кнопка", "random_id": 0
})
if "Secondary" in event.object.text:
vk.method("messages.send", {"peer_id": event.object.peer_id, "message": "Обычная кнопка", "random_id": 0
})
from vk_api.keyboard import VkKeyboard, VkKeyboardColor
keyboard = VkKeyboard(one_time=False)
keyboard.add_button('нижняя левая кнопка', color=VkKeyboardColor.PRIMARY)
keyboard.add_button('Нижняя правая', color=VkKeyboardColor.SECONDARY)
keyboard.add_line()
keyboard.add_button('верхняя левая кнопка', color=VkKeyboardColor.NEGATIVE)
keyboard.add_button('верхняя правая кнопка', color=VkKeyboardColor.POSITIVE)
import vk_api
from vk_api.bot_longpoll import VkBotEventType, VkBotLongPoll
import json
vk = vk_api.VkApi(token="токен")
vk._auth_token()
vk.get_api()
keyboard = {
"one_time": False,
"buttons": [
[{
"action": {
"type": "text",
"payload": "{\"button\": \"1\"}",
"label": "верхняя левая кнопка"
},
"color": "negative"
},
{
"action": {
"type": "text",
"payload": "{\"button\": \"1\"}",
"label": "верхняя правая кнопка"
},
"color": "positive"
},
],[
{
"action": {
"type": "text",
"payload": "{\"button\": \"2\"}",
"label": "нижняя левая кнопка"
},
"color": "primary"
},
{
"action": {
"type": "text",
"payload": "{\"button\": \"3\"}",
"label": "Нижняя правая"
},
"color": "secondary"
}
]
]
}
keyboard = json.dumps(keyboard, ensure_ascii=False).encode('utf-8')
keyboard = str(keyboard.decode('utf-8'))
longpoll = VkBotLongPoll(vk, айди сообщ-ва)
while True: