Skip to content

GramIO API Reference / gramio/dist / Hooks / OnApiCall

Type Alias: OnApiCall()<Methods>

OnApiCall<Methods> = (context, next) => Promise<unknown>

Defined in: gramio/index.d.ts:796

Type for onApiCall hook (wrap-style)

This hook wraps the entire API call execution, enabling span creation around API calls for tracing/instrumentation.

Type Parameters

Type ParameterDefault type
Methods extends keyof APIMethodskeyof APIMethods

Parameters

ParameterType
contextOnApiCallContext<Methods>
next() => Promise<unknown>

Returns

Promise<unknown>

Example

typescript
import { Bot } from "gramio";

const bot = new Bot(process.env.TOKEN!).onApiCall(async (context, next) => {
    console.log(`Calling ${context.method}`);
    const result = await next();
    console.log(`${context.method} completed`);
    return result;
});