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.
ts
// Overload 1
webhookCallback<C extends Context = Context, A extends FrameworkAdapter | AdapterNames = FrameworkAdapter | AdapterNames>(
bot: Bot<C>,
adapter: A,
webhookOptions?: WebhookOptions,
): (...args: Parameters<ResolveName<A>>) => ReturnType<ResolveName<A>>["handlerReturn"] extends undefined ? Promise<void> : NonNullable<ReturnType<ResolveName<A>>["handlerReturn"]>;
// Overload 2
webhookCallback<C extends Context = Context, A extends FrameworkAdapter | AdapterNames = FrameworkAdapter | AdapterNames>(
bot: Bot<C>,
adapter: A,
onTimeout?: WebhookOptions["onTimeout"],
timeoutMilliseconds?: WebhookOptions["timeoutMilliseconds"],
secretToken?: WebhookOptions["secretToken"],
): (...args: Parameters<ResolveName<A>>) => ReturnType<ResolveName<A>>["handlerReturn"] extends undefined ? Promise<void> : NonNullable<ReturnType<ResolveName<A>>["handlerReturn"]>;
Overload 1
Type Parameters
C
A
ts
A extends FrameworkAdapter | AdapterNames = FrameworkAdapter | AdapterNames
Parameters
bot
The bot for which to create a callback
adapter
ts
adapter: A
An optional string identifying the framework (default: ‘express’)
webhookOptions
ts
webhookOptions?: WebhookOptions
Further options for the webhook setup
Return Type
ts
(...args: Parameters<ResolveName<A>>) => ReturnType<ResolveName<A>>["handlerReturn"] extends undefined ? Promise<void> : NonNullable<ReturnType<ResolveName<A>>["handlerReturn"]>
ts
// Overload 1
webhookCallback<C extends Context = Context, A extends FrameworkAdapter | AdapterNames = FrameworkAdapter | AdapterNames>(
bot: Bot<C>,
adapter: A,
onTimeout?: WebhookOptions["onTimeout"],
timeoutMilliseconds?: WebhookOptions["timeoutMilliseconds"],
secretToken?: WebhookOptions["secretToken"],
): (...args: Parameters<ResolveName<A>>) => ReturnType<ResolveName<A>>["handlerReturn"] extends undefined ? Promise<void> : NonNullable<ReturnType<ResolveName<A>>["handlerReturn"]>;
// Overload 2
webhookCallback<C extends Context = Context, A extends FrameworkAdapter | AdapterNames = FrameworkAdapter | AdapterNames>(
bot: Bot<C>,
adapter: A,
onTimeout?: WebhookOptions["onTimeout"],
timeoutMilliseconds?: WebhookOptions["timeoutMilliseconds"],
secretToken?: WebhookOptions["secretToken"],
): (...args: Parameters<ResolveName<A>>) => ReturnType<ResolveName<A>>["handlerReturn"] extends undefined ? Promise<void> : NonNullable<ReturnType<ResolveName<A>>["handlerReturn"]>;
Overload 2
Type Parameters
C
A
ts
A extends FrameworkAdapter | AdapterNames = FrameworkAdapter | AdapterNames
Parameters
bot
adapter
ts
adapter: A
onTimeout
ts
onTimeout?: WebhookOptions["onTimeout"]
timeoutMilliseconds
ts
timeoutMilliseconds?: WebhookOptions["timeoutMilliseconds"]
secretToken
ts
secretToken?: WebhookOptions["secretToken"]
Return Type
ts
(...args: Parameters<ResolveName<A>>) => ReturnType<ResolveName<A>>["handlerReturn"] extends undefined ? Promise<void> : NonNullable<ReturnType<ResolveName<A>>["handlerReturn"]>
ts
// Overload 1
webhookCallback<C extends Context = Context>(
bot: Bot<C>,
adapter: FrameworkAdapter | AdapterNames,
onTimeout?: WebhookOptions | WebhookOptions["onTimeout"],
timeoutMilliseconds?: WebhookOptions["timeoutMilliseconds"],
secretToken?: WebhookOptions["secretToken"],
);
// Overload 2
webhookCallback<C extends Context = Context, A extends FrameworkAdapter | AdapterNames = FrameworkAdapter | AdapterNames>(
bot: Bot<C>,
adapter: A,
onTimeout?: WebhookOptions["onTimeout"],
timeoutMilliseconds?: WebhookOptions["timeoutMilliseconds"],
secretToken?: WebhookOptions["secretToken"],
): (...args: Parameters<ResolveName<A>>) => ReturnType<ResolveName<A>>["handlerReturn"] extends undefined ? Promise<void> : NonNullable<ReturnType<ResolveName<A>>["handlerReturn"]>;
Overload 3
Type Parameters
C
Parameters
bot
adapter
ts
adapter: FrameworkAdapter | AdapterNames
onTimeout
ts
onTimeout?: WebhookOptions | WebhookOptions["onTimeout"]
timeoutMilliseconds
ts
timeoutMilliseconds?: WebhookOptions["timeoutMilliseconds"]
secretToken
ts
secretToken?: WebhookOptions["secretToken"]