Forward Dialog utterance and parameters when doing a LUIS Intent redirection
See original GitHub issueI have implemented the onDefault
action to handle all the utterances that are not matched elsewhere.
I have added a grammar spell checker, so that I could fix typos by the user like
quute by adele
that is not understood by LUIS, by a simple grammar can turn this in the right one that is quote by adele
.
At this point, I’m going to suggest the user if the correction is the right one prompting it:
var msg = "You typed " + result.text + "\nDid you mean \""+result.correction+"\"?"
BotBuilder.Prompts.text(session, msg );
and as soon as the user type yes
I would like to reenter the dialog with this query, but I do not see a way to do this:
function (session, results)
{
var response=results.response;
if ( response == 'yes' ) {
//@TODO redo query
session.beginDialog('/');
}
else {
session.send( self.getLocalizedString('RESPONSE_DISCARD','RESPONSE_DISCARD') );
}
}
For my understanding I can define redirects like
.on('DeleteTask', '/deleteTask')
Using the Session userData
object I can add parameters like
session.userData.correct = {
text : result.text,
correct : result.correction
};
in a session, and that’s ok, but how to forward the user utterance as well properly in order to force to the right redirect i.e. force LUIS Dialog to the right route programmatically or to express this differently:
Given an utterance programmatically, is in the botframework api a way to get the matching Intent
objects back from LUIS dialog model?
Here is the code callbacks in the onDefault
.
self.dialog.onDefault(
[
function(session, args, next)
{
// Check query grammar
var message = session.message.text;
console.log("Checking grammar on %s", message);
self.languageBot.spellChecker(message, function(result,error) {
if(error) { // grammar error
self.logger.error("Failed to check grammar for %s", message);
session.send( self._options.locale['RESPONSE_NOTUNDERSTOOD'] )
} else { // grammar passed
if( result.text != result.correction ) { // misspelling
var msg = "You typed " + result.text + "\nDid you mean \""+result.correction+"\"?"
session.userData.correct = {
text : result.text,
correct : result.correction
};
BotBuilder.Prompts.text(session, msg );
}
else {
session.send( self._options.locale['RESPONSE_NOTUNDERSTOOD'] )
}
}
});
}
, function (session, results)
{
var response=results.response;
if ( response == 'yes' ) {
//@TODO redo query
session.beginDialog('/');
}
else {
session.send( self.getLocalizedString('RESPONSE_DISCARD','RESPONSE_DISCARD') );
}
}
]);
Issue Analytics
- State:
- Created 7 years ago
- Comments:14 (7 by maintainers)
So I guess I have one more suggestion. You can teach LUIS to recognize these misspellings. When you first train your LUIS model it’s going to pretty much suck. The idea is you have to regularly go back and update your model by labeling all of the utterances it’s been seeing, including the ones with misspellings, and then retrain and deploy a new model . If you do this it will quickly get better and eventually it’ll will handle pretty much any misspellings the user throws at it. Honestly you shouldn’t need to add your own spell checking logic as a way to deal with unrecognized intents. Just be religious about updating your model every day the first few weeks/months your bot is deployed.
Its also useful to just let a few people kick the tires by throwing your bot some messages you didn’t think of. It’s going to suck at first but it will quickly get better.
Interesting… First let me answer your core question and then I have one other suggestion…
To answer your question you’d want to use
session.replaceDialog()
instead ofsession.beginDialog()
that will unload and reload the current dialog. To apply the correction just assign it tosession.message.text
before callingreplaceDialog()
That should do what you’re trying to do.My other suggestion is to use Prompts.confirm() instead of Prompts.text(). This prompt already knows to look for several variants of the yes & no. The returned
result.response
will be a simple Boolean so way easier to check.