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

Commit e6527e0

Browse files
committed
add fixes for buttons helper for #116
1 parent 27e1af2 commit e6527e0

File tree

3 files changed

+13
-6
lines changed

3 files changed

+13
-6
lines changed

flask_assistant/core.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -129,10 +129,9 @@ def init_app(self, app):
129129
app.add_url_rule(
130130
self._route, view_func=self._flask_assitant_view_func, methods=["POST"]
131131
)
132-
if self.client_id is None:
132+
if self.client_id is None and self.app is not None:
133133
self.client_id = self.app.config.get("AOG_CLIENT_ID")
134134

135-
136135
# Taken from Flask-ask courtesy of @voutilad
137136
def init_blueprint(self, blueprint, path="templates.yaml"):
138137
"""Initialize a Flask Blueprint, similar to init_app, but without the access
@@ -158,11 +157,11 @@ def init_blueprint(self, blueprint, path="templates.yaml"):
158157
blueprint.add_url_rule(
159158
"", view_func=self._flask_assitant_view_func, methods=["POST"]
160159
)
160+
161161
# blueprint.jinja_loader = ChoiceLoader([YamlLoader(blueprint, path)])
162-
if self.client_id is None:
162+
if self.client_id is None and self.app is not None:
163163
self.client_id = self.app.config.get("AOG_CLIENT_ID")
164164

165-
166165
@property
167166
def request(self):
168167
"""Local Proxy refering to the request JSON recieved from Dialogflow"""

flask_assistant/response/actions.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,10 @@ def build_card(
1111

1212
card_payload = {"title": title, "subtitle": subtitle, "formattedText": text}
1313

14-
if link and link_title:
14+
if buttons:
15+
card_payload["buttons"] = buttons
16+
17+
elif link and link_title:
1518
btn_payload = [{"title": link_title, "openUriAction": {"uri": link}}]
1619
card_payload["buttons"] = btn_payload
1720

flask_assistant/response/base.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,7 @@ def card(
168168
subtitle=None,
169169
link=None,
170170
link_title=None,
171+
buttons=None,
171172
):
172173
df_card = dialogflow.build_card(
173174
text, title, img_url, img_alt, subtitle, link, link_title
@@ -192,7 +193,7 @@ def card(
192193

193194
if "ACTIONS_ON_GOOGLE" in self._integrations:
194195
actions_card = actions.build_card(
195-
text, title, img_url, img_alt, subtitle, link, link_title
196+
text, title, img_url, img_alt, subtitle, link, link_title, buttons
196197
)
197198

198199
self._messages.append(actions_card)
@@ -282,6 +283,10 @@ def add_media(self, url, name, description=None, icon_url=None, icon_alt=None):
282283
return self
283284

284285

286+
def build_button(title, link):
287+
return {"title": title, "openUriAction": {"uri": link}}
288+
289+
285290
def build_item(
286291
title, key=None, synonyms=None, description=None, img_url=None, alt_text=None
287292
):

0 commit comments

Comments
 (0)