首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >:如果用户使用无效值进行响应,如何重新提示Prompt.text

:如果用户使用无效值进行响应,如何重新提示Prompt.text
EN

Stack Overflow用户
提问于 2018-02-14 10:55:56
回答 1查看 693关注 0票数 2

我有一个dialog,它有多个Prompts(Prompts.textPrompts.numberPrompts.ChoicePrompts.confirm)。虽然Prompts.choicePrompts.confirm似乎有内置的验证,但是如何验证Prompts.text呢?

我已经浏览过这个线程如何处理来自用户的错误输入?,但它是通过将文本转换为选择来纠正的。

另外,我不想重新启动整个对话框,因为它从开始询问问题形式,然后如创建自定义提示来验证输入中所示

下面是我的对话框的较短版本:

代码语言:javascript
复制
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', 
})
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2018-02-14 13:38:08

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

代码语言:javascript
复制
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;
   }
}));
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/48785441

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档