Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support nhttp for webhook handler #494

Merged
merged 3 commits into from
Oct 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/bot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,7 @@
) {
if (this.me === undefined) {
throw new Error(
"Bot not initialized! Either call `await bot.init()`, \
"Bot not initialized! Either call `await bot.init()`, \

Check warning on line 333 in src/bot.ts

View check run for this annotation

Codecov / codecov/patch

src/bot.ts#L333

Added line #L333 was not covered by tests
or directly set the `botInfo` option in the `Bot` constructor to specify \
a known bot info object.",
);
Expand Down
10 changes: 10 additions & 0 deletions src/convenience/frameworks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -340,6 +340,15 @@
unauthorized: () => res.send(401, WRONG_TOKEN_ERROR),
});

/** nhttp web framework */
const nhttp: FrameworkAdapter = (rev) => ({
update: rev.body,
header: rev.headers.get(SECRET_HEADER) || undefined,
end: () => rev.response.sendStatus(200),
respond: (json) => rev.response.status(200).send(json),
unauthorized: () => rev.response.status(401).send(WRONG_TOKEN_ERROR),
});

Check warning on line 350 in src/convenience/frameworks.ts

View check run for this annotation

Codecov / codecov/patch

src/convenience/frameworks.ts#L343-L350

Added lines #L343 - L350 were not covered by tests

// Please open a PR if you want to add another adapter
export const adapters = {
express,
Expand All @@ -359,4 +368,5 @@
"cloudflare-mod": cloudflareModule,
hono,
worktop,
nhttp,
};
Loading