Giter Club home page Giter Club logo

Comments (8)

jkelvie avatar jkelvie commented on August 21, 2024 1

Hi @MnHung - just saying alexa.utter("do some work") as a first call to the emulator should do it. Have you tried that? It is equivalent to saying "ask skill to do some work".

from virtual-alexa.

jkelvie avatar jkelvie commented on August 21, 2024 1

from virtual-alexa.

MnHung avatar MnHung commented on August 21, 2024

Thank you @jkelvie , yes it works.
um... should I close it or something? I am new to github

from virtual-alexa.

ultradian avatar ultradian commented on August 21, 2024

I am probably missing something simple, but I am unable to get my LaunchRequest to trigger. I set up a very simple index.js:

"use strict";
const Alexa = require("alexa-sdk");

//=============================================================================
const APP_ID = "amzn1.ask.skill.[unique-value-here]";

const HELP_MESSAGE = "You can ask for help.";
const HELP_REPROMPT = "Ask for help.";
const STOP_MESSAGE = "Goodbye!";

exports.handler = (event, context) => {
    const alexa = Alexa.handler(event, context);
    alexa.appId = APP_ID;
    alexa.registerHandlers(handlers);
    alexa.execute();
};

const handlers = {
    "LaunchRequest" : function() {
        console.log("DEBUG: start LaunchRequest");
        this.attributes.speechOutput = "Welcome to the test program.";
        this.response.speak(this.attributes.speechOutput);
        this.emit(':responseReady');
    },
    "AMAZON.HelpIntent": function() {
        this.attributes.speechOutput = HELP_MESSAGE;
        this.attributes.repromptSpeech = HELP_REPROMPT;
        this.response.speak(this.attributes.speechOutput)
            .listen(this.attributes.repromptSpeech);
        this.emit(":responseReady");
    },
    "AMAZON.RepeatIntent": function() {
        this.response.speak(this.attributes.speechOutput)
            .listen(this.attributes.repromptSpeech);
        this.emit(":responseReady");
    },
    "AMAZON.CancelIntent": function() {
        this.emit("EndSession");
    },
    "AMAZON.StopIntent": function() {
        this.emit("EndSession");
    },
    "EndSession": function() {
        this.response.speak(STOP_MESSAGE);
        this.emit(":responseReady");
    },
    "Unhandled": function() {
        this.attributes.speechOutput = "No intent match.";
        this.attributes.repromptSpeech = "Try again";
        this.response.speak(this.attributes.speechOutput)
            .listen(this.attributes.repromptSpeech);
        this.emit(":responseReady");
    },
};

for testing using Jest with this test file:

const vax = require("virtual-alexa");
const alexa = vax.VirtualAlexa.Builder()
    .handler("../src/index.handler") // Lambda function file and name
    .interactionModelFile("./model.json")
    .applicationID("amzn1.ask.skill.[unique-value-here]")
    .create();

test("Launches successfully", (done) => {
    alexa.utter("get started").then((payload) => {
        expect(payload.response.outputSpeech.ssml).toContain("Welcome");
        return alexa.utter("");
    });
});

And it triggers the CancelIntent instead of LaunchRequest. Specifically:

  console.warn node_modules/virtual-alexa/lib/src/SkillInteractor.js:33
    No intentName matches utterance: get started. Using fallback utterance: cancel

What am I doing wrong? If you need the code, I put it up at https://github.com/ultradian/AlexaTesting
For package.json I used:

{
  "name": "unitTest",
  "version": "1.0.0",
  "private": true,
  "dependencies": {
    "alexa-sdk": "^1.0.22",
    "i18next": "^10.2.1",
    "i18next-sprintf-postprocessor": "^0.2.2"
  },
  "devDependencies": {
      "jest": "^22.3.0",
      "pack-zip": "^0.2.2",
      "virtual-alexa": "^0.4.2"
  },
  "scripts": {
    "build-aws-resource": "pack-zip",
    "test": "jest"
 }
}

from virtual-alexa.

jkelvie avatar jkelvie commented on August 21, 2024

Hi @ultradian - you want to call alexa.launch instead of utter to get a launch request. See here:
https://github.com/bespoken/giftionary/blob/master/test/index.test.js#L48

Let me know if that works for you! Best, John

from virtual-alexa.

ultradian avatar ultradian commented on August 21, 2024

Thanks, John. That works great. I didn't go deep enough into the code... Is there a doc page besides https://github.com/bespoken/virtual-alexa/blob/master/README.md? The info at http://docs.bespoken.io/ only describes bstAlexa.

from virtual-alexa.

jkelvie avatar jkelvie commented on August 21, 2024

Yes, take a look here:
https://bespoken.github.io/virtual-alexa/api/

from virtual-alexa.

ultradian avatar ultradian commented on August 21, 2024

Thanks for the link. I'll put it in the Github. A further question that I don't see documented (but probably is there somewhere)... is there a way to trigger the 'Unhandled' intent? I think there is some config file I'm missing because it says it is using a 'fallback utterance' which defaults to cancel.

from virtual-alexa.

Related Issues (20)

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.