diff --git a/src/luis-middleware.js b/src/luis-middleware.js index 39034b0..3dc255e 100644 --- a/src/luis-middleware.js +++ b/src/luis-middleware.js @@ -4,7 +4,8 @@ module.exports = { middleware: { receive: receive, hereIntent: hereIntent, - hereAction: hereAction + hereAction: hereAction, + getEntity: getEntity, } }; @@ -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. @@ -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; @@ -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); +} \ No newline at end of file