我只有一个dialog,其中有多个提示(Prompts.textPrompts.numberPrompts.ChoicePrompts.confirm)。虽然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;
   }
}));

10-08 01:47