44class _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
257266class 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
263272class 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