Skip to content

Commit

Permalink
reply in transition (#150)
Browse files Browse the repository at this point in the history
* reply in transition

- Now users can use voxa2 style transitions with `reply`

Also:
- removed unused `ask-sdk` and `ask-sdk-core` dependencies, we only need
`ask-sdk-model`
- started using prettier
- removed the Rendering system support for random, this is now handled
in the directives

* Lint

* Ignoring typedoc errors

* Working on the Docs

* Adding more documentation about the transitions

* More work on the docs

* More docs
  • Loading branch information
armonge committed Sep 5, 2018
1 parent 9db4d69 commit 8ef4fc9
Show file tree
Hide file tree
Showing 27 changed files with 1,250 additions and 975 deletions.
2 changes: 1 addition & 1 deletion docs/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#

# You can set these variables from the command line.
SPHINXOPTS = -n -a
SPHINXOPTS = -n -a --ignore _build
SPHINXBUILD = sphinx-build
SPHINXPROJ = voxa
SOURCEDIR = .
Expand Down
9 changes: 9 additions & 0 deletions docs/alexa-apis.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ Alexa APIs
==============================================
Amazon has integrated several APIs so users can leverage the Alexa's configurations, device's and user's information.


.. _alexa-customer-contact:

--------------------------------------
Customer Contact Information Reference
--------------------------------------
Expand Down Expand Up @@ -99,6 +102,8 @@ To send a card requesting user the permission to access their information, you c
},
.. _alexa-device-address:

------------------------------------
Device Address Information Reference
------------------------------------
Expand Down Expand Up @@ -172,6 +177,8 @@ To send a card requesting user the permission to access the device address info,
},
.. _alexa-device-settings:

-------------------------
Device Settings Reference
-------------------------
Expand Down Expand Up @@ -229,6 +236,7 @@ With Voxa, you can ask for the full device's address like this:
You don't need to request to the user the permission to access the device settings info.

.. _alexa-isp:

----------------------------
In-Skill Purchases Reference
Expand Down Expand Up @@ -312,6 +320,7 @@ When users accept or refuse to buy/cancel an item, Alexa sends a Connections.Res
"token": "string"
}
.. _alexa-lists:

----------------------------------------
Alexa Shopping and To-Do Lists Reference
Expand Down
26 changes: 15 additions & 11 deletions docs/alexa-event.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,24 +7,28 @@ The ``AlexaEvent`` Object

The ``alexaEvent`` object contains all the information from the Voxa event, it's an object kept for the entire lifecycle of the state machine transitions and as such is a perfect place for middleware to put information that should be available on every request.

.. js:attribute:: AlexaEvent.intent

In Voxa the alexaEvent object makes ``intent.slots`` available through ``intent.params`` after aplying a simple transformation so ``{ slots: [{ name: 'Dish', value: 'Fried Chicken' }] }`` becomes ``{ Dish: 'Fried Chicken' }``, in other platforms it does it best to make the intent params for each platform also available on ``intent.params``
.. js:attribute:: AlexaEvent.token

.. js:attribute:: AlexaEvent.user
A convenience getter to obtain the request's token, specially when using the ``Display.ElementSelected``

A convenience getter to obtain the user from ``session.user`` or ``context.System.user`` in alexa, and ``conv.user.id`` in dialogflow. In other platforms it's also available, you can always count on the ``alexaEvent.user.userId`` being available. If there's an ``accessToken`` it will also be available through ``alexaEvent.user.accessToken``
.. js:attribute:: AlexaEvent.alexa.customerContact

.. js:attribute:: AlexaEvent.token

A convenience getter to obtain the request's token, specially when using the ``Display.ElementSelected``
When a customer enables your Alexa skill, your skill can request the customer's permission to the their contact information, see :ref:`alexa-customer-contact`.

.. js:attribute:: AlexaEvent.alexa.deviceAddress

When a customer enables your Alexa skill, your skill can obtain the customer's permission to use address data associated with the customer's Alexa device, see :ref:`alexa-device-address`.

.. js:attribute:: AlexaEvent.alexa.deviceSettings

.. js:attribute:: AlexaEvent.requestToIntent
Alexa customers can set their timezone, distance measuring unit, and temperature measurement unit in the Alexa app, see :ref:`alexa-device-settings`.

