webhookCallback
Creates a callback function that you can pass to a web framework (such as express) if you want to run your bot via webhooks. Use it like this:
ts
const app = express() // or whatever you're using
const bot = new Bot('<token>')
app.use(webhookCallback(bot, 'express'))
Confer the grammY documentation to read more about how to run your bot with webhooks.
// Overload 1
webhookCallback<C extends Context = Context>(
bot: Bot<C>,
adapter?: SupportedFrameworks | FrameworkAdapter,
onTimeout?: WebhookOptions["onTimeout"],
timeoutMilliseconds?: WebhookOptions["timeoutMilliseconds"],
secretToken?: WebhookOptions["secretToken"],
): (...args: any[]) => any;
// Overload 2
webhookCallback<C extends Context = Context>(
bot: Bot<C>,
adapter?: SupportedFrameworks | FrameworkAdapter,
webhookOptions?: WebhookOptions,
): (...args: any[]) => any;
Overload 1
Type Parameters
C
Parameters
bot
The bot for which to create a callback
adapter
adapter?: SupportedFrameworks | FrameworkAdapter
An optional string identifying the framework (default: ‘express’)
onTimeout
onTimeout?: WebhookOptions["onTimeout"]
An optional strategy to handle timeouts (default: ‘throw’)
timeoutMilliseconds
timeoutMilliseconds?: WebhookOptions["timeoutMilliseconds"]
An optional number of timeout milliseconds (default: 10_000)
secretToken
secretToken?: WebhookOptions["secretToken"]
Return Type
(...args: any[]) => any
// Overload 1
webhookCallback<C extends Context = Context>(
bot: Bot<C>,
adapter?: SupportedFrameworks | FrameworkAdapter,
webhookOptions?: WebhookOptions,
): (...args: any[]) => any;
// Overload 2
webhookCallback<C extends Context = Context>(
bot: Bot<C>,
adapter?: SupportedFrameworks | FrameworkAdapter,
webhookOptions?: WebhookOptions,
): (...args: any[]) => any;
Overload 2
Type Parameters
C
Parameters
bot
adapter
adapter?: SupportedFrameworks | FrameworkAdapter
webhookOptions
webhookOptions?: WebhookOptions
Return Type
(...args: any[]) => any
// Overload 1
webhookCallback<C extends Context = Context>(
bot: Bot<C>,
adapter: SupportedFrameworks | FrameworkAdapter,
onTimeout: WebhookOptions | WebhookOptions["onTimeout"],
timeoutMilliseconds: WebhookOptions["timeoutMilliseconds"],
secretToken?: WebhookOptions["secretToken"],
);
// Overload 2
webhookCallback<C extends Context = Context>(
bot: Bot<C>,
adapter?: SupportedFrameworks | FrameworkAdapter,
webhookOptions?: WebhookOptions,
): (...args: any[]) => any;
Overload 3
Type Parameters
C
Parameters
bot
adapter
adapter: SupportedFrameworks | FrameworkAdapter
onTimeout
onTimeout: WebhookOptions | WebhookOptions["onTimeout"]
timeoutMilliseconds
timeoutMilliseconds: WebhookOptions["timeoutMilliseconds"]
secretToken
secretToken?: WebhookOptions["secretToken"]