telegram-bot-api-lightweight-client
Version:
Lightweight Telegram Bot API client. Exports only minimal Fetch call. Fully compatible with AWS LLRT.
24 lines (18 loc) • 687 B
text/typescript
let baseUrl: string | undefined = undefined;
export let client_fetch = async <In, Out>(path: string, args: In): Promise<Out> => {
const response = await fetch(`${baseUrl}/${path}`, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify(args),
});
return (await response.json()) as unknown as Out;
};
export const client_setClientToken = (token: string): void => {
baseUrl = `https://api.telegram.org/bot${token}`;
};
export const client_setBaseUrl = (url: string): void => {
baseUrl = url;
};
export const client_setFetch = (customFetch: typeof client_fetch): void => {
client_fetch = customFetch;
};