grammyjs / grammY

The Telegram Bot Framework.
https://grammy.dev
MIT License
2.17k stars 110 forks source link

Fix hono adapter #528

Closed joshgillies closed 7 months ago

joshgillies commented 7 months ago

Experiencing the following errors when using Hono and grammY.

2024-02-10T06:11:33.126 app[90806145c55418] syd [info] 123 | /** hono web framework */

2024-02-10T06:11:33.126 app[90806145c55418] syd [info] 124 | const hono = (ctx) => {

2024-02-10T06:11:33.126 app[90806145c55418] syd [info] 125 | let resolveResponse;

2024-02-10T06:11:33.126 app[90806145c55418] syd [info] 126 | return {

2024-02-10T06:11:33.126 app[90806145c55418] syd [info] 127 | update: ctx.req.json(),

2024-02-10T06:11:33.126 app[90806145c55418] syd [info] 128 | header: ctx.req.headers.get(SECRET_HEADER) || undefined,

2024-02-10T06:11:33.126 app[90806145c55418] syd [info] ^

2024-02-10T06:11:33.126 app[90806145c55418] syd [info] TypeError: undefined is not an object (evaluating 'ctx.req.headers.get')

2024-02-10T06:11:33.126 app[90806145c55418] syd [info] at hono (/app/node_modules/grammy/out/convenience/frameworks.js:128:17)

2024-02-10T06:11:33.126 app[90806145c55418] syd [info] at /app/node_modules/grammy/out/convenience/webhook.js:23:79

2024-02-10T06:11:33.126 app[90806145c55418] syd [info] at /app/node_modules/grammy/out/convenience/webhook.js:22:22

2024-02-10T06:11:33.126 app[90806145c55418] syd [info] at dispatch (/app/node_modules/hono/dist/hono-base.js:213:15)

2024-02-10T06:11:33.127 app[90806145c55418] syd [info] TypeError: Request aborted

2024-02-10T06:11:33.127 app[90806145c55418] syd [info] code: "ABORT_ERR"

The fix ensures we correctly access the incoming header via the correct Hono API: c.req.header.

codecov[bot] commented 7 months ago

Codecov Report

Attention: 2 lines in your changes are missing coverage. Please review.

Comparison is base (bd67f5b) 46.05% compared to head (659ee31) 46.06%.

Files Patch % Lines
src/convenience/frameworks.ts 0.00% 2 Missing :warning:
Additional details and impacted files ```diff @@ Coverage Diff @@ ## main #528 +/- ## ======================================= Coverage 46.05% 46.06% ======================================= Files 19 19 Lines 6051 6050 -1 Branches 320 320 ======================================= Hits 2787 2787 + Misses 3261 3260 -1 Partials 3 3 ```

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

KnorpelSenf commented 7 months ago

@all-contributors add @joshgillies for this code

allcontributors[bot] commented 7 months ago

@KnorpelSenf

I've put up a pull request to add @joshgillies! :tada: