RealSpeaker / telegraf-session-local

Telegraf local sessions middleware with multiple supported storage types (Memory/FileSync/FileAsync/...) using lowdb
https://git.io/v7iw9
MIT License
93 stars 10 forks source link

Save a session on bot start? #49

Closed amirhoseinsalimi closed 5 years ago

amirhoseinsalimi commented 5 years ago

Hello,

I want to save user's information as he/she starts using my bot but I figured out setting sessions on bot.start() doesn't work or at least I'm doing something wrong. Manipulating sessions on other event handlers (.hears(), on('audio'), etc.) works well though. Here's the code:

Screenshot from 2019-08-16 15-33-26

Where did I go wrong? Is this a Telegram bot API limitation?

TemaSM commented 5 years ago

Hi, I tried to reproduce, but it worked well, just as expected. May you please give info about Telegraf and telegraf-session-local versions you're using? Also, it would be great if you send me a link to repository or attach zipped sources of you bot. (with package.json but without node_modules)

amirhoseinsalimi commented 5 years ago

Sorry for my late reply and thank you for your attention.

After 3 days it's turned out that moving the session-related statements to the upper scope (outside if... else) solves the problem! Also, a funny mistake I had made was to miss parenthesis to invoke the constructor of date -> new Date (line 49). Now the code looks like this and works as it should does:

Screenshot from 2019-08-19 23-59-06

TemaSM commented 5 years ago

Nice to hear that you solved the problem 👍 Now closing this "issue", but feel free to re/open if you have any questions or facing bugs in telegraf-session-local