-
Notifications
You must be signed in to change notification settings - Fork 145
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Promise from macros never resolve #247
Comments
When I use this fork https://github.com/genericallyloud/rivescript-js const reply = rs.reply(user, message)
console.log(reply, typeof reply) //=> Promise { <pending }, object
if(reply.then){
reply.then(replyStr => {
console.log(replyStr) //=> hello
bot.sendMessage(replyStr, channel)
})
}else{
bot.sendMessage(reply, channel)
} The only problem is the fork is way behind and I'd like to also stay updated with changes on this repo. I guess it solves most of the problem and is backward compatible |
This one stumped me for a little bit. Here's an example that works with the latest version: https://play.rivescript.com/s/T7AQtaUpn3 (enable "Async Replies" at the bottom) It seems that the native Promise object to JavaScript isn't supported by RiveScript right now. When this feature was first implemented, an When I tested the above code with the native Promise object, the reply would come back as "Testing: [object Promise]" whether When I switched to the My hunch is there is an API difference between rsvp.js and the native Promise, and so internally when it tries to resolve the object macros, it fails to. |
as a user of the library, is this something we need to be aware of? is this related to I also haven't been able to get values back to Rivescript from simple javascript calls: it seems that a next tick is required before we can do things like conditionals. |
I honestly think we wouldn't need a I'd try to add changes from that fork into this but I'm afraid we may have to just ditch |
The other way to avoid breaking compatibility would be to add an additional parameter to
Async-Await (like #220) will let us "pause" and wait for macros to resolve for things like conditionals and will make all of this a lot nicer. We could also use it in the What we should do for this ticket: fix the promise system, get rid of rsvp.js and try to use native promises, or find a better polyfill library when native promises aren't available. |
Yeah that fork works in a similar way. A string always get returned when you don't have a macro that returns a promise. I guess what I don't understand is how to know when to use const reply = rs.reply(user, message) // At this point I don't know if it'd return a string or promise so
// how do I decide if reply or replyAsync
//
// if I know I've added some macros returning promise then I can check for them
if(reply.then){
reply.then(value => bot.reply(value))
}else{
bot.reply(reply)
}
// if I don't need to work with promises at all
bot.reply(reply) // Reply is a string Now the question remains why would I be using Currently using it like that on https://github.com/josephrexme/rivescript-promises and I could work on this if you get my point. In the long run we may decide to keep |
Short answer: just use Longer answer: It was a different function because Naive code that pre-dated the async macro support might sometimes tell the user "Bot: [object Promise]" if they didn't know to type check the reply. Instead, what happens is that if an async macro was called, the bot will say "[ERR: async routine called from reply: use replyAsync instead]" in place of the macro's output. This would tell the bot maker they should update their code to use |
Following up on #43 I have a macro returning a promise and it never resolves. With the following code:
I always get a string. Then I tried with the
replyAsync
It always return the promise value as a string.
The text was updated successfully, but these errors were encountered: