Comments (11)
@benbrown I've tried both increasing tick time from 1 sec -> 2 sec and calling convo.next() inside my callback function but behavior is still erratic.
I think I'll try promisify method or use some other workaround until I optimize my datastore response time.
@zachdunn you can increase the tick time to 1.5 seconds but this still does not guarantee your call will be done until the next tick. Also now your conversation will flow %50 percent slower overall.
from botkit.
We've found some stability improvements by wrapping the handler with Promisify. It's not a perfect solution, but it's one of the ways we've managed to keep things a bit more predictable until it's patched.
Here's a sample gist for response handler:
'use strict';
const Promise = require('bluebird');
module.exports = function (bot, message) {
Promise.promisifyAll(bot);
bot.startConversationAsync(message).then(function (convo) {
return Promise.fromCallback(function(callback) {
return convo.ask('What did you need?', function (a, b) {
callback(null, [a, b]);
});
}, true).spread(function (response, convo) {
convo.say(`Let's see what I can do for *"${response.text}"*`);
convo.next();
return new Promise((resolve) => {
convo.ask(`Found something. Do you want it?`, [
{
pattern: bot.utterances.yes,
callback: (response, convo) => {
convo.say(`Great. It's all yours.`);
resolve();
}
},
{
pattern: bot.utterances.no,
callback: (response, convo) => {
convo.say('OK, nevermind.');
resolve();
}
},
{
default: true,
callback: (response, convo) => {
convo.repeat();
}
}
]);
});
}).finally(function () {
convo.next();
});
}).catch(function (err) {
bot.reply(message, err.toString());
});
};
This is not a magic wand, and there's still some kind of race condition in play here.
from botkit.
Are you hitting the 1 message/sec api limit?
from botkit.
I'm not sure that limit would be in play here. You can see that the bot always replies to the message, and it's a matter of the conversation closing on the Node side (as logs show) intermittently before the API response is sent.
Of course I may have just missed your point entirely.
from botkit.
I face a similar issue when I'm trying to get some data from datastore and do convo.ask with this data, in some cases conversation ends prematurely, in other cases convo.ask succeeds. This has all the indications of a race condition.
What is the time limit to add a new ask into a conversation before it ends?
How can we set it?
More importantly how can we make sure conversation doesn't end prematurely before some API request is completed?
from botkit.
+1 – i've encountered this unusual behavior as well. any thoughts on what might be the culprit?
from botkit.
from botkit.
The issue here is that conversations proceed, at roughly 1 message per second until there are no messages left in the queue.
If you do something asynchronous while the message queue is processing as normal, it may end prematurely because you have not yet pushed another message onto the queue.
The current best way to handle this is to not call convo.next() until after your asynchronous action has finished.
Another approach would be to do all the asynchronous actions before starting the conversation.
from botkit.
If you do something asynchronous while the message queue is processing as normal, it may end prematurely because you have not yet pushed another message onto the queue.
Suddenly #20 (comment) makes a lot more sense. Is there a way to disable/adjust this timeout on conversations? Seems like there's a parallel to KeepAlive
in server configurations.
Or was that achieved by your convo.next()
comment?
Reason I ask -- you can imagine a bot where the workflow isn't as predictable and ability to specify how quickly a conversation expires (or if it ever does without explicit commands) is needed:
User says something like "Let's search for hats"
Conversation starts
Bot switches into a context that's primed for hats. "What type of hat did you want?"
User says "baseball hats"
Bot fetches results from whatever leading hat-based API exists out there
Riveting hat conversation continues. User can ask for more information (more API calls)
User is done, says "OK we're done"
Exit hat context
End conversation
Happy to be wildly off base here. Would make life much simpler. 😀
from botkit.
It's a shame this is closed, as it seems it's still a problem. I'm doing a convo.say, then mapping over an array to make an api request for each item to build a response and the conversation ends before I get the next response out. This happens even if there is only a single item in the array. I'm only doing this because bot.reply messages aren't guaranteed to be sent in order.
from botkit.
@darrenparkinson the solution to your issue is to do those asyncronous calls outside of the conversation - by using createConversation, doing the async, then calling convo.activate(), or by doing it in a convo.ask callback before calling convo.next.
from botkit.
Related Issues (20)
- How to recover from a BotFrameworkAdapter message rejection (401 error)? HOT 7
- MS Teams: Property 'api' does not exist on type 'BotWorker' HOT 10
- Send proactive message on MS teams HOT 2
- botkit 4.15.0 and Webex Adapter 1.0.10 are not on NPM HOT 1
- How to upload this Bot to Teams? HOT 2
- Bot can send, but not receive anymore HOT 2
- Botkit Webex API client not returning data HOT 1
- Question: Handling Websocket terminations HOT 1
- Uncatchable throws on botbuilder-adapter-webex registerWebhookSubscription Functions HOT 19
- Conversation become "duplicated" when running long operation HOT 1
- Help in Implementing the B2C Chatbot
- Webex Teams Adapter Doesn't Support direct_mention Event Type
- ☺
- BotkitConversation not executing when using axios but its executing fine when calling inside request?
- Cannot read property '1' of undefined
- Block Action Issue (when 'Clear Selection' is clicked)
- Can I message a pages followers with this??
- Remove deprecated request package
- Is project Dead? HOT 2
- Botkit
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from botkit.