KnorpelSenf / telegraf-session-firestore

Google Firestore based session middleware for telegraf.js
MIT License
4 stars 0 forks source link

Lazy mode with Scenes #3

Closed absemetov closed 2 years ago

absemetov commented 3 years ago

Is it possible to customize the scenes for this mode? Or use lazy mode in chat, this code not work


bot.use(firestoreSession(firestore.collection("sessions"), {
  lazy: (ctx) => ctx.chat.type === "private",
}));
KnorpelSenf commented 3 years ago

Sorry for late response. I don't think anything else for telegraf interoperates well with lazy mode. It can basically only be used well if you wrote all the code that touches the session data, because no other plugin can do it.

That being said, you can of course write your own version of scenes that properly awaits ctx.session. But let me tell you that the scenes of telegraf are a large hack under the hood, so it may or may not be a bit painful to adapt it.

There is a new bot framework that is trivial to pick up if you know telegraf, and it natively supports lazy mode everywhere. It has no scenes yet so it won't solve your problem, but it will be announced in @grammyjs_news as soon as it's done. (I know because I created grammY.)

KnorpelSenf commented 2 years ago

A superior alternative to scenes have been added to grammY. They are called conversations. Naturally, they support lazy mode. The documentation for this plugin can be found here: https://grammy.dev/plugins/conversations.html