Stevenic / botkit-middleware-luis

Middleware for using http://luis.ai with Botkit-powered bots
MIT License
16 stars 10 forks source link

Add option to expose LUIS entities for use in questions #8

Open menachem-stratfs opened 4 years ago

menachem-stratfs commented 4 years ago

With the release of Botkit 4.8, bot developers now have access to the full message object inside of dialogs. This allows for the opportunity to use LUIS entities not just to trigger new dialogs, but also as a means of interpreting a user's response to a prompt.

For example:

    dialog.addQuestion('Enter a date', async (rawInput, convo, bot, message) => {
        const dateEntity = message.entities.find(entity => entity.type === 'builtin.datetimeV2.date');
        const date = new Date(dateEntity.resolution.value);
        doStuffWith(date);
        ...
}

The PR exposes an option alwaysIncludeEntities that, when true, will attach entities from the LUIS service to the message.

I've also added a helper function that finds an expected entity type. It can be used like this:

    dialog.addQuestion('Please enter the price', async (rawValue, convo, bot, message) => {
        const number = luis.middleware.getEntity(message, 'builtin.number', 'builtin.currency') || rawValue;
        doStuffWith(number);
        ...
}