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

Commit bcfba8a

Browse files
committed
Merge branch 'release/0.3.4'
2 parents 8c53582 + 6ab92cf commit bcfba8a

File tree

2 files changed

+34
-16
lines changed

2 files changed

+34
-16
lines changed

flask_assistant/response.py

Lines changed: 33 additions & 15 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):
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,22 +26,40 @@ def __init__(self, speech):
2626
}
2727

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

31-
def add_msg(self, speech):
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)
34+
self._integrate_with_actions(speech, display_text, is_ssml)
3535

3636
return self
3737

38-
def _integrate_with_actions(self, speech=None):
39-
self._messages.append(
40-
{
41-
"platform": "ACTIONS_ON_GOOGLE",
42-
"simpleResponses": {"simpleResponses": [{"textToSpeech": speech}]},
43-
}
44-
)
38+
def _integrate_with_actions(self, speech=None, display_text=None, is_ssml=False):
39+
40+
if is_ssml:
41+
ssml_speech = "<speak>" + speech + "</speak>"
42+
self._messages.append(
43+
{
44+
"platform": "ACTIONS_ON_GOOGLE",
45+
"simpleResponses": {
46+
"simpleResponses": [
47+
{"ssml": ssml_speech, "displayText": display_text}
48+
]
49+
},
50+
}
51+
)
52+
else:
53+
self._messages.append(
54+
{
55+
"platform": "ACTIONS_ON_GOOGLE",
56+
"simpleResponses": {
57+
"simpleResponses": [
58+
{"textToSpeech": speech, "displayText": display_text}
59+
]
60+
},
61+
}
62+
)
4563

4664
def _include_contexts(self):
4765
from flask_assistant import core
@@ -246,20 +264,20 @@ def _add_message(self):
246264

247265

248266
class tell(_Response):
249-
def __init__(self, speech):
250-
super(tell, self).__init__(speech)
267+
def __init__(self, speech, display_text=None, is_ssml=False):
268+
super(tell, self).__init__(speech, display_text, is_ssml)
251269
self._response["payload"]["google"]["expect_user_response"] = False
252270

253271

254272
class ask(_Response):
255-
def __init__(self, speech):
273+
def __init__(self, speech, display_text=None, is_ssml=False):
256274
"""Returns a response to the user and keeps the current session alive.
257275
Expects a response from the user.
258276
259277
Arguments:
260278
speech {str} -- Text to be pronounced to the user / shown on the screen
261279
"""
262-
super(ask, self).__init__(speech)
280+
super(ask, self).__init__(speech, display_text, is_ssml)
263281
self._response["payload"]["google"]["expect_user_response"] = True
264282

265283
def reprompt(self, prompt):

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
setup(
1313
name="Flask-Assistant",
14-
version="0.3.3",
14+
version="0.3.4",
1515
url="https://github.com/treethought/flask-assistant",
1616
license="Apache 2.0",
1717
author="Cam Sweeney",

0 commit comments

Comments
 (0)