Skip to content

Commit

Permalink
Merge pull request johnwheeler#221 from 3SpheresRoboticsProject/master
Browse files Browse the repository at this point in the history
Added support for ElicitSlot, ConfirmSlot, ConfirmIntent dialog directives
  • Loading branch information
johnwheeler authored Feb 28, 2018
2 parents 792546e + 3a0565b commit 39c61df
Show file tree
Hide file tree
Showing 2 changed files with 73 additions and 5 deletions.
10 changes: 9 additions & 1 deletion flask_ask/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,12 @@
convert_errors
)

from .models import question, statement, audio, delegate
from .models import (
question,
statement,
audio,
delegate,
elicit_slot,
confirm_slot,
confirm_intent
)
68 changes: 64 additions & 4 deletions flask_ask/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,8 @@
import aniso8601
from .core import session, context, current_stream, stream_cache, dbgdump
from .cache import push_stream
from . import logger
import uuid

from pprint import pprint


class _Field(dict):
"""Container to represent Alexa Request Data.
Expand Down Expand Up @@ -206,12 +203,75 @@ def reprompt(self, reprompt):

class delegate(_Response):

def __init__(self, speech):
def __init__(self, updated_intent=None):
self._response = {
'shouldEndSession': False,
'directives': [{'type': 'Dialog.Delegate'}]
}

if updated_intent:
self._response['directives'][0]['updatedIntent'] = updated_intent


class elicit_slot(_Response):
"""
Sends an ElicitSlot directive.
slot - The slot name to elicit
speech - The output speech
updated_intent - Optional updated intent
"""

def __init__(self, slot, speech, updated_intent=None):
self._response = {
'shouldEndSession': False,
'directives': [{
'type': 'Dialog.ElicitSlot',
'slotToElicit': slot,
}],
'outputSpeech': _output_speech(speech),
}

if updated_intent:
self._response['directives'][0]['updatedIntent'] = updated_intent

class confirm_slot(_Response):
"""
Sends a ConfirmSlot directive.
slot - The slot name to confirm
speech - The output speech
updated_intent - Optional updated intent
"""

def __init__(self, slot, speech, updated_intent=None):
self._response = {
'shouldEndSession': False,
'directives': [{
'type': 'Dialog.ConfirmSlot',
'slotToConfirm': slot,
}],
'outputSpeech': _output_speech(speech),
}

if updated_intent:
self._response['directives'][0]['updatedIntent'] = updated_intent

class confirm_intent(_Response):
"""
Sends a ConfirmIntent directive.
"""
def __init__(self, speech, updated_intent=None):
self._response = {
'shouldEndSession': False,
'directives': [{
'type': 'Dialog.ConfirmIntent',
}],
'outputSpeech': _output_speech(speech),
}

if updated_intent:
self._response['directives'][0]['updatedIntent'] = updated_intent


class audio(_Response):
"""Returns a response object with an Amazon AudioPlayer Directive.
Expand Down

0 comments on commit 39c61df

Please sign in to comment.