From 9712b05700966c6e002c84a79390ee68d11f9fc7 Mon Sep 17 00:00:00 2001 From: Cream Crumpets Date: Wed, 19 Sep 2018 13:50:06 -0400 Subject: [PATCH 1/8] Add Progressive Responses Implements the following API through the progressive_response function to be used in intent functions. https://developer.amazon.com/docs/custom-skills/send-the-user-a-progressive-response.html --- flask_ask/models.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/flask_ask/models.py b/flask_ask/models.py index d159f7b..1276112 100644 --- a/flask_ask/models.py +++ b/flask_ask/models.py @@ -440,6 +440,25 @@ 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'] = context.System.apiAccessToken + response['directive']['speech'] = request.requestId + + + headers = {"Authorization":'Bearer '+authToken, "Content-Type":"application/json"} + r = requests.post("https://api.amazonalexa.com/v1/directives", headers=headers, json=response) + return r.status_code def _copyattr(src, dest, attr, convert=None): From c5aa0d3e1b6a7b7c241002d3f14d076536fda67f Mon Sep 17 00:00:00 2001 From: Cream Crumpets Date: Wed, 19 Sep 2018 13:59:59 -0400 Subject: [PATCH 2/8] Import progressive_response --- flask_ask/__init__.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) 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 ) From 7286515958c668997bc3dfde7a7bc4a3b2209fc0 Mon Sep 17 00:00:00 2001 From: Cream Crumpets Date: Wed, 19 Sep 2018 14:21:55 -0400 Subject: [PATCH 3/8] Document progressive_response use cases --- docs/responses.rst | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/docs/responses.rst b/docs/responses.rst index b262929..cbfdd47 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('ConfirmAppointmentIntent') + def confirm_appointment(): + 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 ------------------ From e7778bb307d3c234282abe82e347f0493b7ba45d Mon Sep 17 00:00:00 2001 From: Cream Crumpets Date: Wed, 19 Sep 2018 14:28:24 -0400 Subject: [PATCH 4/8] Fix progressive_response SSML example --- docs/responses.rst | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/docs/responses.rst b/docs/responses.rst index cbfdd47..b114805 100644 --- a/docs/responses.rst +++ b/docs/responses.rst @@ -50,19 +50,19 @@ Sending updates with ``progressive_response`` -------------------------- ``progressive_response`` causes Alexa to speak while your app finishes processing a request:: - @ask.intent('ConfirmAppointmentIntent') - def confirm_appointment(): + @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 +``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("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:: +``progressive_response`` may only be used within an intent function:: Session Management ------------------ From cf1e27d23a9edc428851df71398ecbcd2d9bc322 Mon Sep 17 00:00:00 2001 From: Cream Crumpets Date: Wed, 19 Sep 2018 14:30:45 -0400 Subject: [PATCH 5/8] Fix formatting --- docs/responses.rst | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/docs/responses.rst b/docs/responses.rst index b114805..28dce56 100644 --- a/docs/responses.rst +++ b/docs/responses.rst @@ -55,12 +55,12 @@ Sending updates with ``progressive_response`` 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`` 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:: From fbd49244bded66091b7b4f7a40483dcfe5558339 Mon Sep 17 00:00:00 2001 From: Cream Crumpets Date: Wed, 19 Sep 2018 14:31:25 -0400 Subject: [PATCH 6/8] Update responses.rst --- docs/responses.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/responses.rst b/docs/responses.rst index 28dce56..07669cb 100644 --- a/docs/responses.rst +++ b/docs/responses.rst @@ -62,7 +62,7 @@ Sending updates with ``progressive_response`` 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:: +``progressive_response`` may only be used within an intent function. Session Management ------------------ From 4a7bd021456f8cdc6f5d564ec508efb0168936c1 Mon Sep 17 00:00:00 2001 From: Cream Crumpets Date: Sat, 18 May 2019 21:34:54 -0400 Subject: [PATCH 7/8] Bug Fixes Correct Request ID US Alexa API endpoint no longer hardcoded. Sends speech with response --- flask_ask/models.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/flask_ask/models.py b/flask_ask/models.py index 1276112..fbacfa1 100644 --- a/flask_ask/models.py +++ b/flask_ask/models.py @@ -452,12 +452,13 @@ def progressive_response(speech:str): "speech":"This text is spoken while your skill processes the full response." } } - response['header']['requestId'] = context.System.apiAccessToken - response['directive']['speech'] = request.requestId - + 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("https://api.amazonalexa.com/v1/directives", headers=headers, json=response) + r = requests.post(alexaAPIendpoint + "/v1/directives", headers=headers, json=response) return r.status_code From 7c99a1e4b45401c12530c1ae93e17f993596cee0 Mon Sep 17 00:00:00 2001 From: Cream Crumpets Date: Sun, 24 May 2020 15:46:12 -0400 Subject: [PATCH 8/8] Update requirements.txt --- requirements.txt | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) 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