Closed kev095 closed 1 year ago
You need a cache or database to persist this. Let's say you have a series of inputs, eg first name, last name, document number, etc, you need to save each of these during the step when the user replies.
This can also prove useful especially if the server restarts in the middle of a conversation as the user won't have to start answering the questions from the top.
Here's an example (not clean code, but demonstrates the idea):
let cache = {}; // can be redis, sql, etc
if (msg.type === 'list_reply') {
if (msg.data.id === 'first_name') {
cache = { ...cache, firstName: msg.data.text };
// send reply, proceed to next step, etc
} else if (msg.data.id === 'document_number') {
cache = { ...cache, documentNumber: msg.data.text };
// send reply, proceed to next step, etc
} else if (msg.data.id === 'email') {
cache = { ...cache, email: msg.data.text };
// send reply, proceed to next step, etc
}
}
Thank you very much for your answer, your successful project is great!
You're most welcome. Thank you very much! 😊
Marking this as closed for now. @kev095, feel free to reopen if need be 😊
Hello, I have a question when I send a list of options (list_reply) and the user enters an "account status" option and then enters the document number. How do I get that value going through the previous validations again?