Amazebot / bbot

An adaptable conversation engine for building bespoke bots.
MIT License
55 stars 2 forks source link

Respond from middleware throws unless async #94

Open timkinnane opened 6 years ago

timkinnane commented 6 years ago

It should be possible to respond from a middleware piece, without needing a matching listener. e.g. To give a message before ignoring.

I've added an e2e test to show that it works, but it throws unless the function is async and awaits the respond call, before calling the done function.

I don't think that's desirable simply because it's too easy to miss it.

e.g.

The following throws...

bot.hearMiddleware((b, next, done) => {
  b.respond('test')
  done()
})

The following works...

bot.hearMiddleware(async (b, next, done) => {
  await b.respond('test')
  done()
})

Here's a workaround for simple promise return...

bot.hearMiddleware((b, next, done) => respond.text('test').then(() => done()))