Skip to content

OutgoingRequests (API Reference)

ts
class OutgoingRequests<TMethod extends RealApiMethodKeys = RealApiMethodKeys>

Type aliases

ts
type RealApiMethodKeys = Methods; // union of all grammY API method names

Request interface

ts
interface Request<TMethod extends Methods = Methods> {
  method: TMethod;
  payload: Payload<TMethod>;
  signal?: AbortSignal;
}

Properties

PropertyTypeDescription
requestsreadonly Request[]All captured requests in order
lengthnumberCount of captured requests

Capture accessors

MethodSignatureDescription
getMethods() => TMethod[]Method names in capture order
getFirst<T>() => Request<T> | nullFirst request
getLast<T>() => Request<T> | nullLast request
getTwoLast<T1,T2>() => [Request<T1>?, Request<T2>?]Last two, oldest first
getThreeLast<T1,T2,T3>() => [Request<T1>?, Request<T2>?, Request<T3>?]Last three
getAll<T1,...>10 overloads returning typed tupleFull store as typed tuple
buildMethods<T>(methods: T[]) => T[]Identity helper for typed method arrays

Mutation

MethodSignatureDescription
push(...requests: Request<TMethod>[]) => thisAppend requests
clear() => thisRemove all captured requests

Error simulation

MethodSignatureDescription
failNext(method, error: GrammyError | GrammyErrorSpec) => thisNext call to method rejects once
failAll(method, error: GrammyError | GrammyErrorSpec) => thisEvery call to method rejects
respondNext(method, payload: unknown) => thisNext call returns custom payload
clearOverrides() => thisRemove all one-shot and sticky overrides

getAll overloads

ts
getAll<T1>(): [Request<T1>?]
getAll<T1, T2>(): [Request<T1>?, Request<T2>?]
getAll<T1, T2, T3>(): [Request<T1>?, Request<T2>?, Request<T3>?]
// ... up to 10 type arguments

See also

Released under the MIT License.