Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

basic fix response handling #4

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 13 additions & 9 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +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.intent
args.push(outcome)
if (intents._intents[intent]) {
intents._intents[intent].forEach(function (registration) {
if (!matched && outcome.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)
Expand Down