How can I efficiently manage sequential prompts in my Telegram bot survey without relying on if…else chains? I tried using a generator function to yield messages and capture responses, but I’m unclear on the proper way to invoke it step by step. Here is an alternate code snippet demonstrating my approach:
function* handleSurveyFlow() {
let firstResponse = yield bot.askMessage(userToken, "Please enter your first name:");
bot.on('update', updateData => {
let firstName = updateData.text;
});
let secondResponse = yield bot.askMessage(userToken, "Now, provide your last name:");
bot.on('update', updateData => {
let lastName = updateData.text;
});
}
I would appreciate any guidance on how to call the generator consistently to process the user inputs in a more structured way.