【问题标题】:How to combine ChoicePrompt and TextPrompt in the same step如何在同一步骤中结合 ChoicePrompt 和 TextPrompt
【发布时间】:2019-08-08 04:43:05
【问题描述】:

我在 node.js 中使用 Microsoft Bot Framework V4。在对话框的一个步骤中,我们需要使用 ChoicePrompt 对象和 TextPrompt 组合按钮。如果用户单击按钮,则会触发建议的操作,如果用户编写纯文本,我们将使用 LUIS 和某些意图来处理该操作。问题在于将这两种操作结合​​起来。

我尝试避免在使用 ChoicePrompt 时重新提示,但我无法做到。我也在寻找其他可以直接结合按钮和文本的提示,但似乎没有。

首先我在提示符中声明我正在使用的对象:

class ExampleDialog extends LogoutDialog {
  constructor(userState, logger) {
    super(EXAMPLE_DIALOG);

    this.addDialog(new TextPrompt(TEXT_PROMPT));
    this.addDialog(new ChoicePrompt(CHOICE_PROMPT));

其次,在步骤中,我使用了之前声明的提示:

async firstStep(step) {    
  const promptOptions = {
    prompt: 'Text to prompt',
    retryPrompt: 'Retry text prompt',
    choices: ChoiceFactory.toChoices(['option1', 'option2', 'option3'])
  };

  const promptAction = await step.prompt(A_PROMPT_ID, promptOptions);

  return promptAction;
}

async secondStep(step) {
  const thePreviousStepResult = step.result.values
}

【问题讨论】:

  • 明确地说,您希望提示接受任何字符串但仍为用户提供按钮。对吗?
  • 是的,正是这个。
  • LogoutDialog 是组件对话框吗?
  • 是的,LogoutDialog 继承自 ComponentDialog,是登录所必需的。

标签: node.js botframework


【解决方案1】:

当你想接受任何字符串时,文本提示是一种方式。请记住,您可以将任何活动作为提示选项的prompt 属性包含在内,并且该活动可以包含附件、建议的操作等。您可以在source code 中看到选择提示只调用Prompt.appendChoices,它使用@ 987654328@ 为其活动生成按钮。你也可以这样做:

const promptOptions = {
    prompt: ChoiceFactory.forChannel(step.context, ['option1', 'option2', 'option3'], 'Text to prompt')
    // You can also include a retry prompt if you like,
    // but there's no need to include the choices property in a text prompt
};

const promptAction = await step.prompt(TEXT_PROMPT, promptOptions);

return promptAction;

【讨论】:

  • 非常感谢!! :)
  • @ErnestoAlarcónGallo - 如果这对你有帮助,请记得点赞并接受我的回答
  • 我想投票,但我还是太新了,我会尽快投票。对不起……
  • @ErnestoAlarcónGallo - 这是您自己问题的答案。即使您不能投票,您仍然可以通过单击复选标记来接受它。
  • 我正在寻找这个。试图给出选择,但同时也接受来自文本的答案。我试过这个,但它不起作用。对话框不断重新渲染。我相信公认的.succeeded 并没有真正做到这一点
猜你喜欢
  • 1970-01-01
  • 2018-06-15
  • 1970-01-01
  • 1970-01-01
  • 2022-11-23
  • 2018-12-25
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多