Skip to content
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
12 changes: 11 additions & 1 deletion src/luis-middleware.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ module.exports = {
middleware: {
receive: receive,
hereIntent: hereIntent,
hereAction: hereAction
hereAction: hereAction,
getEntity: getEntity,
}
};

Expand All @@ -20,6 +21,7 @@ function receive(options) {
}
var minThreshold = options.minThreshold || 0.1;
var captureThreshold = options.captureThreshold || 0.7;
var alwaysIncludeEntities = options.alwaysIncludeEntities || false;
return function (bot, message, next) {
// We will only process the text and either there's no topIntent
// or the score for the topIntent is below the captureThreshold.
Expand All @@ -32,6 +34,9 @@ function receive(options) {

var result = JSON.parse(body);

if (alwaysIncludeEntities) {
message.entities = result.entities || [];
}
if (result.topScoringIntent) {
// API v2.0
message.topIntent = result.topScoringIntent;
Expand Down Expand Up @@ -94,3 +99,8 @@ function hereAction(tests, message) {
}
return false;
}

function getEntity({ entities = [] }, ...types) {
const entity = entities.find(entity => types.includes(entity.type));
return entity && (entity.resolution.value || entity.resolution.values);
}