def write_msg(self, user_id, message):
try:
self.vk.method('messages.send', {'user_id': user_id, 'message': message, 'keyboard': keyboard, 'random_id': random.randint(0, 100000000)})
except Exception as ex:
print("error (write_msg, {0}, {1}):".format(user_id, message), ex)
keyboard = '''
{
"one_time": false,
"buttons": [
[
{
"action": {
"type": "text",
"label": "Подписаться"
},
"color": "positive"
},
{
"action": {
"type":"text",
"label":"Отписаться"
},
"color": "negative"
},
{
"action": {
"type":"text",
"label":"Команды"
},
"color": "primary"
}
]
]
}
'''
keyboard2 = '''
{
"one_time": false,
"buttons": [
[
{
"action": {
"type": "text",
"label": "Кнопка 1"
},
"color": "positive"
},
{
"action": {
"type":"text",
"label":"Кнопка 2"
},
"color": "negative"
},
{
"action": {
"type":"text",
"label":"Вернуться назад"
},
"color": "primary"
}
]
]
}
'''
for event in self.longpoll.listen():
if event.type == VkEventType.MESSAGE_NEW and event.to_me:
id = event.user_id
msg = event.text.lower()
if msg == "подписаться":
#ТОГДА ПОКАЖИ ЮСЕРУ КЛАВИАТУРУ НОМЕР 2!!!
def write_msg(self, user_id, message, key):
try:
self.vk.method('messages.send', {'user_id': user_id, 'message': message, 'keyboard': key, 'random_id': random.randint(0, 100000000)})
except Exception as ex:
print("error (write_msg, {0}, {1}):".format(user_id, message), ex)
for event in self.longpoll.listen():
if event.type == VkEventType.MESSAGE_NEW and event.to_me:
id = event.user_id
msg = event.text.lower()
if msg == "подписаться":
write_msg(id, 'Подписались', keyboard2)
keyboard = '''
{
"one_time": false,
"buttons": [
[
{
"action": {
"type": "text",
"label": "Подписаться"
},
"color": "positive"
},
{
"action": {
"type":"text",
"label":"Отписаться"
},
"color": "negative"
},
{
"action": {
"type":"text",
"label":"Команды"
},
"color": "primary"
}
]
[
{
"action": {
"type": "text",
"label": "Кнопка 1"
},
"color": "positive"
},
{
"action": {
"type":"text",
"label":"Кнопка 2"
},
"color": "negative"
},
{
"action": {
"type":"text",
"label":"Вернуться назад"
},
"color": "primary"
}
]
]
}
'''