An array of requests to be converted to intents to be used as ``app.toIntent`` in the app code.
.. js:attribute:: AlexaEvent.alexa.isp

.. js:function:: AlexaEvent.supportedInterfaces()
The `in-skill purchasing <https://developer.amazon.com/docs/in-skill-purchase/isp-overview.html>`_ feature enables you to sell premium content such as game features and interactive stories for use in skills with a custom interaction model, see :ref:`alexa-isp`.

Array of supported interfaces
.. js:attribute:: AlexaEvent.alexa.lists

:returns Array: A string array of the platform's supported interfaces
Alexa customers have access to two default lists: Alexa to-do and Alexa shopping. In addition, Alexa customer can create and manage `custom lists <https://developer.amazon.com/docs/custom-skills/access-the-alexa-shopping-and-to-do-lists.html>`_ in a skill that supports that, see :ref:`alexa-lists`.
6 changes: 2 additions & 4 deletions docs/dialogflow-directives.rst
Original file line number Diff line number Diff line change
Expand Up @@ -173,11 +173,9 @@ Avoid repeating the information presented in the card in the chat bubble at all
return {
dialogFlowBasicCard: {
text: `This is a basic card. Text in a basic card can include "quotes" and
most other unicode characters including emoji 📱. Basic cards also support
most other unicode characters including emoji. Basic cards also support
some markdown formatting like *emphasis* or _italics_, **strong** or
__bold__, and ***bold itallic*** or ___strong emphasis___ as well as other
things like line \nbreaks`, // Note the two spaces before '\n' required for
// a line break to be rendered in the card.
__bold__, and ***bold itallic*** or ___strong emphasis___ `,
subtitle: 'This is a subtitle',
title: 'Title: this is a title',
buttons: new Button({
Expand Down
15 changes: 1 addition & 14 deletions docs/dialogflow-event.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,7 @@ The ``DialogFlowEvent`` Object

The ``dialogFlowEvent`` object contains all the information from the Voxa event, it's an object kept for the entire lifecycle of the state machine transitions and as such is a perfect place for middleware to put information that should be available on every request.

.. js:attribute:: DialogFlowEvent.conv
.. js:attribute:: DialogFlowEvent.google.conv

The conversation instance that contains the raw input sent by Dialogflow

.. js:attribute:: DialogFlowEvent.intent

In Voxa the dialogFlowEvent object makes ``intent.slots`` available through ``intent.params`` after aplying a simple transformation so ``{ slots: [{ name: 'Dish', value: 'Fried Chicken' }] }`` becomes ``{ Dish: 'Fried Chicken' }``, in other platforms it does it best to make the intent params for each platform also available on ``intent.params``

.. js:attribute:: DialogFlowEvent.user

A convenience getter to obtain the user from ``session.user`` or ``context.System.user`` in alexa, and ``conv.user.id`` in dialogflow. In other platforms it's also available, you can always count on the ``dialogFlowEvent.user.userId`` being available. If there's an ``accessToken`` it will also be available through ``dialogFlowEvent.user.accessToken``

.. js:function:: DialogFlowEvent.supportedInterfaces()

Array of supported interfaces

:returns Array: A string array of the platform's supported interfaces
2 changes: 2 additions & 0 deletions docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,8 @@ Links

new-alexa-user
mvc-description
voxa-app
voxa-platform
models
views-and-variables
controllers
Expand Down
24 changes: 12 additions & 12 deletions docs/plugins.rst
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@ After instantiating a StateMachineSkill you can register plugins on it. Built in
.. code-block:: javascript
'use strict';
const Voxa = require('voxa');
const { VoxaApp, plugins } = require('voxa');
const Model = require('./model');
const views = require('./views'):
const variables = require('./variables');
const app = new Voxa({ Model, variables, views });
const app = new VoxaApp({ Model, variables, views });
Voxa.plugins.replaceIntent(app);
plugins.replaceIntent(app);
State Flow plugin
Expand All @@ -30,9 +30,9 @@ Stores the state transitions for every alexa event in an array.

.. js:function:: stateFlow(app)

State Flow attaches callbacks to :js:func:`~Voxa.onRequestStarted`, :js:func:`~Voxa.onBeforeStateChanged` and :js:func:`~Voxa.onBeforeReplySent` to track state transitions in a ``voxaEvent.flow`` array
State Flow attaches callbacks to :js:func:`~VoxaApp.onRequestStarted`, :js:func:`~VoxaApp.onBeforeStateChanged` and :js:func:`~VoxaApp.onBeforeReplySent` to track state transitions in a ``voxaEvent.flow`` array

:param Voxa app: The app object
:param VoxaApp app: The app object



Expand All @@ -58,9 +58,9 @@ It allows you to rename an intent name based on a regular expression. By default

.. js:function:: replaceIntent(app, [config])

Replace Intent plugin uses :js:func:`~Voxa.onIntentRequest` to modify the incoming request intent name
Replace Intent plugin uses :js:func:`~VoxaApp.onIntentRequest` to modify the incoming request intent name

:param Voxa app: The stateMachineSkill
:param VoxaApp app: The stateMachineSkill
:param config: An object with the ``regex`` to look for and the ``replace`` value.


Expand Down Expand Up @@ -106,9 +106,9 @@ Params

.. js:function:: cloudwatch(app, cloudwatch, [eventMetric])

CloudWatch plugin uses :js:func:`Voxa.onError`, :js:func:`Voxa.onStateMachineError` and :js:func:`Voxa.onBeforeReplySent` to log metrics
CloudWatch plugin uses :js:func:`VoxaApp.onError` and :js:func:`VoxaApp.onBeforeReplySent` to log metrics

:param Voxa app: The stateMachineSkill
:param VoxaApp app: The stateMachineSkill
:param cloudwatch: A new `AWS.CloudWatch <http://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/CloudWatch.html#constructor-property/>`_ object.
:param putMetricDataParams: Params for `putMetricData <http://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/CloudWatch.html#putMetricData-property>`_

Expand Down Expand Up @@ -143,7 +143,7 @@ Params

Autoload plugin uses ``app.onSessionStarted`` to load data the first time the user opens a skill

:param Voxa app: The stateMachineSkill.
:param VoxaApp app: The stateMachineSkill.
:param config: An object with an ``adapter`` key with a `get` Promise method in which you can handle your database access to fetch information from any resource.


Expand All @@ -152,6 +152,6 @@ Usage

.. code-block:: javascript
const app = new Voxa({ Model, variables, views });
const app = new VoxaApp({ Model, variables, views });
Voxa.plugins.autoLoad(app, { adapter });
plugins.autoLoad(app, { adapter });
46 changes: 32 additions & 14 deletions docs/transition.rst
Original file line number Diff line number Diff line change
Expand Up @@ -18,29 +18,47 @@ The ``to`` key should be the name of a state in your state machine, when present
``directives``
--------------

Directives are used passed directly to the alexa response, the format is described in `the alexa documentation <https://developer.amazon.com/public/solutions/alexa/alexa-voice-service/reference/interaction-model#interfaces>`_
Directives is an array of directive objects that implement the ``IDirective`` interface, they can make modifications to the reply object directly

.. code-block:: javascript
const { PlayAudio } = require('voxa').alexa;
return {
directives: [{
type: 'AudioPlayer.Play',
playBehavior: 'REPLACE_ALL',
audioItem: {
stream: {
token: lesson.id,
url: lesson.Url,
offsetInMilliseconds: 0,
}
}
}],
directives: [new PlayAudio(url, token)],
};
``flow``
--------

The ``flow`` key can take one of three values:

``continue``:
This is the default value if the flow key is not present, it merely continues the state machine execution with an internal transition, it keeps building the response until a controller returns a ``yield`` or a ``terminate`` flow.

``yield``:
This stops the state machine and returns the current response to the user without terminating the session.

``terminate``:
This stops the state machine and returns the current response to the user, it closes the session.


``say``
-------

Used to render a view and add the result to the response


``reprompt``
------------

Used to render a view and add the result to the response as a reprompt


``reply``
---------

The ``reply`` key can take 2 forms, a simple string pointing to one of your views or a :ref:`Reply <voxa-reply>` object.

.. code-block:: javascript
return { reply: 'LaunchIntent.OpenResponse' };
Expand Down

0 comments on commit 8ef4fc9

Please sign in to comment.