Skip to content

Commit

Permalink
feat: support nhttp for webhook handler (#494)
Browse files Browse the repository at this point in the history
Co-authored-by: KnorpelSenf <[email protected]>
  • Loading branch information
shevernitskiy and KnorpelSenf authored Oct 14, 2023
1 parent 34f0de1 commit 469a736
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
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 @@ export class Bot<
) {
if (this.me === undefined) {
throw new Error(
"Bot not initialized! Either call `await bot.init()`, \
"Bot not initialized! Either call `await bot.init()`, \
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 @@ const worktop: FrameworkAdapter = (req, res) => ({
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),
});

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

0 comments on commit 469a736

Please sign in to comment.