Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for Progressive Responses #250

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
18 changes: 18 additions & 0 deletions docs/responses.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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("<speak>Please wait while I get today's events. <audio src="https://yoursite.com/jeopardy.mp3"/></speak>")
return statement('Today at 3pm, you have scheduled feeding deadly cobras!')

``progressive_response`` may only be used within an intent function.

Session Management
------------------

Expand Down
3 changes: 2 additions & 1 deletion flask_ask/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,6 @@
confirm_intent,
buy,
upsell,
refund
refund,
progressive_response
)
20 changes: 20 additions & 0 deletions flask_ask/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't hardcode request Id

},
"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):
Expand Down