44class _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
248266class 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
254272class 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 ):
0 commit comments