我正在尝试让我的文件管理变得更容易一些,并将每个意图放在它自己的文件中。我如何将其包含进来,以便我的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());
}我想在这个文件中使用午餐建议。您如何做到这一点?
发布于 2018-04-20 12:17:42
在你的./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();
};https://stackoverflow.com/questions/49782969
复制相似问题