Setting Default Text or Quick Replies For Wrong Responses

  1. People, How Can I set a Default Text or Quick Reply When User Enters Wrong or Gibberish Response(s) ?

  2. People, How Can I repeat the text or quick reply of a step, when the user enters any invalid response ?

1 Like

I have found this solution a while back and I think this may help people who have the same issue, if i posted the solution here !

If we want to validate something and return a false response via code in the Developer Section, or if we want to repeat the same question to the user with some response like “THE GIVEN ORDER ID DOESN’T EXIST !” or “KINDLY ENTER A PROPER INPUT” etc, We should pass an object inside the resolve() method.

SYNTAX:

resolve({
    success: false,
    question: INVALID_RESPONSE_MESSAGE
});

EXAMPLE:

let givenUserId = app.data.message;
let res;
res = await app.dataStore.search({
       table: "user_details",
       body: {
           query: {
               match: {
                   user_id:{
                       query:givenUserId
                   }
               }
           }
       }
   });
   if (res.hits.total == 0) {
       return resolve({
           success: false,
           question: "THE GIVEN USER ID DOES NOT EXIST ! \n 
                      KINDLY ENTER A VALID USER ID !"
       });

}

1 Like

Thank you @Amudhan_S for sharing this solution with the YM community!

1 Like

Hey Amudhan,

What is the difference between the above approach and the following?

let givenUserId = app.data.message;
let res;
res = await app.dataStore.search({
       table: "user_details",
       body: {
           query: {
               match: {
                   user_id:{
                       query:givenUserId
                   }
               }
           }
       }
   });
   if (res.hits.total == 0) {
       await app.sendTextMessage("THE GIVEN USER ID DOES NOT EXIST ! \nKINDLY ENTER A VALID USER ID !")
       return resolve({
           success: false
       });
}

Ideally a function is only supposed to do one thing which is why I prefer the latter approach which I also find to be clear & concise.

Hi Arun,

I guess both of the codes are similar. I agree that your code looks cleaner than mine. But I think, the exact conclusion on which code is to preferred or suggested would be based on the use cases. Because, I have been suggested to use as much lesser Asynchronous functions as possible, since each of those functions tend to eat up some n period of time.

2 Likes