node.js - 如果用户响应无效值,则 Azure Botframework : How to re-prompt the Prompt. 文本

标签 node.js botframework

我有一个对话框,其中有多个提示(Prompts.text, Prompts.number, Prompts.Choice提示.确认)。虽然 Prompts.choicePrompts.confirm 似乎有内置验证,但如何验证 Prompts.text

我已经浏览过这个线程How to handle wrong input from the user?但通过将文本转换为选择来纠正它。

此外,我不想重新启动整个对话框,因为它会提出从那时开始的问题,如 create custom prompts to validate input 所示。

这是我的对话框的简短版本:

bot.dialog('/getDetails', [

 function (session, args, next) {

    let options = {
                retryPrompt: 'The response id invalid'
                }

      builder.Prompts.text(session, 'What is your full name?', options);
     //passing options as argument works for Prompts.choice, which seems an inbuilt validation

 },
 function (session, results, next){

     var name = session.dialogData.name;

     //How to to reprompt if user does not enters its full name?
     if (results.response) {
         name.fullname = results.response;
     }

       builder.Prompts.text(session, 'Can you please provide your country name?');  

 },
 function (session, results) {

     var name = session.dialogData.name;

     //How to reprompt only last Prompts.text if user enter an invlid value?
     if (results.response) {
         name.text = results.response;
     }

    }
 }]).triggerAction({
    matches: 'GetDetails', 
})

最佳答案

这是我如何通过 DialogAction.validatedPrompt 解决这个问题的

bot.dialog('/getDetail', [
    function (session) {
      session.beginDialog('/validateAge', { prompt: "What's your age?" });

      //if false response, then prmopts "I did not understand {age}""    

    },
    function (session, results) {

        if (results.response) {
            session.send("Thank you for adding your age");
        } 
    }
]).triggerAction({
     matches: /^lets validate$/i

})


bot.dialog('/validateAge', builder.DialogAction.validatedPrompt(builder.PromptType.text, function (response) {
   if(response> 0 && response < 70){

    return response;
   }
}));

关于node.js - 如果用户响应无效值,则 Azure Botframework : How to re-prompt the Prompt. 文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48785441/

相关文章:

c# - Cosmos,在 MessageController 中检索对话数据

typescript - 获取 Botbuilder 登录按钮取消响应

c# - C# 中使用 ILogger 进行单元测试静态方法 ILoggerFactory 为 Null

javascript - 为抛出错误的异步函数编写测试

node.js - 中间 suv-patch Node.js 包版本

node.js - 直接流式表达响应时处理mongodb错误

iis - 阻止我的机器人应用程序发布到 IIS Web 服务器的 "AppOffline"是什么?

azure - Azure Function Bot 部署失败

javascript - 使用 Async/Await 计算来自 3 个不同循环的错误,这些循环在每次迭代时调用异步函数

node.js - 我有一个基于webrtc的跨域屏幕共享。它可以完美地在网络中运行,但是当我将其转换为 Electron 时,它将停止工作