diff --git a/docs/responses.rst b/docs/responses.rst index b262929..07669cb 100644 --- a/docs/responses.rst +++ b/docs/responses.rst @@ -46,6 +46,24 @@ If the user doesn't respond, encourage them by rephrasing the question with ``re .reprompt("I didn't get that. When would you like to be seen?") +Sending updates with ``progressive_response`` +-------------------------- +``progressive_response`` causes Alexa to speak while your app finishes processing a request:: + + @ask.intent('ListAppointmentIntent') + def list_appointments(): + progressive_response("One moment while I add coconut harvesting to your calendar.") + return statement('Alright! Coconut harvesting is scheduled for when the coconut turns brown.') + +``progressive_response`` supports SSML by default:: + + @ask.intent('ConfirmAppointmentIntent') + def confirm_appointment(): + progressive_response("Please wait while I get today's events. ") + return statement('Today at 3pm, you have scheduled feeding deadly cobras!') + +``progressive_response`` may only be used within an intent function. + Session Management ------------------ diff --git a/flask_ask/__init__.py b/flask_ask/__init__.py index d878d12..56dea69 100644 --- a/flask_ask/__init__.py +++ b/flask_ask/__init__.py @@ -26,5 +26,6 @@ confirm_intent, buy, upsell, - refund + refund, + progressive_response ) diff --git a/flask_ask/models.py b/flask_ask/models.py index d159f7b..fbacfa1 100644 --- a/flask_ask/models.py +++ b/flask_ask/models.py @@ -440,6 +440,26 @@ def clear_queue(self, stop=False): self._response['directives'].append(directive) return self + +def progressive_response(speech:str): + """Causes Alexa to speak before your skill sends its full response.""" + response = { + "header":{ + "requestId":"amzn1.echo-api.request.xxxxxxx" + }, + "directive":{ + "type":"VoicePlayer.Speak", + "speech":"This text is spoken while your skill processes the full response." + } + } + response['header']['requestId'] = request.requestId + response['directive']['speech'] = speech + + authToken = context.System.apiAccessToken + alexaAPIendpoint = context.System.apiEndpoint + headers = {"Authorization":'Bearer '+authToken, "Content-Type":"application/json"} + r = requests.post(alexaAPIendpoint + "/v1/directives", headers=headers, json=response) + return r.status_code def _copyattr(src, dest, attr, convert=None): diff --git a/requirements.txt b/requirements.txt index 50a7927..e643668 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,7 +1,7 @@ -aniso8601==1.2.0 -Flask==0.12.1 -cryptography==2.1.4 -pyOpenSSL==17.0.0 -PyYAML==3.12 -six==1.11.0 +aniso8601 +Flask +cryptography +pyOpenSSL +PyYAML +six