Skip to content

Commit

Permalink
Now logging errors
Browse files Browse the repository at this point in the history
  • Loading branch information
Gnzlt committed Apr 4, 2017
1 parent 68cf04b commit 3926073
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,21 @@ exports.handler = function (event, context) {
var handlers = {
'LaunchRequest': function () {
var self = this;
alexaSessionId = self.event.session.sessionId.split('amzn1.echo-api.session.').pop();
setAlexaSessionId(self.event.session.sessionId);
apiAi.eventRequest({name: 'WELCOME'}, {sessionId: alexaSessionId})
.on('response', function (response) {
var speech = response.result.fulfillment.speech;
self.emit(':ask', speech, speech);
})
.on('error', function (error) {
console.error(error.message);
self.emit(':tell', error);
})
.end();
},
'ApiIntent': function () {
var self = this;
setAlexaSessionId(self.event.session.sessionId);
var text = self.event.request.intent.slots.Text.value;
if (text) {
apiAi.textRequest(text, {sessionId: alexaSessionId})
Expand All @@ -44,6 +46,7 @@ var handlers = {
}
})
.on('error', function (error) {
console.error(error.message);
self.emit(':tell', error.message);
})
.end();
Expand All @@ -61,6 +64,7 @@ var handlers = {
self.emit(':tell', response.result.fulfillment.speech);
})
.on('error', function (error) {
console.error(error.message);
self.emit(':tell', error.message);
})
.end();
Expand All @@ -73,8 +77,13 @@ var handlers = {
self.emit(':ask', speech, speech);
})
.on('error', function (error) {
console.error(error.message);
self.emit(':tell', error.message);
})
.end();
}
};

function setAlexaSessionId(sessionId) {
alexaSessionId = sessionId.split('amzn1.echo-api.session.').pop();
}

0 comments on commit 3926073

Please sign in to comment.