Giter VIP home page Giter VIP logo

Comments (7)

EdJoPaTo avatar EdJoPaTo commented on June 19, 2024 1

From experience: It worked fine with async stuff for me. But forgetting the await on something is easily done in JavaScript / TypeScript. There are some ESLints that help with finding that in TypeScript.

Personally I switched away towards grammY. It provides its own session logic and the storage is separated from the middleware logic which prevents implementation bugs there. It might be worth a look. Switching from Telegraf to grammY is relatively straight forward and grammYs documentation is way better.

from telegraf-session-local.

vtcaregorodtcev avatar vtcaregorodtcev commented on June 19, 2024

Here is the example vtcaregorodtcev/remark-telegram-bot@dde683b#diff-5566f90f142be7d5c358410953f0b4c628c99e20b620d172c8e12ec92bdc9620R34

at 34 line I use sync middleware to save Link to the session
at 35 I use async middleware to get data from the Link

at 36 line I can get async data only within the same user message if the user will send another message, I lost data from 35 line.

from telegraf-session-local.

vtcaregorodtcev avatar vtcaregorodtcev commented on June 19, 2024

Screenshot 2022-01-16 at 08 39 41

from telegraf-session-local.

vtcaregorodtcev avatar vtcaregorodtcev commented on June 19, 2024

@EdJoPaTo it's also worth mentioning, my example is based on AWS setup

from telegraf-session-local.

EdJoPaTo avatar EdJoPaTo commented on June 19, 2024

AWS should be completely irrelevant here. Node.js is Node.js and its async/await Logic is handled the same way on all platforms. Whatever the exact problem is, you should be able to reproduce it locally. When that is possible throw out stuff in order to have a minimal example where you can still reproduce the bug. Then its way easier to find the cause of it.

What helps me with missing awaits somewhere: Create a simple logging middleware and put it in between every other middleware. If a log message comes before it should, there is a missing await.

Maybe check out my console.time middleware for testing middlewares. If the inner is way to short or the report comes back way to early the problem is below of what you tested. If the before/after is way to short, then its the middleware you just checked.

from telegraf-session-local.

vtcaregorodtcev avatar vtcaregorodtcev commented on June 19, 2024

@EdJoPaTo sorry, it looks like I should anyway set up all AWS flow for minimal reproduction. I guess you can fork provided commit vtcaregorodtcev/remark-telegram-bot@dde683b and there is an issue.

there is Link property which set in sync manner vtcaregorodtcev/remark-telegram-bot@dde683b#diff-4219770533d72f642405c1221b67774ae414f90ab05212b8b44bb2b063b62cf9R15

and Text property which set in async manner vtcaregorodtcev/remark-telegram-bot@dde683b#diff-a2fb86f8d1743026e193802adeb45a908d8793046564073b63e6dcc1feade4c2R31

if we will set console.log or something here vtcaregorodtcev/remark-telegram-bot@dde683b#diff-5566f90f142be7d5c358410953f0b4c628c99e20b620d172c8e12ec92bdc9620R32

we will see that after each request Link is still stay but Text is missing.

to run it locally we should anyway deploy lambda to AWS to use offline serverless.
pnpm deploy then get lamda URL and TOKEN=your_bot_token HOOK=lambda_url pnpm start

from telegraf-session-local.

TemaSM avatar TemaSM commented on June 19, 2024

Thanks for help @EdJoPaTo 👍
Closing now as stale, but if someone wanna ask more - feel free to do so.

from telegraf-session-local.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.