Skip to content

Commit 8bf1d2b

Browse files
authored
Merge pull request #189 from alexa/shreraju/repromptDirective
feat: Adding Directive support for RePrompt SPI
2 parents dc89038 + a89c92e commit 8bf1d2b

File tree

3 files changed

+64
-16
lines changed

3 files changed

+64
-16
lines changed

ask-sdk-core/ask_sdk_core/response_helper.py

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,16 +17,17 @@
1717
#
1818

1919
import typing
20+
2021
from ask_sdk_model import Response
21-
from ask_sdk_model.ui import SsmlOutputSpeech, Reprompt
22-
from ask_sdk_model.interfaces.display import (
23-
TextContent, PlainText, RichText)
22+
from ask_sdk_model.interfaces.display import PlainText, RichText, TextContent
23+
from ask_sdk_model.ui import Reprompt, SsmlOutputSpeech
2424

2525
if typing.TYPE_CHECKING:
2626
from typing import Union
27+
2728
from ask_sdk_model import Directive
28-
from ask_sdk_model.ui import Card
2929
from ask_sdk_model.canfulfill import CanFulfillIntent
30+
from ask_sdk_model.ui import Card
3031
from ask_sdk_model.ui.play_behavior import PlayBehavior
3132

3233

@@ -132,6 +133,25 @@ def add_directive(self, directive):
132133
self.response.directives.append(directive)
133134
return self
134135

136+
def add_directive_to_reprompt(self, directive):
137+
# type: (Directive) -> 'ResponseFactory'
138+
"""Adds directive to reprompts.
139+
140+
:param directive: the directive sent back to Alexa device.
141+
:type directive: ask_sdk_model.directive.Directive
142+
:return: response factory with partial response being built and
143+
access from self.response.
144+
:rtype: ResponseFactory
145+
"""
146+
if self.response.reprompt is None:
147+
self.response.reprompt = Reprompt(directives=[])
148+
149+
if self.response.reprompt.directives is not None:
150+
self.response.reprompt.directives.append(directive)
151+
152+
self.set_should_end_session(False)
153+
return self
154+
135155
def set_should_end_session(self, should_end_session):
136156
# type: (bool) -> 'ResponseFactory'
137157
"""Sets shouldEndSession value to null/false/true.

ask-sdk-core/tests/unit/test_response_helper.py

Lines changed: 34 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -18,20 +18,23 @@
1818

1919
import unittest
2020

21-
from ask_sdk_model.interfaces.videoapp import LaunchDirective, VideoItem, Metadata
22-
from ask_sdk_model.ui import SsmlOutputSpeech, Reprompt
23-
from ask_sdk_model.interfaces.display import TextContent
24-
from ask_sdk_model.interfaces.display import PlainText
25-
from ask_sdk_model.interfaces.display import RichText
26-
from ask_sdk_model.canfulfill import (
27-
CanFulfillIntent, CanFulfillIntentValues, CanFulfillSlot,
28-
CanFulfillSlotValues, CanUnderstandSlotValues)
21+
from ask_sdk_core.response_helper import (PLAIN_TEXT_TYPE, RICH_TEXT_TYPE,
22+
ResponseFactory,
23+
get_plain_text_content,
24+
get_rich_text_content,
25+
get_text_content)
26+
from ask_sdk_model import directive
27+
from ask_sdk_model.canfulfill import (CanFulfillIntent, CanFulfillIntentValues,
28+
CanFulfillSlot, CanFulfillSlotValues,
29+
CanUnderstandSlotValues)
30+
from ask_sdk_model.interfaces.display import PlainText, RichText, TextContent
31+
from ask_sdk_model.interfaces.videoapp import (LaunchDirective, Metadata,
32+
VideoItem)
33+
from ask_sdk_model.response import Response
34+
from ask_sdk_model.ui import (Reprompt, SsmlOutputSpeech, output_speech,
35+
reprompt, ssml_output_speech)
2936
from ask_sdk_model.ui.play_behavior import PlayBehavior
3037

31-
from ask_sdk_core.response_helper import (
32-
ResponseFactory, get_text_content, get_plain_text_content,
33-
get_rich_text_content, PLAIN_TEXT_TYPE, RICH_TEXT_TYPE)
34-
3538

3639
class TestResponseFactory(unittest.TestCase):
3740
def setUp(self):
@@ -118,6 +121,25 @@ def test_add_two_directives(self):
118121
"The add_directive method of ResponseFactory fails to add "
119122
"multiple directives")
120123

124+
def test_add_reprompt_directive(self):
125+
response_factory = self.response_factory.add_directive_to_reprompt(directive=None)
126+
127+
assert len(response_factory.response.reprompt.directives) == 1, (
128+
"The add_directive_to_reprompt method of ResponseFactory fails "
129+
"to add directive"
130+
)
131+
132+
def test_response_with_reprompt_directive(self):
133+
expected_response = Response(
134+
output_speech=SsmlOutputSpeech(ssml="<speak>Hello World</speak>"),
135+
reprompt=Reprompt(directives=['Alexa.Presentation.APLA.RenderDocument']),
136+
should_end_session=False)
137+
138+
response_factory = self.response_factory.set_should_end_session(True).add_directive_to_reprompt(
139+
directive='Alexa.Presentation.APLA.RenderDocument').speak('Hello World')
140+
assert response_factory.response == expected_response, (
141+
"The add_directive_to_reprompt method of ResponseFactory fails to add directive")
142+
121143
def test_add_video_app_launch_directive(self):
122144
directive = LaunchDirective(video_item=VideoItem(
123145
source=None, metadata=Metadata(title=None, subtitle=None)))

tox.ini

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@ commands =
2929
python -m pip install --upgrade pip
3030
python -m pip install --upgrade wheel
3131
py{36,37,38}: python -m pip install --upgrade mypy
32+
python -m pip install types-python-dateutil
33+
python -m pip install types-requests
34+
python -m pip install types-six
3235
{toxinidir}/scripts/ci/sdk_install
3336
{toxinidir}/scripts/ci/run_tests
3437
py{36,37,38}: mypy ask-sdk/ask_sdk
@@ -57,6 +60,9 @@ commands =
5760
python -m pip install --upgrade pip
5861
python -m pip install --upgrade wheel
5962
py{36,37,38}: python -m pip install --upgrade mypy
63+
python -m pip install types-python-dateutil
64+
python -m pip install types-requests
65+
python -m pip install types-six
6066
python {toxinidir}\scripts\ci\sdk_install
6167
python {toxinidir}\scripts\ci\run_tests
6268
mypy ask-sdk\ask_sdk

0 commit comments

Comments
 (0)