Skip to content

Commit

Permalink
Added context lifespan check
Browse files Browse the repository at this point in the history
  • Loading branch information
Gnzlt committed Apr 4, 2017
1 parent 3926073 commit 8dcde2c
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ var handlers = {
apiAi.textRequest(text, {sessionId: alexaSessionId})
.on('response', function (response) {
var speech = response.result.fulfillment.speech;
if (response.result.actionIncomplete) {
if (isResponseIncompleted(response)) {
self.emit(':ask', speech, speech);
} else {
self.emit(':tell', speech);
Expand Down Expand Up @@ -84,6 +84,19 @@ var handlers = {
}
};

function isResponseIncompleted(response) {
if (response.result.actionIncomplete) {
return true;
} else {
for (var i = 0; i < response.result.contexts.length; i++) {
if (response.result.contexts[i].lifespan > 1) {
return true;
}
}
return false;
}
}

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

0 comments on commit 8dcde2c

Please sign in to comment.