@@ -11,7 +11,7 @@ def __init__(self, speech, display_text=None, is_ssml=False):
1111 self ._display_text = display_text
1212 self ._integrations = current_app .config .get ("INTEGRATIONS" , [])
1313 self ._messages = [{"text" : {"text" : [speech ]}}]
14-
14+ self . _is_ssml = is_ssml
1515 self ._response = {
1616 "fulfillmentText" : speech ,
1717 "fulfillmentMessages" : self ._messages ,
@@ -197,6 +197,49 @@ def build_carousel(self, items=None):
197197 )
198198 return carousel
199199
200+ def add_media (self , url , name , description = None , icon_url = None , icon_alt = None ):
201+ """Adds a Media Card Response
202+
203+ Media responses let your Actions play audio content with a
204+ playback duration longer than the 240-second limit of SSML.
205+
206+ Can be included with ask and tell responses.
207+ If added to an `ask` response, suggestion chips
208+
209+ Arguments:
210+ url {str} -- Required. Url where the media is stored
211+ name {str} -- Name of media card.
212+
213+ Optional:
214+ description {str} -- A description of the item (default: {None})
215+ icon_url {str} -- Url of icon image
216+ icon_alt {str} -- Accessibility text for icon image
217+
218+ example usage:
219+
220+ resp = ask("Check out this tune")
221+ resp = resp.add_media(url, "Jazzy Tune")
222+ return resp_with_media.suggest("Next Song", "Done")
223+
224+
225+ """
226+ media_object = {"contentUrl" : url , "name" : name }
227+ if description :
228+ media_object ["description" ] = description
229+
230+ if icon_url :
231+ media_object ["largeImage" ] = {}
232+ media_object ["largeImage" ]["imageUri" ] = icon_url
233+ media_object ["largeImage" ]["accessibilityText" ] = icon_alt or name
234+
235+ self ._messages .append (
236+ {
237+ "platform" : "ACTIONS_ON_GOOGLE" ,
238+ "mediaContent" : {"mediaObjects" : [media_object ], "mediaType" : "AUDIO" ,},
239+ }
240+ )
241+ return self
242+
200243
201244def build_item (
202245 title , key = None , synonyms = None , description = None , img_url = None , alt_text = None
@@ -307,10 +350,12 @@ def __init__(self, speech, display_text=None, is_ssml=False):
307350 self ._response ["payload" ]["google" ]["expect_user_response" ] = True
308351
309352 def reprompt (self , prompt ):
310- self ._response ["payload" ]["google" ]["no_input_prompts" ] = [
311- {"text_to_speech" : prompt }
312- ]
313-
353+ repromtKey = "text_to_speech"
354+ if self ._is_ssml :
355+ repromtKey = "ssml"
356+ repromtResponse = {}
357+ repromtResponse [repromtKey ] = prompt
358+ self ._response ["payload" ]["google" ]["no_input_prompts" ] = [repromtResponse ]
314359 return self
315360
316361
@@ -367,18 +412,26 @@ class sign_in(_Response):
367412 with the `user.profile` local
368413
369414 In order to complete the sign in process, you will need to create an intent with
370- the `actions_intent_SIGN)IN ` event
415+ the `actions_intent_SIGN_IN ` event
371416 """
372417
418+ # Payload according to https://developers.google.com/assistant/conversational/helpers#account_sign-in
373419 def __init__ (self , reason = None ):
374420 super (sign_in , self ).__init__ (speech = None )
375421
376422 self ._messages [:] = []
377- self ._response ["payload" ]["google" ]["systemIntent" ] = {
378- "intent" : "actions.intent.SIGN_IN" ,
379- "data" : {
380- "optContext" : reason ,
381- "@type" : "type.googleapis.com/google.actions.v2.SignInValueSpec" ,
382- },
423+ self ._response = {
424+ "payload" : {
425+ "google" : {
426+ "expectUserResponse" : True ,
427+ "systemIntent" : {
428+ "intent" : "actions.intent.SIGN_IN" ,
429+ "data" : {
430+ "@type" : "type.googleapis.com/google.actions.v2.SignInValueSpec"
431+ },
432+ },
433+ }
434+ }
383435 }
384436
437+
0 commit comments