EdJoPaTo / grammy-inline-menu

Inline Menus for Telegram made simple. Successor of telegraf-inline-menu.
MIT License
355 stars 44 forks source link

telegraf error undefined undefined Error: next(ctx) called with invalid context #2

Closed PollyDrive closed 4 years ago

PollyDrive commented 5 years ago
telegraf error undefined undefined Error: next(ctx) called with invalid context
    at execute (/Users/polly/Web/activecollab-telegram-bot/node_modules/telegraf-inline-menu/node_modules/telegraf/composer.js:303:33)
    at /Users/polly/Web/activecollab-telegram-bot/node_modules/telegraf-inline-menu/node_modules/telegraf/composer.js:300:14
    at execute (/Users/polly/Web/activecollab-telegram-bot/node_modules/telegraf/composer.js:315:13)
    at Promise.resolve.handler (/Users/polly/Web/activecollab-telegram-bot/node_modules/telegraf/composer.js:315:49)
    at execute (/Users/polly/Web/activecollab-telegram-bot/node_modules/telegraf/composer.js:315:13)
    at Promise.resolve.handler (/Users/polly/Web/activecollab-telegram-bot/node_modules/telegraf/composer.js:315:49)
    at /Users/polly/Web/activecollab-telegram-bot/node_modules/telegraf/session.js:24:12
    at execute (/Users/polly/Web/activecollab-telegram-bot/node_modules/telegraf/composer.js:315:13)
    at Promise.resolve.handler (/Users/polly/Web/activecollab-telegram-bot/node_modules/telegraf/composer.js:315:49)
    at /Users/polly/Web/activecollab-telegram-bot/node_modules/telegraf/composer.js:116:56
alirezaac commented 5 years ago

upgrading telegraf package fixed mine

EdJoPaTo commented 5 years ago

based on PollyDrive/activecollab-telegram-bot package.json there is already the latest version of telegraf used (0.26.0 at the moment).

I am not sure what happened for this error to occur? For example what kind of button was pressed?

alirezaac commented 5 years ago

I don't get it from pressing buttons it's from start at init and when I upgraded telegraf it worked properly but today I wanted to reproduce it so I tested your example using npm and get the above error and when I upgrade telegraf using yarn it gets fixed

"@types/node@^10.1.2":
  version "10.12.18"
  resolved "https://registry.yarnpkg.com/@types/node/-/node-10.12.18.tgz#1d3ca764718915584fcd9f6344621b7672665c67"

debug@^4.0.1:
  version "4.1.1"
  resolved "https://registry.yarnpkg.com/debug/-/debug-4.1.1.tgz#3b72260255109c6b589cee050f1d516139664791"
  dependencies:
    ms "^2.1.1"

ms@^2.1.1:
  version "2.1.1"
  resolved "https://registry.yarnpkg.com/ms/-/ms-2.1.1.tgz#30a5864eb3ebb0a66f2ebe6d727af06a09d86e0a"

node-fetch@^2.2.0:
  version "2.3.0"
  resolved "https://registry.yarnpkg.com/node-fetch/-/node-fetch-2.3.0.tgz#1a1d940bbfb916a1d3e0219f037e89e71f8c5fa5"

sandwich-stream@^2.0.1:
  version "2.0.2"
  resolved "https://registry.yarnpkg.com/sandwich-stream/-/sandwich-stream-2.0.2.tgz#6d1feb6cf7e9fe9fadb41513459a72c2e84000fa"

telegraf-inline-menu@^3.2.2:
  version "3.2.2"
  resolved "https://registry.yarnpkg.com/telegraf-inline-menu/-/telegraf-inline-menu-3.2.2.tgz#ae3d2be2003117d8cfdba910b61935f8197ce01e"
  dependencies:
    telegraf "^3.26.0"

telegraf@^3.26.0:
  version "3.26.0"
  resolved "https://registry.yarnpkg.com/telegraf/-/telegraf-3.26.0.tgz#6102280c7971431a8a8a96fe0502285cc1a223c9"
  dependencies:
    "@types/node" "^10.1.2"
    debug "^4.0.1"
    node-fetch "^2.2.0"
    sandwich-stream "^2.0.1"
    telegram-typings "^3.6.0"

telegram-typings@^3.6.0:
  version "3.6.1"
  resolved "https://registry.yarnpkg.com/telegram-typings/-/telegram-typings-3.6.1.tgz#1288d547f8694b61f1c01c2993e295f3114d9e25"
EdJoPaTo commented 5 years ago

I had no luck with recreating it. I simply generated a new project, installed telegraf-inline-menu and ran a copy of example.js.

I also used older versions of telegraf and older versions of telegraf-inline-menu without any errors.

I doubt it is a startup error as on the startup of telegraf-inline-menu no telegraf is involved. I assume there was a message that was not yet handled before the start so it happened while handling the first updates (after bot.startPolling() was called).

Any ideas how to recreate this error?

alirezaac commented 5 years ago

well, I've tested it on other machines, it worked fine so I Thought it was related to npm and a reinstall fixed it

EdJoPaTo commented 5 years ago

I just close this as it does not seem to be reproducible with up to date Telegraf versions.

lamuertepeluda commented 4 years ago

I still have encountered this problem

package.json

    "telegraf": "^3.35.0",
    "telegraf-inline-menu": "^4.0.0",

package-lock.json

    "telegraf": {
          "version": "3.35.0",
          ...
      }
     ...
    "telegraf-inline-menu": {
      "version": "4.0.0",
      "resolved": "https://registry.npmjs.org/telegraf-inline-menu/-/telegraf-inline-menu-4.0.0.tgz",
      "integrity": "sha512-1tEL9+xfq9/HA8pD0XebfQeqKg6+aqqtlBck/GGXxK/BrA1L15Ou8z7mXnAI9lVdrFWuMVguG2sZpiwpAviFYw=="
    },
lamuertepeluda commented 4 years ago

In my setup, a typescript project with nestjs + other middlewares it still breaks with this very same error. However, executing the example.js or the example.ts alone works... 🤔

EdJoPaTo commented 4 years ago

I have multiple bots running with v4.0.0 without any problems. Various telegraf versions worked for me. I have no idea how to reproduce it currently… 🤔

lamuertepeluda commented 4 years ago

@EdJoPaTo I'm really sorry that I had you re-open this issue: I think I found out the problem! I had multiple instances of Telegraf (with the same version 3.35.0).

I was contributing to https://github.com/bukhalo/nestjs-telegraf and so I installed it in my project via npm i ../nestjs-telegraf instead of having it packed with npm pack.
So I had 2 copies of the Telegraf library being called from 2 different node_modules folders, thus invalidating the bot context since the menu were registered to a different instance than the other middlewares I was using. I notice this path difference quite late when looking in the debugger inspector. I'm glad I found it finally out, but I feel also a bit dumb.

EdJoPaTo commented 4 years ago

Don’t feel dumb :) It took time so it’s nothing obvious. Also something like that occurred to others before without any explanation why. Maybe it helps others to prevent mistakes like that in the future. Thanks for sharing! :)