Skip to content
This repository was archived by the owner on Jun 26, 2025. It is now read-only.

Commit d27c988

Browse files
authored
Merge pull request #116 from Serafim-End/fix_user_storage
update isinstance of user_storage / multiple buttons per card
2 parents 337a424 + 5ef4bb3 commit d27c988

File tree

2 files changed

+27
-4
lines changed

2 files changed

+27
-4
lines changed

flask_assistant/__init__.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,10 @@
2626
profile
2727
)
2828

29-
from flask_assistant.response import ask, tell, event, build_item, permission, sign_in
29+
from flask_assistant.response import (
30+
ask, tell, event, build_item, permission, sign_in, build_button
31+
)
32+
3033
from flask_assistant.manager import Context
3134

3235
import flask_assistant.utils

flask_assistant/response.py

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -140,13 +140,26 @@ def card(
140140
subtitle=None,
141141
link=None,
142142
link_title=None,
143+
buttons=None,
143144
):
145+
"""
146+
:param: link and :param: link_title supports only one button per card
147+
in future versions should be deleted
148+
and from now deprecated
149+
150+
:param link:
151+
:param link_title:
152+
:return:
153+
"""
144154

145155
card_payload = {"title": title, "subtitle": subtitle, "formattedText": text}
146156

147-
if link and link_title:
148-
btn_payload = [{"title": link_title, "openUriAction": {"uri": link}}]
149-
card_payload["buttons"] = btn_payload
157+
if buttons:
158+
card_payload["buttons"] = buttons
159+
elif link and link_title:
160+
logger.info('use button parameter instead of link and link_title')
161+
buttons = [build_button(title=link_title, link=link)]
162+
card_payload["buttons"] = buttons
150163

151164
if img_url:
152165
img_payload = {"imageUri": img_url, "accessibilityText": img_alt or img_url}
@@ -241,6 +254,13 @@ def add_media(self, url, name, description=None, icon_url=None, icon_alt=None):
241254
return self
242255

243256

257+
def build_button(title, link):
258+
return {
259+
"title": title,
260+
"openUriAction": {"uri": link}
261+
}
262+
263+
244264
def build_item(
245265
title, key=None, synonyms=None, description=None, img_url=None, alt_text=None
246266
):

0 commit comments

Comments
 (0)