APIs & Integrations

AlexCornejo
Participant

ChatFlow "responseExpected": it does not work

Résolue

Dear,

 

I'm doing a chatflow with code snippet 🙂 Using your own example:

 

exports.main = (event, callback) => {
var responseJson = {

"botMessage": "Select one option",
"quickReplies": [ { value:'op1 ', label:'op1' }, { value:'op2', label:'op2'} ],
"responseExpected": false
};
callback(responseJson);
};

 

This one won't let me respond.

 

I've looked for documentation and it doesn't exist. Do you have any idea how to make it work?

 

Thanks a lot.

0 Votes
1 Solution acceptée
zaklein
Solution
Contributeur | Partenaire solutions Diamond
Contributeur | Partenaire solutions Diamond

ChatFlow "responseExpected": it does not work

Résolue

Hi AlexCornejo,

 

Again, the reason you're stuck in a loop is because the exports.main function is called again when responseExpected is set to true. The reason it behaves like this is to give you a chance to do something based on the visitor's response.

 

For the purpose of getting your example to work, the below should do the trick. It's not particularly useful because it doesn't change the chatflow's behaviour based on the visitor's selection --> it simply let's the visitor choose an option and then goes to the "next_module" without acting on the visitor's choice. But hopefully, it'll get you on the right track 😄

 

exports.main = (event, callback) => {
  if (event.userMessage.quickReply == null) {
    // this block will run if there are no quick replies in the event object
    const responseJson = {
      botMessage: "select an option",
      quickReplies: [ { value:'option_1', label:'Option 1' }, { value:'option_2', label:'Option 2' } ],
      nextModuleNickname: "next_module",
      responseExpected: true
    };
    callback(responseJson);
  } else {
    // this block will run if the event object contains quick reply messages
    // (i.e. when someone has selected any option in their most recent reply)
    const responseJson = {
      nextModuleNickname: "next_module"
    };
    callback(responseJson);
  }
};

 

All the best,

 

Zach

Voir la solution dans l'envoi d'origine

6 Réponses
zaklein
Solution
Contributeur | Partenaire solutions Diamond
Contributeur | Partenaire solutions Diamond

ChatFlow "responseExpected": it does not work

Résolue

Hi AlexCornejo,

 

Again, the reason you're stuck in a loop is because the exports.main function is called again when responseExpected is set to true. The reason it behaves like this is to give you a chance to do something based on the visitor's response.

 

For the purpose of getting your example to work, the below should do the trick. It's not particularly useful because it doesn't change the chatflow's behaviour based on the visitor's selection --> it simply let's the visitor choose an option and then goes to the "next_module" without acting on the visitor's choice. But hopefully, it'll get you on the right track 😄

 

exports.main = (event, callback) => {
  if (event.userMessage.quickReply == null) {
    // this block will run if there are no quick replies in the event object
    const responseJson = {
      botMessage: "select an option",
      quickReplies: [ { value:'option_1', label:'Option 1' }, { value:'option_2', label:'Option 2' } ],
      nextModuleNickname: "next_module",
      responseExpected: true
    };
    callback(responseJson);
  } else {
    // this block will run if the event object contains quick reply messages
    // (i.e. when someone has selected any option in their most recent reply)
    const responseJson = {
      nextModuleNickname: "next_module"
    };
    callback(responseJson);
  }
};

 

All the best,

 

Zach

AlexCornejo
Participant

ChatFlow "responseExpected": it does not work

Résolue

Thank you very much for your help with this if I can pass the following module

0 Votes
zaklein
Contributeur | Partenaire solutions Diamond
Contributeur | Partenaire solutions Diamond

ChatFlow "responseExpected": it does not work

Résolue

Hi Alex,

 

I think changing the value of the responseExpected key to true will do the trick, i.e. -->

"responseExpected": true

 

Hope that helps 🙂

Zach

 

AlexCornejo
Participant

ChatFlow "responseExpected": it does not work

Résolue

Hi Zaklein 🙂

 

  • False doesn't let me respodner but it goes to the next node.
  • True lets me answer but asks me the same infinitely. if here it could go to the next node it would work perfect. Try "nextModuleNickname: 'nextNode' but it doesn't work.

Do you have any idea how to make it work?

 

Thank

0 Votes
zaklein
Contributeur | Partenaire solutions Diamond
Contributeur | Partenaire solutions Diamond

ChatFlow "responseExpected": it does not work

Résolue

Hi again AlexCornejo,

 

If responseExpected is set to true, the exports.main block is called again after the chatflow visitor has responded. This gives you the chance to change the chatflow's behaviour based on the visitor's response to the questions you ask using quickReplies.

 

If you want to move to a specific module after the visitor has responded to your quickReplies question, try using nextModuleNickname --> to find the target chatflow module's "nickname", go out to your chatflow view, click the module and copy the value in the "Action name (internal only)*" field.

 

 

exports.main = (event, callback) => {
  var responseJson = {
    "botMessage": "Select one option",
    "quickReplies": [ { value:'op1', label:'op1' }, { value:'op2', label:'op2' } ],
    "nextModuleNickname": "Target next module 'Action name' / nickname",
    "responseExpected": true
  };
  callback(responseJson);
};

 

 

If you would like to change the chatflow's behaviour based on how the visitor responds to your quickReplies question, you could try doing something like this ...

 

 

exports.main = (event, callback) => {
  if (event.userMessage.quickReply == null) {
      // this block will run if there are no quick replies in the event object
      const responseJson = {
        botMessage: "Select one option",
        quickReplies: [ { value:'option_1', label:'Option 1' }, { value:'option_2', label:'Option 2' } ],
        responseExpected: true
      };
      callback(responseJson);
    } else if (event.userMessage.quickReply.quickReplies[0].value == "option_1") {
      // this block will run if the visitor has selected "Option 1" (value "option_1")
      const responseJson = {
        botMessage: "Thanks for selecting " + event.userMessage.quickReply.quickReplies[0].label,
        nextModuleNickname: "Target next module 'Action name' / nickname",
        responseExpected: false
      };
      callback(responseJson);
    } else if (event.userMessage.quickReply.quickReplies[0].value == "option_2") {
      // this block will run if the visitor has selected "Option 2" (value "option_2")
      const responseJson = {
        botMessage: "Thanks for selecting " + event.userMessage.quickReply.quickReplies[0].label,
        nextModuleNickname: "Target next module 'Action name' / nickname",
        responseExpected: false
      };
      callback(responseJson);
    }
};

 

 

Of course, the exact logic you'll need to use will depend on the chatflow question immediately preceding your cope snippet module.

 

Hope this helps 😄

 

Zach

 

AlexCornejo
Participant

ChatFlow "responseExpected": it does not work

Résolue

wow!

Thank you very much,

it worked very well, when the user finishes responding, it goes to the next node.

But anyway ignore the part of the "nextModuleNickname" that I am missing? Can you help me with an example of this? am I doing the node wrong?

Greetings.

 

AlexCornejo_0-1607538223993.png

 

AlexCornejo_1-1607538279596.png

 

0 Votes