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

Commit 281a242

Browse files
committed
restore display_text support
1 parent 0f7d9bb commit 281a242

File tree

1 file changed

+21
-12
lines changed

1 file changed

+21
-12
lines changed

flask_assistant/response.py

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
class _Response(object):
55
"""Base webhook response to be returned to Dialogflow"""
66

7-
def __init__(self, speech, is_ssml=False):
7+
def __init__(self, speech, display_text=None, is_ssml=False):
88

99
self._speech = speech
1010
self._integrations = current_app.config.get("INTEGRATIONS", [])
@@ -26,29 +26,38 @@ def __init__(self, speech, is_ssml=False):
2626
}
2727

2828
if "ACTIONS_ON_GOOGLE" in self._integrations:
29-
self._integrate_with_actions(speech, is_ssml)
29+
self._integrate_with_actions(speech, display_text, is_ssml)
3030

31-
def add_msg(self, speech, is_ssml=False):
31+
def add_msg(self, speech, display_text=None, is_ssml=False):
3232
self._messages.append({"text": {"text": [speech]}})
3333
if "ACTIONS_ON_GOOGLE" in self._integrations:
34-
self._integrate_with_actions(speech, is_ssml)
34+
self._integrate_with_actions(speech, display_text, is_ssml)
3535

3636
return self
3737

38-
def _integrate_with_actions(self, speech=None, is_ssml=False):
38+
def _integrate_with_actions(self, speech=None, display_text=None, is_ssml=False):
39+
3940
if is_ssml:
40-
speech = "<speak>" + speech + "</speak>"
41+
ssml_speech = "<speak>" + speech + "</speak>"
4142
self._messages.append(
4243
{
4344
"platform": "ACTIONS_ON_GOOGLE",
44-
"simpleResponses": {"simpleResponses": [{"ssml": speech}]},
45+
"simpleResponses": {
46+
"simpleResponses": [
47+
{"ssml": ssml_speech, "displayText": display_text}
48+
]
49+
},
4550
}
4651
)
4752
else:
4853
self._messages.append(
4954
{
5055
"platform": "ACTIONS_ON_GOOGLE",
51-
"simpleResponses": {"simpleResponses": [{"textToSpeech": speech}]},
56+
"simpleResponses": {
57+
"simpleResponses": [
58+
{"textToSpeech": speech, "displayText": display_text}
59+
]
60+
},
5261
}
5362
)
5463

@@ -255,20 +264,20 @@ def _add_message(self):
255264

256265

257266
class tell(_Response):
258-
def __init__(self, speech, is_ssml=False):
259-
super(tell, self).__init__(speech, is_ssml)
267+
def __init__(self, speech, display_text=None, is_ssml=False):
268+
super(tell, self).__init__(speech, display_text, is_ssml)
260269
self._response["payload"]["google"]["expect_user_response"] = False
261270

262271

263272
class ask(_Response):
264-
def __init__(self, speech, is_ssml=False):
273+
def __init__(self, speech, display_text=None, is_ssml=False):
265274
"""Returns a response to the user and keeps the current session alive.
266275
Expects a response from the user.
267276
268277
Arguments:
269278
speech {str} -- Text to be pronounced to the user / shown on the screen
270279
"""
271-
super(ask, self).__init__(speech, is_ssml)
280+
super(ask, self).__init__(speech, display_text, is_ssml)
272281
self._response["payload"]["google"]["expect_user_response"] = True
273282

274283
def reprompt(self, prompt):

0 commit comments

Comments
 (0)