alexa-js / alexa-app

A framework for Alexa (Amazon Echo) apps using Node.js
https://www.youtube.com/watch?v=pzM4jv7k7Rg
MIT License
1.03k stars 212 forks source link

Jump from launch to an initial intent #102

Closed nikolasleblanc closed 5 years ago

nikolasleblanc commented 7 years ago

If at the conclusion of an intent I would like to return to the initial intent, how would I do that?

app.launch(function(request,response) {
  // jump to InitIntent
});
app.intent('InitIntent', function(request, response) {
  // some intent stuff
});
dblock commented 7 years ago

Maybe ask this on an Alexa forum? (add link)

nikolasleblanc commented 7 years ago

It can definitely be done, just wondering if it was part of the alexa-app api, see https://github.com/alexa/alexa-skills-kit-sdk-for-nodejs:

var handlers = {
    'LaunchRequest': function () {
        this.emit('HelloWorldIntent');
    },

    'HelloWorldIntent': function () {
        this.emit(':tell', 'Hello World!');
    }
 };
dblock commented 7 years ago

@nikolasleblanc Would welcome a new feature that does it!

nikolasleblanc commented 7 years ago

Cool @dblock. I'm pretty new to this, but really enjoying it. Will see what I can do!

ajcrites commented 7 years ago

You can create a function that is used by both the initial intent and the launch intent. I think that it would currently be very difficult to write code that would trigger a handler (launch or otherwise) from another handler.

app.launch((req, res) => {
  // do launch things
  return initialBehavior(req, res);
});
app.intent("HelloWorldIntent", (req, res) => {
  return initialBehavior(req, res);
});
function initialBehavior(req, res) {
  // do things you would do for both here
}
ajcrites commented 7 years ago

I like the idea of being able to trigger other handlers from within a handler (launch as well as other intents). I'll try to hack on this when I get a chance to.

kobim commented 5 years ago

Resolved via #374