UNPKG

vk-io

Version:

Modern VK API SDK for Node.js

50 lines (49 loc) 1.73 kB
/// <reference types="node" /> /// <reference types="node" /> /// <reference types="node" /> import { TlsOptions } from 'tls'; import { Server as HTTPSServer } from 'https'; import { Server as HttpServer, IncomingMessage, ServerResponse } from 'http'; import { API } from '../../api'; import { IUpdatesOptions } from '../updates'; export interface IWebhookTransportStartOptions { tls?: TlsOptions; path?: string; port?: number; host?: string; next?: (req: IncomingMessage, res: ServerResponse) => unknown; } export type WebhookTransportCallback = (req: IncomingMessage, res: ServerResponse, next?: (err?: Error) => unknown) => unknown; export type WebhookTransportKoaCallback = (context: { request: { body: Record<string, string>; }; body: object; status: number; set(key: string, value: string): unknown; }, next: () => unknown) => unknown; export declare class WebhookTransport { started: boolean; webhookHandler: (update: object) => unknown; protected webhookServer?: HttpServer | HTTPSServer; protected api: API; private options; constructor({ api, ...options }: Omit<IUpdatesOptions, 'upload'>); /** * Starts the webhook server */ start({ path, tls, host, port: customPort, next, }?: IWebhookTransportStartOptions): Promise<void>; /** * Stopping gets updates */ stop(): Promise<void>; /** * Returns webhook callback like http[s] or express */ getWebhookCallback(path?: string): WebhookTransportCallback; subscribe(handler: (update: object) => unknown): void; /** * Returns the middleware for the webhook under koa */ getKoaWebhookMiddleware(): WebhookTransportKoaCallback; }