Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add utterance to alexa.launch() ? #24

Closed
MnHung opened this issue Jan 11, 2018 · 8 comments
Closed

Add utterance to alexa.launch() ? #24

MnHung opened this issue Jan 11, 2018 · 8 comments

Comments

@MnHung
Copy link

MnHung commented Jan 11, 2018

Hi all:

const launchResponse = await alexa.launch();

can simulate a user say "Alexa, open {invocation-name}"

Is it possible to add utterance support to launch() , maybe it is like

await alexa.launch("do some work");

to simulate a user say "Alexa, ask {invocation-name} to do some work" ?

and thank you all, you did a great job.

@jkelvie
Copy link
Member

jkelvie commented Jan 11, 2018

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".

@MnHung
Copy link
Author

MnHung commented Jan 18, 2018

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

@jkelvie
Copy link
Member

jkelvie commented Jan 18, 2018 via email

@MnHung MnHung closed this as completed Jan 19, 2018
@ultradian
Copy link

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"
 }
}

@jkelvie
Copy link
Member

jkelvie commented Feb 21, 2018

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

@ultradian
Copy link

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.

@jkelvie
Copy link
Member

jkelvie commented Feb 22, 2018

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

@ultradian
Copy link

ultradian commented Feb 24, 2018

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants