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

[Question] Docs/example for creating a custom v3.8.x choice prompt? #3129

Closed
amitbend opened this issue Jul 13, 2017 · 6 comments
Closed

[Question] Docs/example for creating a custom v3.8.x choice prompt? #3129

amitbend opened this issue Jul 13, 2017 · 6 comments
Assignees

Comments

@amitbend
Copy link

amitbend commented Jul 13, 2017

System Information (Required)

  • SDK Language: NODE
  • SDK Version: 3.8.4
  • Development Environment: LOCALHOST, AZURE_BOT_SERVICE

Issue Description

I'm trying to create a custom choice prompt using the new v3.8.x mechanism, but i can't seem to find any references of how to do it correctly.
I tried to play with it, but I don't see any quick replies as I should.

Code Example

let destChoice = new builder.PromptChoice({
        disableRecognizer : true
})

library.dialog('destChoice',destChoice); 

builder.Prompts.destChoice = function (session, prompt, options) {
    console.log(prompt,options);
    var args = options || {};
    args.prompt = prompt || options.prompt;
    session.beginDialog('destChoice', args);
}
@nwhitmont nwhitmont changed the title Docs/example for creating a custom v3.8.x choice prompt? [Question] Docs/example for creating a custom v3.8.x choice prompt? Jul 13, 2017
@stevengum stevengum self-assigned this Jul 13, 2017
@stevengum
Copy link
Member

stevengum commented Jul 13, 2017

@amitbend, you're missing an .onRecognize() call. You disabled the built-in recognition, so you need to set up your own logic to handle users' responses. The only other issue I spotted with your code is if prompt and options.prompt weren't passed in as parameters. You're already setting args to options || {}, so you should setup your following code as:

args.prompt = prompt || args.prompt;

This way if prompt wasn't passed in, you won't run into the error saying that prompt is not a property of options. You can also use .onFormatMessage() to set a default prompt message if no prompt was passed in.

Out of curiosity, what are you trying to do with your custom prompt? Are you plugging in NLU via LUIS or API.ai?

@haakotsm
Copy link

Not sure if this helps, but I had to manually configure some intent matches for my prompts untill I found out my issue was a bug with the source code. What I did was create a new PromptChoice instance and attach intent matches on it. Then I configured the builder.Prompts.choice to use my instance of the PromptChoice instead of the default one.

let prompt = new builder.PromptChoice();
  prompt.matches(INTENTS.REQUEST_RECIPE, (session, args) => session.endDialogWithResult(args)) // The same method as matches in IntentDialog
    .matches(INTENTS.REQUEST_HELP, (session, args) => session.beginDialog(DIALOGS.REQUEST_HELP))
    .matches(INTENTS.DECLINE, (session, args) => session.endDialogWithResult(args))
    .matches(INTENTS.CONFIRM, (session, args) => session.endDialogWithResult(args));

  builder.Prompts.customize(builder.PromptType.choice, prompt); // Replace the default PromptChoice
  builder.Prompts.choice(session, promptText, choices, options); // Call on it normally, as I would any other prompts. 

@amitbend
Copy link
Author

amitbend commented Jul 16, 2017

Hi @stevengum97, I'm still trying to tackle #2987.
I thought to disable the recognizer, do he won't interrupt the choices.

I tried to write an onRecognize method, and applied the changed you've suggested.
But I still can't see the options (quick replies).
What am I missing?

@haakotsm I have a dynamic list of choices, so I can't hard code them. Thanks for trying to help anyway.

@stevengum
Copy link
Member

@amitbend re-reading my comment I may have been a little unclear... I'm actually referring to PromptChoice.onRecognize(), not something like LuisRecognizer.onRecognize().

Here's an example of what I'm talking about:

var customPrompt = new builder.PromptChoice({
  defaultListStyle: builder.ListStyle.button,
  disableRecognizer: true 
}); 

customPrompt.onRecognize(function (context, callback) {
  recognizer.recognize(context, function (err, result) {
    // If we don't get an error from recognizer.recognize 
    // we'll either send send the LUIS results along or trigger 
    // our custom prompt to re-prompt the user. 
    if (!err) {
      if (result && result.intent !== 'None') {
        callback(null, result.score, result);
      } else {
        callback(null, 0.0, { intent: 'None', score: 0.0 });
      }
    } else {
      callback(err, 0.0);
    }
  })
})

bot.dialog('CustomPrompt', customPrompt);

builder.Prompts.customPrompt = function (session, prompt, choices, options) {
  var args = options || {};
  args.choices = choices || args.choices;
  args.prompt = prompt || args.prompt;
  session.beginDialog('CustomPrompt', args);
}

Also, I don't see any choices handling here:

builder.Prompts.destChoice = function (session, prompt, options) {
    console.log(prompt,options);
    var args = options || {};
    args.prompt = prompt || options.prompt;
    session.beginDialog('destChoice', args);
}

I assume you're passing the choices in via the options object?

@stevengum
Copy link
Member

I'm closing the issue due to inactivity; if you're still having difficulty, please feel free to reopen this issue.

@ancashoria
Copy link

@amitbend I had to make sure my choices are passed in as an array of objects:
[ {value: 'Choice1'}, {value: 'Choice2'} ]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants