Skip to content

Commit

Permalink
Add VkKeyboardButton.add_openlink_button (#342)
Browse files Browse the repository at this point in the history
  • Loading branch information
viklover committed Feb 21, 2020
1 parent c0482e7 commit 3f827c7
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions vk_api/keyboard.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ class VkKeyboardButton(Enum):

#: Кнопка с приложением VK Apps
VKAPPS = "open_app"

#: Кнопка с ссылкой
OPENLINK = "open_link"



Expand Down Expand Up @@ -213,6 +216,37 @@ def add_vkapps_button(self, app_id, owner_id, label, hash, payload=None):
'hash': hash
}
})

def add_openlink_button(self, label, link, payload=None):
""" Добавить кнопку с ссылкой
Максимальное количество кнопок на строке - 4
:param label: Надпись на кнопке
:type label: str
:param link: ссылка, которую необходимо открыть по нажатию на кнопку
:type link: str
:param payload: Параметр для callback api
:type payload: str or list or dict
"""
current_line = self.lines[-1]

if len(current_line) >= 4:
raise ValueError('Max 4 buttons on a line')

if payload is not None and not isinstance(payload, six.string_types):
payload = sjson_dumps(payload)

button_type = VkKeyboardButton.OPENLINK.value

current_line.append({
'action': {
'type': button_type,
'link' : link,
'label': label,
'payload': payload
}
})


def add_line(self):
""" Создаёт новую строку, на которой можно размещать кнопки.
Expand Down

0 comments on commit 3f827c7

Please sign in to comment.