@elimeleth/vct-flow
Version:
Crea un archivo app.ts, coloca el codigo de abajo alli y luego puedes correrlo con `npx tsx src/app.ts`
184 lines (183 loc) • 5.22 kB
TypeScript
import { type Polka } from 'polka';
import type { PolkaRes, ProviderHttpServer } from './server';
import type { GlobalVendorArgs, ProviderEventTypes } from '../types';
import { EventEmitterClass } from './eventEmmitter';
/**
*
* @param fullHash
* @returns
*/
export declare const getEventName: (fullHash: string) => string | null;
/**
*
* @param name
* @returns
*/
export declare const setEvent: (name: string) => string;
/**
*
* @param phone
* @returns
*/
export declare const removePlus: (phone: string) => string;
export type Vendor<T = {}> = {} & T;
/**
* Abstract class representing a ProviderClass.
* @abstract
* @extends EventEmitterClass
* @implements ProviderHttpServer
* @typeparam V - Type parameter for vendor.
*/
declare abstract class ProviderClass<V = any> extends EventEmitterClass<ProviderEventTypes> implements ProviderHttpServer {
/**
* Global arguments for vendor.
* @abstract
* @type {GlobalVendorArgs}
*/
abstract globalVendorArgs: GlobalVendorArgs;
/**
* Vendor instance.
* @type {Vendor<V>}
*/
vendor: Vendor<V>;
/**
* HTTP server instance.
* @type {Polka}
*/
server: Polka;
/**
* Bot name identifier.
* @type {string}
*/
idBotName: string;
/**
* Context bot identifier.
* @type {string}
*/
idCtxBot: string;
/**
* Constructs a ProviderClass instance.
*/
constructor();
/**
* Abstract method to be executed before http initialization.
* @protected
* @abstract
*/
protected abstract beforeHttpServerInit(): void;
/**
* Abstract method to be executed after http initialization.
* @protected
* @abstract
*/
protected abstract afterHttpServerInit(): void;
/**
* Abstract method to define bus events.
* @protected
* @abstract
* @returns {Array<{ event: string; func: Function }>} Array of event definitions.
*/
protected abstract busEvents(): Array<{
event: string;
func: Function;
}>;
/**
* Abstract method to initialize vendor.
* @protected
* @abstract
* @returns {Promise<any>} A promise indicating the completion of vendor initialization.
*/
protected abstract initVendor(): Promise<any>;
/**
* Abstract method to send a message.
* @public
* @abstract
* @template K
* @param {string} userId - User identifier.
* @param {*} message - Message to be sent.
* @param {*} [args] - Additional arguments.
* @returns {Promise<K>} A promise resolving to the sent message.
*/
abstract sendMessage<K = any>(userId: string, message: any, args?: any): Promise<K>;
get client(): any;
typing(ctx: any): Promise<any>;
recording(ctx: any): Promise<any>;
/**
* Abstract method to save a file.
* @public
* @abstract
* @param {*} ctx - Context information.
* @param {{ path: string }} [options] - File save options.
* @returns {Promise<string>} A promise resolving to the path of the saved file.
*/
abstract saveFile(ctx: any, options?: {
path: string;
}): Promise<string>;
/**
* Listen on vendor events.
* @protected
* @param {{ on: any, [key: string]: any }} vendor - Vendor instance.
* @returns {void}
*/
protected listenOnEvents(vendor: Vendor<any>): void;
/**
* Start the HTTP server.
* @public
* @param {BotCtxMiddleware} vendor - Bot context middleware.
* @param {(arg?: any) => void} [cb=() => null] - Callback function.
* @returns {void}
*/
start(vendor: any, cb?: (arg?: any) => void): void;
/**
* Stop the HTTP server.
* @public
* @returns {Promise<void>} A promise indicating the completion of server shutdown.
*/
stop(): Promise<void>;
/**
* Handle context middleware.
* @public
* @param {Function} ctxPolka - Context polka function.
* @returns {Function} Request handler function.
*/
inHandleCtx<T extends Pick<ProviderClass<V>, 'sendMessage'> & {
provider: V;
}>(ctxPolka: (bot: T, req: Request, res: PolkaRes) => Promise<void>): (...args: any[]) => any;
/**
* Trigger send inside event
* @param payload
*/
dispatchInside(payload: {
body: string;
name: string;
from: string;
}): void;
/**
* Get list of routes registered on the server.
* @public
* @param {Polka} app - Polka application instance.
* @returns {string[]} Array of route definitions.
*/
getListRoutes(app: Polka): string[];
/**
* Build the HTTP server.
* @public
* @returns {Polka} Polka instance.
*/
buildHTTPServer(): Polka;
/**
* Get instance of the vendor.
* @public
* @returns {Vendor} Vendor instance.
*/
getInstance(): Vendor;
/**
* Initialize HTTP server and vendor.
* @public
* @param {number} port - Port number.
* @param {Pick<BotCtxMiddlewareOptions, 'blacklist'>} opts - Middleware options.
* @returns {void}
*/
initAll: (port: number, opts?: any) => void;
}
export { ProviderClass };