Skip to content

Commit

Permalink
feat: add stdHttp (deno) adapter
Browse files Browse the repository at this point in the history
  • Loading branch information
kravetsone committed May 15, 2024
1 parent 1e30322 commit ff58d20
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/webhook/adapters.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
import type { Buffer } from "node:buffer";
import type { TelegramUpdate } from "@gramio/types";
import { Response } from "undici";
import type { MaybePromise } from "../types";

const SECRET_TOKEN_HEADER = "X-Telegram-Bot-Api-Secret-Token";

export interface FrameworkHandler {
update: MaybePromise<TelegramUpdate>;
header?: string;
response?: () => unknown;
}
export type FrameworkAdapter = (...args: any[]) => FrameworkHandler;

Expand Down Expand Up @@ -43,4 +45,9 @@ export const frameworks = {
}),
header: req.headers[SECRET_TOKEN_HEADER.toLowerCase()],
}),
stdHTTP: (req) => ({
update: req.json(),
header: req.headers.get(SECRET_TOKEN_HEADER),
response: () => new Response(null, { status: 200 }),
}),
} satisfies Record<string, FrameworkAdapter>;

0 comments on commit ff58d20

Please sign in to comment.