Closed dandaka closed 1 year ago
You need to import from grammy/web
. A guide for this is in the works. You can look at a preview of it at https://github.com/grammyjs/website/pull/587#issuecomment-1407387869
Hey @KnorpelSenf, thank you for helping out. Do you think it is possible to use grammyjs with a router library? The most popular on Workers is this one.
https://github.com/kwhitley/itty-router
I was trying to call webhookCallback(bot, "cloudflare") with little success. Sorry if my question is too noob.
Yes, there is a way to do this. I'm not familiar with that project. Can you share the code that you used when you tried to integrate the two libraries?
This is the original way your documentation suggests using Grammy, it works on Workers just fine https://github.com/dandaka/workers-grammy/blob/main/src/index.ts
This is a version with a router that does not work https://github.com/dandaka/workers-grammy/blob/main/src/index-router.ts
I assume there should be a way to link 2 different event listeners, but could not find a way yet
Also when I call
webhookCallback(bot, "cloudflare");
I get the following TS error in my IDE:
No overload matches this call.
Overload 1 of 2, '(bot: Bot<Context, Api<RawApi>>, adapter?: "callback" | "express" | "koa" | "fastify" | "std/http" | "oak" | "hono" | "http" | "https" | "aws-lambda" | "azure" | "next-js" | "sveltekit" | FrameworkAdapter | undefined, onTimeout?: "throw" | ... 2 more ... | undefined, timeoutMilliseconds?: number | undefined, secretToken?: string | undefined): (...args: any[]) => any', gave the following error.
Argument of type '"cloudflare"' is not assignable to parameter of type '"callback" | "express" | "koa" | "fastify" | "std/http" | "oak" | "hono" | "http" | "https" | "aws-lambda" | "azure" | "next-js" | "sveltekit" | FrameworkAdapter | undefined'.
Overload 2 of 2, '(bot: Bot<Context, Api<RawApi>>, adapter?: "callback" | "express" | "koa" | "fastify" | "std/http" | "oak" | "hono" | "http" | "https" | "aws-lambda" | "azure" | "next-js" | "sveltekit" | FrameworkAdapter | undefined, webhookOptions?: WebhookOptions | undefined): (...args: any[]) => any', gave the following error.
Argument of type '"cloudflare"' is not assignable to parameter of type '"callback" | "express" | "koa" | "fastify" | "std/http" | "oak" | "hono" | "http" | "https" | "aws-lambda" | "azure" | "next-js" | "sveltekit" | FrameworkAdapter | undefined'.
The code runs fine on Workers thou. Should I update the grammY library version?
Using the latest version is always a good idea.
I'm not sure why the type error happens, I'll ask the person who contributed the adapter about that.
Thanks for sharing the code snippets. It looks to me like the router expects handlers in the form of (req: Request) => Promise<Response>
. Coincidentally, this is also the function signature that event handlers in worker modules expect. Can you try using the "cloudflare-mod"
adapter and report back if that does the job? It isn't documented at https://grammy.dev/guide/deployment-types.html#web-framework-adapters yet but I'll include your experience when I get to edit the page. (Or do you feel like adding it to the docs if you can make it work?)
I have managed to launch Grammy with honojs/hono
router, works great.
How to reproduce
If I add node_compat = true, I get another error