Closed expelliamus closed 4 years ago
Hey.
This package is designed to work with async handlers. Problem is definitely not in there.
I think it does not work in your case because of the middleware order. Middlewares should be added before the handlers in order for them to work, like this:
bot.on(...) // sessions will not work here
bot.use(...); // let's say this is our session middleware
bot.on(...); // sessions will work here
bot.command(...); // sessions will work here
Here's an example that I just tested:
bot.use(async (_, next) => {
console.log('middleware before');
await next();
});
bot.command('/test', () => console.log('command'));
bot.use(async (_, next) => {
console.log('middleware after');
await next();
});
Output was:
middleware before
command
I hope this helped you.
Hi! I'm having the same issue here, and bot.on() is placed after bot.use(session(db)). For example, i have this code:
bot.on('text', async (ctx) => {
ctx.session.msg0 = 'wowow'
ctx.reply('woot').then(res=>ctx.session.msg1 = res)
const msg = await ctx.reply('woot')
ctx.session.msg2 = msg.message_id
ctx.session.msg3 = 'wowow'
})
Only msg0 is saved to the db, other 3 are accessible in this function's scope, but not afterwards.
Hi,
first of all thanks for this library. I have configured the session in this way:
I'm facing a strange issue when I do this:
essentially the session doesn't store the
optionsMessage
object, but if I do this:I can see the record stored in
data
, I did something wrong or there is an issue?thanks.