Nested conversation.ask() don't fire
See original GitHub issueHello,
When i execute this code , the program get stucked on the second recursion of getResponse(). Both someFunctionWhoGenerateResponse and generateGreeting function return valid string and work perfectly.
` const bot = new BootBot({ accessToken: config.get(‘accessToken’), verifyToken: config.get(‘verifyToken’), appSecret: config.get(‘appSecret’) });
function getResponse(txt, convo) { var rps = someFunctionWhoGenerateResponse(txt); convo.sendTypingIndicator(); convo.ask(rps, (payload, convo, data) => { convo.say(“hum”); getResponse(payload.message.text, convo); }); }
function sendGreeting(response, convo) { var init = generateGreeting(); convo.ask(init, (payload, convo, data) => { getResponse(payload.message.text, convo); }); }
bot.hear(‘hello’, (payload, chat) => { chat.conversation((convo)=> { sendGreeting(payload.message.text, convo); }); }); `
Issue Analytics
- State:
- Created 7 years ago
- Comments:5 (3 by maintainers)
Top GitHub Comments
@Charca I think there’s a small bug here that might be related to this issue:
https://github.com/Charca/bootbot/blob/master/lib/Conversation.js#L105
If you synchronously call ask() again inside the listener, your callback is assigned to this.listeningAnswer, but upon return to the above line of code, your newly added listener is thrown away. This was causing a similar issue for me and changing it to do something more like:
solved the problem. I can make a pull request at some point but am kinda in a crunch at the moment.
Thanks for the very nice library!
@andrijdavid Heads up, FYI.
Fixed in v1.0.10: https://github.com/Charca/bootbot/compare/v1.0.9...v1.0.10