Skip to content

Commit

Permalink
Add canfullfill intent in response builder, corresponding models in d…
Browse files Browse the repository at this point in the history
…ocs (#42)

Fixes #29
  • Loading branch information
nikhilym committed Nov 5, 2018
1 parent ab3bbac commit 8a4f47c
Show file tree
Hide file tree
Showing 6 changed files with 101 additions and 1 deletion.
2 changes: 2 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,8 @@ Preview

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

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


Got Feedback?
-------------
Expand Down
20 changes: 19 additions & 1 deletion ask-sdk-core/ask_sdk_core/response_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
from typing import Union
from ask_sdk_model import Directive
from ask_sdk_model.ui import Card
from ask_sdk_model.canfulfill import CanFulfillIntent


PLAIN_TEXT_TYPE = "PlainText"
Expand All @@ -47,7 +48,8 @@ def __init__(self):
"""
self.response = Response(
output_speech=None, card=None, reprompt=None,
directives=None, should_end_session=None)
directives=None, should_end_session=None,
can_fulfill_intent=None)

def speak(self, speech):
# type: (str) -> 'ResponseFactory'
Expand Down Expand Up @@ -136,6 +138,22 @@ def set_should_end_session(self, should_end_session):
self.response.should_end_session = should_end_session
return self

def set_can_fulfill_intent(self, can_fulfill_intent):
# type: (CanFulfillIntent) -> 'ResponseFactory'
"""Sets CanFulfill intent to the response.
For more information on CanFulfillIntent, check the name-free
interaction doc here: https://developer.amazon.com/docs/custom-skills/understand-name-free-interaction-for-custom-skills.html
:param can_fulfill_intent: CanFulfill Intent sent back in response.
:type can_fulfill_intent: CanFulfillIntent
:return: response factory with partial response being built and
access from self.response.
:rtype: ResponseFactory
"""
self.response.can_fulfill_intent = can_fulfill_intent
return self

def __trim_outputspeech(self, speech_output=None):
# type: (Union[str, None]) -> str
"""Trims the output speech if it already has the
Expand Down
20 changes: 20 additions & 0 deletions ask-sdk-core/tests/unit/test_response_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@
from ask_sdk_model.interfaces.display import TextContent
from ask_sdk_model.interfaces.display import PlainText
from ask_sdk_model.interfaces.display import RichText
from ask_sdk_model.canfulfill import (
CanFulfillIntent, CanFulfillIntentValues, CanFulfillSlot,
CanFulfillSlotValues, CanUnderstandSlotValues)

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

def test_set_can_fulfill_intent(self):
intent = CanFulfillIntent(
can_fulfill=CanFulfillIntentValues.MAYBE,
slots={
"testSlot": CanFulfillSlot(
can_understand=CanUnderstandSlotValues.YES,
can_fulfill=CanFulfillSlotValues.YES
)
}
)
response_factory = self.response_factory.set_can_fulfill_intent(
can_fulfill_intent=intent)

assert response_factory.response.can_fulfill_intent == intent, (
"The set_can_fulfill_intent method of ResponseFactory fails to "
"set can_fulfill_intent value")


class TestTextHelper(unittest.TestCase):
def test_build_primary_text_default(self):
Expand Down
2 changes: 2 additions & 0 deletions docs/en/SDK_SUPPORTED_ALEXA_CAPABILITIES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -50,3 +50,5 @@ Preview
* `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>`__

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

* `Name-free Interactions <https://developer.amazon.com/docs/custom-skills/understand-name-free-interaction-for-custom-skills.html>`_
57 changes: 57 additions & 0 deletions docs/en/models/ask_sdk_model.canfulfill.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
ask_sdk_model.canfulfill package
================================

Submodules
----------

.. note::

Canonical imports have been added in the ``__init__.py`` of the package.
This helps in importing the class directly from the package, than
through the module.

For eg: if ``package a`` has ``module b`` with
``class C``, you can do ``from a import C`` instead of
``from a.b import C``.

ask\_sdk\_model.canfulfill.can\_fulfill\_intent module
------------------------------------------------------

.. automodule:: ask_sdk_model.canfulfill.can_fulfill_intent
:members:
:show-inheritance:

ask\_sdk\_model.canfulfill.can\_fulfill\_intent\_request module
---------------------------------------------------------------

.. automodule:: ask_sdk_model.canfulfill.can_fulfill_intent_request
:members:
:show-inheritance:

ask\_sdk\_model.canfulfill.can\_fulfill\_intent\_values module
--------------------------------------------------------------

.. automodule:: ask_sdk_model.canfulfill.can_fulfill_intent_values
:members:
:show-inheritance:

ask\_sdk\_model.canfulfill.can\_fulfill\_slot module
----------------------------------------------------

.. automodule:: ask_sdk_model.canfulfill.can_fulfill_slot
:members:
:show-inheritance:

ask\_sdk\_model.canfulfill.can\_fulfill\_slot\_values module
------------------------------------------------------------

.. automodule:: ask_sdk_model.canfulfill.can_fulfill_slot_values
:members:
:show-inheritance:

ask\_sdk\_model.canfulfill.can\_understand\_slot\_values module
---------------------------------------------------------------

.. automodule:: ask_sdk_model.canfulfill.can_understand_slot_values
:members:
:show-inheritance:
1 change: 1 addition & 0 deletions docs/en/models/ask_sdk_model.rst
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ Subpackages
.. toctree::
:maxdepth: 1

ask_sdk_model.canfulfill
ask_sdk_model.dialog
ask_sdk_model.events
ask_sdk_model.interfaces
Expand Down

0 comments on commit 8a4f47c

Please sign in to comment.