1

我试图让我的文件管理更容易一些,并将每个意图放在自己的文件中。我如何包含它,以便我的 index.js 使用该意图。继承人和我尝试过的示例。

var alexa = require('alexa-app');
var app = new alexa.app();
var GetLunchSuggestions = require('./Intents/GetLunchSuggestions');
app.launch(function(request, response) {
response.say('Welcome I am built to handle your lunch requests');
response.shouldEndSession(false);
});

app.use(GetLunchSuggestions);

// Connect to lambda
exports.handler = app.lambda();
if (process.argv.length === 3 && process.argv[2] === 'schema') {
console.log(app.schema());
console.log(app.utterances());
}

我想在这个文件中使用午餐建议意图。你怎么做到这一点?

4

1 回答 1

0

在你的./Intents/GetLunchSuggestions.js

module.exports = {
  'AMAZON.HelpIntent': function () {
      const speechOutput = 'I'm a handler from different file.';

      this.response.speak(speechOutput).shouldEndSession(isLaunched);
      this.emit(':responseReady');
   }
}

然后在你的index.js

const GetLaunchSuggestions = require('./Intents/GetLunchSuggestions');

exports.handler = function (event, context, callback) {
  const alexa = Alexa.handler(event, context, callback);
  alexa.appId = APP_ID; // APP_ID is your skill id which can be found in the Amazon developer console where you create the skill.
  alexa.registerHandlers(
    handlers, // this where some of your handlers being defined. You can remove this if it was not define it your code.
    GetLaunchSuggestions // this is your handler from different file.
  );
  alexa.execute();
};
于 2018-04-20T04:17:41.600 回答