From 80a8ec136717294bdf193fa084be95adc690116c Mon Sep 17 00:00:00 2001 From: Jelle Scholtalbers Date: Fri, 25 Nov 2016 13:21:00 +0100 Subject: [PATCH 1/2] basic fix response handling --- index.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/index.js b/index.js index 1020cdb..6405cb8 100644 --- a/index.js +++ b/index.js @@ -22,11 +22,13 @@ function Witbot (witToken) { // only consider the 1st outcome if (res.outcomes && res.outcomes.length > 0) { var outcome = res.outcomes[0] - var intent = outcome.intent + var intent = outcome.entities.intent[0].value + var confidence = outcome.entities.intent[0].confidence args.push(outcome) if (intents._intents[intent]) { + console.log('"' + intent + '" - intent found') intents._intents[intent].forEach(function (registration) { - if (!matched && outcome.confidence >= registration.confidence) { + if (!matched && confidence >= registration.confidence) { matched = true registration.fn.apply(undefined, args) } From 5b48b4e81662c9ce9e54f225a3e98eb1bf0154a0 Mon Sep 17 00:00:00 2001 From: Jelle Scholtalbers Date: Fri, 25 Nov 2016 13:34:35 +0100 Subject: [PATCH 2/2] handle undefined --- index.js | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/index.js b/index.js index 6405cb8..1ef70e6 100644 --- a/index.js +++ b/index.js @@ -22,17 +22,19 @@ function Witbot (witToken) { // only consider the 1st outcome if (res.outcomes && res.outcomes.length > 0) { var outcome = res.outcomes[0] - var intent = outcome.entities.intent[0].value - var confidence = outcome.entities.intent[0].confidence - args.push(outcome) - if (intents._intents[intent]) { - console.log('"' + intent + '" - intent found') - intents._intents[intent].forEach(function (registration) { - if (!matched && confidence >= registration.confidence) { - matched = true - registration.fn.apply(undefined, args) - } - }) + if(typeof outcome.entities.intent !== 'undefined'){ + var intent = outcome.entities.intent[0].value + var confidence = outcome.entities.intent[0].confidence + args.push(outcome) + if (intents._intents[intent]) { + console.log('"' + intent + '" - intent found') + intents._intents[intent].forEach(function (registration) { + if (!matched && confidence >= registration.confidence) { + matched = true + registration.fn.apply(undefined, args) + } + }) + } } else if (intents._any) { matched = true intents._any.apply(undefined, args)