Alexa-App создает намерения в отдельных файлах, импортирует и использует их в index.js
Я пытаюсь немного облегчить управление файлами и сделать каждое намерение отдельным файлом. Как мне это включить, чтобы мой 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());
}
Я хочу использовать намерения ланча в этом файле. Как ты это делаешь?
1 ответ
В вашем ./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();
};