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);
}
};
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);
}
};
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.
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.
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.