Skip to content

Commit 8a4f47c

Browse files
authored
Add canfullfill intent in response builder, corresponding models in docs (#42)
Fixes #29
1 parent ab3bbac commit 8a4f47c

File tree

6 files changed

+101
-1
lines changed

6 files changed

+101
-1
lines changed

README.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,8 @@ Preview
245245

246246
* `Alexa Presentation Language <https://developer.amazon.com/docs/alexa-presentation-language/apl-overview.html>`__
247247

248+
* `Name-free Interactions <https://developer.amazon.com/docs/custom-skills/understand-name-free-interaction-for-custom-skills.html>`_
249+
248250

249251
Got Feedback?
250252
-------------

ask-sdk-core/ask_sdk_core/response_helper.py

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
from typing import Union
2727
from ask_sdk_model import Directive
2828
from ask_sdk_model.ui import Card
29+
from ask_sdk_model.canfulfill import CanFulfillIntent
2930

3031

3132
PLAIN_TEXT_TYPE = "PlainText"
@@ -47,7 +48,8 @@ def __init__(self):
4748
"""
4849
self.response = Response(
4950
output_speech=None, card=None, reprompt=None,
50-
directives=None, should_end_session=None)
51+
directives=None, should_end_session=None,
52+
can_fulfill_intent=None)
5153

5254
def speak(self, speech):
5355
# type: (str) -> 'ResponseFactory'
@@ -136,6 +138,22 @@ def set_should_end_session(self, should_end_session):
136138
self.response.should_end_session = should_end_session
137139
return self
138140

141+
def set_can_fulfill_intent(self, can_fulfill_intent):
142+
# type: (CanFulfillIntent) -> 'ResponseFactory'
143+
"""Sets CanFulfill intent to the response.
144+
145+
For more information on CanFulfillIntent, check the name-free
146+
interaction doc here: https://developer.amazon.com/docs/custom-skills/understand-name-free-interaction-for-custom-skills.html
147+
148+
:param can_fulfill_intent: CanFulfill Intent sent back in response.
149+
:type can_fulfill_intent: CanFulfillIntent
150+
:return: response factory with partial response being built and
151+
access from self.response.
152+
:rtype: ResponseFactory
153+
"""
154+
self.response.can_fulfill_intent = can_fulfill_intent
155+
return self
156+
139157
def __trim_outputspeech(self, speech_output=None):
140158
# type: (Union[str, None]) -> str
141159
"""Trims the output speech if it already has the

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

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@
2323
from ask_sdk_model.interfaces.display import TextContent
2424
from ask_sdk_model.interfaces.display import PlainText
2525
from ask_sdk_model.interfaces.display import RichText
26+
from ask_sdk_model.canfulfill import (
27+
CanFulfillIntent, CanFulfillIntentValues, CanFulfillSlot,
28+
CanFulfillSlotValues, CanUnderstandSlotValues)
2629

2730
from ask_sdk_core.response_helper import (
2831
ResponseFactory, get_text_content, get_plain_text_content,
@@ -131,6 +134,23 @@ def test_trim_outputspeech(self):
131134
speech=speech_output4).response.output_speech.ssml == "<speak>Hello World</speak>", (
132135
"The trim_outputspeech method fails to trim the outputspeech")
133136

137+
def test_set_can_fulfill_intent(self):
138+
intent = CanFulfillIntent(
139+
can_fulfill=CanFulfillIntentValues.MAYBE,
140+
slots={
141+
"testSlot": CanFulfillSlot(
142+
can_understand=CanUnderstandSlotValues.YES,
143+
can_fulfill=CanFulfillSlotValues.YES
144+
)
145+
}
146+
)
147+
response_factory = self.response_factory.set_can_fulfill_intent(
148+
can_fulfill_intent=intent)
149+
150+
assert response_factory.response.can_fulfill_intent == intent, (
151+
"The set_can_fulfill_intent method of ResponseFactory fails to "
152+
"set can_fulfill_intent value")
153+
134154

135155
class TestTextHelper(unittest.TestCase):
136156
def test_build_primary_text_default(self):

docs/en/SDK_SUPPORTED_ALEXA_CAPABILITIES.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,3 +50,5 @@ Preview
5050
* `Connections <https://developer.amazon.com/blogs/alexa/post/7b332b32-893e-4cad-be07-a5877efcbbb4/skill-connections-preview-now-skills-can-work-together-to-help-customers-get-more-done>`__
5151

5252
* `Alexa Presentation Language <https://developer.amazon.com/docs/alexa-presentation-language/apl-overview.html>`__
53+
54+
* `Name-free Interactions <https://developer.amazon.com/docs/custom-skills/understand-name-free-interaction-for-custom-skills.html>`_
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
ask_sdk_model.canfulfill package
2+
================================
3+
4+
Submodules
5+
----------
6+
7+
.. note::
8+
9+
Canonical imports have been added in the ``__init__.py`` of the package.
10+
This helps in importing the class directly from the package, than
11+
through the module.
12+
13+
For eg: if ``package a`` has ``module b`` with
14+
``class C``, you can do ``from a import C`` instead of
15+
``from a.b import C``.
16+
17+
ask\_sdk\_model.canfulfill.can\_fulfill\_intent module
18+
------------------------------------------------------
19+
20+
.. automodule:: ask_sdk_model.canfulfill.can_fulfill_intent
21+
:members:
22+
:show-inheritance:
23+
24+
ask\_sdk\_model.canfulfill.can\_fulfill\_intent\_request module
25+
---------------------------------------------------------------
26+
27+
.. automodule:: ask_sdk_model.canfulfill.can_fulfill_intent_request
28+
:members:
29+
:show-inheritance:
30+
31+
ask\_sdk\_model.canfulfill.can\_fulfill\_intent\_values module
32+
--------------------------------------------------------------
33+
34+
.. automodule:: ask_sdk_model.canfulfill.can_fulfill_intent_values
35+
:members:
36+
:show-inheritance:
37+
38+
ask\_sdk\_model.canfulfill.can\_fulfill\_slot module
39+
----------------------------------------------------
40+
41+
.. automodule:: ask_sdk_model.canfulfill.can_fulfill_slot
42+
:members:
43+
:show-inheritance:
44+
45+
ask\_sdk\_model.canfulfill.can\_fulfill\_slot\_values module
46+
------------------------------------------------------------
47+
48+
.. automodule:: ask_sdk_model.canfulfill.can_fulfill_slot_values
49+
:members:
50+
:show-inheritance:
51+
52+
ask\_sdk\_model.canfulfill.can\_understand\_slot\_values module
53+
---------------------------------------------------------------
54+
55+
.. automodule:: ask_sdk_model.canfulfill.can_understand_slot_values
56+
:members:
57+
:show-inheritance:

docs/en/models/ask_sdk_model.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ Subpackages
1313
.. toctree::
1414
:maxdepth: 1
1515

16+
ask_sdk_model.canfulfill
1617
ask_sdk_model.dialog
1718
ask_sdk_model.events
1819
ask_sdk_model.interfaces

0 commit comments

Comments
 (0)