Giter Site home page Giter Site logo

alexa-tester's Introduction

Alexa Tester

How To Use

Run against an Alexa Skill by specifying the file path of the skill model, skill endpint, and the file path of function mapping:

$ node index.js endpoint_url skill_model_path function_mapping_path

An example model and function is provided in the repository. You can run this against the Make Connections skill with the following command:

$ node index.js http://localhost:8060/alexa models/example-complex.json examples/correlations-game/helpers/answer-functions.js

Skill Model

The skill model that needs to be passed to the tester is not the same as the Interaction Model defined in the Alexa Developer Console. Models are defined in a tree structure. Below is an example of a simple model where a 'No' intent after launch should end the skill session. Alexa Tester will validate that this is correct.

{
    "requestType": "LaunchRequest",
    "children": [
        {
            "requestType": "IntentRequest",
            "name": "AMAZON.NoIntent",
            "shouldEndSession": true            
        }
    ]
}

Nodes in the tree have the following attributes:

  • requestType: "LaunchRequest" or "IntentRequest"
  • (optional) name: a string. This is required for intent requests
  • (optional) children: an array of request nodes
  • (optional) slots: a slot object (see below)
  • (optional) shouldEndSession: true or false
  • (optional) repeatRequest: an integer. Repeats the request n number of times

Slots follow a similiar format to those sent in requests to the Alexa Skill endpoint. Each slot is defined as an attribute of the slots object. Each slot needs a name and a value. Slot values can be literal, for example you can test what happens when you pass a string or number. However, Alexa Tester is powerful in that it supports functions for values. These functions must be defined by the developer and they take, as input, the response from the previous request. By using this information, developers can direct conversations down specific logical paths, for example given a quiz question you can test both the correct and incorrect answer path.

"slots": {
    "Answer": {
        "name": "Answer",
        "value": {
            "function": "correctAnswer"
        }
    }
}

To make use of functions with Alexa Tester you must define a function mapping in a separate file

const functionMapping = {
    "correctAnswer": correctAnswer,
    "incorrectAnswer": incorrectAnswer
};

function correctAnswer(outputSpeech) {
    ...
}

function incorrectAnswer(outputSpeech) {
    ...
}

module.exports = functionMapping;

Understanding Results

Alexa Tester works by calculating all the possible paths from the provided tree and testing each of these against the given endpoint. If the path completes and the final request response matches the expected result, the program will return 'Success'.

If the final request response is not as expected, it will return one of the following messages:

  • ERROR: Session Did Not End As Expected
  • ERROR: Session Unexpectedly Ended

alexa-tester's People

Contributors

jdevt avatar lily2point0 avatar snyk-bot avatar wheresrhys avatar

Watchers

 avatar  avatar  avatar  avatar

Forkers

isabella232

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.