telegraf / telegraf

Modern Telegram Bot Framework for Node.js
https://telegraf.js.org
MIT License
8.25k stars 928 forks source link

How do I keep track of the last sent message? #132

Closed ghost closed 7 years ago

ghost commented 7 years ago

I feel like this should be trivial but I still can't quite get there:

bot.use((ctx, next) => {
  return next().then(() => {
    ctx.session.lastSentMessage = ???
  });
});

Overriding reply also seems like a dead end:

const reply = bot.context.reply;
bot.context.reply = (...args) => {
  ???
  reply(...args);
}

Note I'm not talking about the user message but the last message sent from the server. It's useful so that I can keep track of ''where'' the user is at any time.

ghost commented 7 years ago

Would be cool if chat already had this property included.

ghost commented 7 years ago

Oh wait, I think I basically had it:

bot.use((ctx, next) => {
  const reply = ctx.reply;
  ctx.reply = (...args) => {
    ctx.session.lastMessage = args;
    reply(...args);
  };
  return next();
});

Is this it?

dotcypress commented 7 years ago

Yes, you can save any user related info to session storage.

Also, check out telegraf-flow library.