My convo ends prematurely due to an API call that takes too much time. What is the recommended way to queue the event convo.say('something') but delay its firing, so that the conversation does not end?
@devhaoy do not call convo.next() until your asynchronous request has completed.
Hi @benbrown one issue with doing the heavy work in the response handler, before convo.next(), is that nothing will fire at all before all the work is processed. In my case I ask a user to send an image and then call an API: the whole process lasts 15 secs so i'd smooth it by sending a message to the user once the bot receives the image but before it calls the API ==> impossible if the API is called before convo.next(), in this case convo.say('I got your image') won't fire until the API call goes through.
This is why I'm calling the API in the subsequent thread and before convo.ask('?' , function(response, convo) { . By doing this though, the conversation ends prematurely except if I artificially add 5 convo.say('something') to queue actions until the API call goes through.
Hence my problem: how can I queue a convo.say but not fire it until the API call is processed?
@devhaoy Aha, yes, this is tricky.
I am actually in the process of adding an additional hook for conversations so that you can trigger actions like this _in between threads_. This would allow you to complete your thread 'I got your image' and then call gotoThread('completed'), but do the API call _before the completed thread begins_.
I am hoping to get this into the next version of Botkit!
@devhaoy take a look at this pull request -> https://github.com/howdyai/botkit/pull/754
Hi @benbrown ! excuse my noob, but could you add an example for beforeThread function? Do I have to use it along with gotoThread or does it work as standalone?
In my case I am calling the next thread as a simple function nextThread(response, convo) then convo.next(). Where do I include beforeThread in there?
Anyway, thanks for releasing a solution so quickly!
@devhaoy you can find it in the docs
https://github.com/howdyai/botkit/blob/b28821337ff99c6060587a1fc60788983b447146/docs/readme.md#convobeforethread
@peterswimm that fix will work with threaded conversation only, i'm looking for anything that will produce the same result but within the default thread. Should repoen?
Could you explain why that is preferable behavior?
Hi @peterswimm it's explained in my second message above. Basically I prompt user to send a picture then process it with several API, which last 15+ seconds in total. Sometime the upload of the pics itself will last 5-7 seconds if the user's connection is poor. I want to send a simple "Got your picture, please hold tight" message to the user once the upload is completed, so that he knows he should wait a bit (a not send another message for example, which could break the flow).
In order to do so I need to call the APIs after calling convo.next() but then the conversation ends prematurely. This is why I'm looking for any solution that will allow me to prevent the conversation from ending when I call the API beforea convo.ask
I have exactly the same problem.
Same here. I think we need something like convo.tick(), which will send the queued messages that have been added with convo.say, but won't move us to the next thread yet.
@TheDApact Maybe I did not understand at the end but, could you use transitionTo('Got your picture, please hold tight','api_succes') and beforeThread('api_succes', (convo,next) => {//api request}) ?
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
Most helpful comment
Same here. I think we need something like convo.tick(), which will send the queued messages that have been added with convo.say, but won't move us to the next thread yet.