Skip to content

Commit 3f827c7

Browse files
authored
Add VkKeyboardButton.add_openlink_button (#342)
open_link button https://vk.com/dev/bots_docs_3
1 parent c0482e7 commit 3f827c7

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

vk_api/keyboard.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,9 @@ class VkKeyboardButton(Enum):
4444

4545
#: Кнопка с приложением VK Apps
4646
VKAPPS = "open_app"
47+
48+
#: Кнопка с ссылкой
49+
OPENLINK = "open_link"
4750

4851

4952

@@ -213,6 +216,37 @@ def add_vkapps_button(self, app_id, owner_id, label, hash, payload=None):
213216
'hash': hash
214217
}
215218
})
219+
220+
def add_openlink_button(self, label, link, payload=None):
221+
""" Добавить кнопку с ссылкой
222+
Максимальное количество кнопок на строке - 4
223+
224+
:param label: Надпись на кнопке
225+
:type label: str
226+
:param link: ссылка, которую необходимо открыть по нажатию на кнопку
227+
:type link: str
228+
:param payload: Параметр для callback api
229+
:type payload: str or list or dict
230+
"""
231+
current_line = self.lines[-1]
232+
233+
if len(current_line) >= 4:
234+
raise ValueError('Max 4 buttons on a line')
235+
236+
if payload is not None and not isinstance(payload, six.string_types):
237+
payload = sjson_dumps(payload)
238+
239+
button_type = VkKeyboardButton.OPENLINK.value
240+
241+
current_line.append({
242+
'action': {
243+
'type': button_type,
244+
'link' : link,
245+
'label': label,
246+
'payload': payload
247+
}
248+
})
249+
216250

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

0 commit comments

Comments
 (0)