UNPKG

vercel-grammy

Version:
105 lines 3.04 kB
import type { Bot, RawApi } from 'grammy'; import type { Other } from 'grammy/out/core/api'; import type { WebhookOptions } from 'grammy/out/convenience/webhook'; /** * Options for hostname */ export interface OptionsForHost { /** * Optional headers from incoming request */ headers?: Headers | Record<string, string>; /** * Optional header name which contains the hostname */ header?: string; /** * Optional fallback hostname */ fallback?: string; } /** * This method generates a hostname from the options passed to it * @returns Target hostname */ export declare function getHost({ fallback, headers, header, }?: OptionsForHost): string; /** * Options for URL */ export interface OptionsForURL extends OptionsForHost { /** * Optional hostname without protocol */ host?: string; /** * Path to a function that receives updates */ path?: string; } /** * This method generates a URL from the options passed to it * @returns Target URL */ export declare function getURL({ host, path, ...other }?: OptionsForURL): string; /** * Options for webhooks */ export interface OptionsForWebhook extends OptionsForURL, Other<RawApi, 'setWebhook', 'url'> { /** * Optional URL for webhooks */ url?: string; /** * Optional strategy for handling errors */ onError?: 'throw' | 'return'; /** * Optional list of environments where this method allowed */ allowedEnvs?: string[]; /** * An optional string to compare to X-Telegram-Bot-Api-Secret-Token */ secretToken?: Other<RawApi, 'setWebhook', 'url'>['secret_token']; } /** * Callback factory for grammY `bot.api.setWebhook` method * @returns Target callback method */ export declare function setWebhookCallback(bot: Bot, { allowedEnvs, secretToken: secret_token, onError, fallback, header, host, path, url, ...other }?: OptionsForWebhook): (req: Request) => Promise<Response>; /** * Options for stream */ export interface OptionsForStream extends WebhookOptions { /** * Optional content for chunks */ chunk?: string; /** * Optional interval for writing chunks to stream */ intervalMilliseconds?: number; } /** * Callback factory for streaming webhook response * @returns Target callback method */ export declare function webhookStream(bot: Bot, { intervalMilliseconds, timeoutMilliseconds, chunk, ...other }?: OptionsForStream): (req: Request) => Response; /** * Parameters from `JSON.stringify` method */ export type StringifyJSON = Parameters<typeof JSON.stringify>; /** * Options for JSON response * @public */ export interface OptionsForJSON extends ResponseInit { replacer?: StringifyJSON[1]; space?: StringifyJSON[2]; } /** * This method generates Response objects for JSON * @returns Target JSON Response */ export declare function jsonResponse(value: any, { space, status, replacer, statusText, headers }?: OptionsForJSON): Response; //# sourceMappingURL=index.d.mts.map