UNPKG

speedybot

Version:

<p align="center"> <a href="https://github.com/valgaze/speedybot"> <img src="https://img.shields.io/npm/v/speedybot.svg" /> </a> <a href="https://github.com/valgaze/speedybot"> <img src="https://img.shields.io/npm/dm/speedybot.svg" /> </a>

295 lines (294 loc) 7.66 kB
import { SpeedyCard, AbbreviatedSpeedyCard } from "./cards"; export declare type SpeedyConfig = Partial<{ allowedEmails: string[]; }>; export declare type SpeedyError = { e: unknown; message: string; status?: string | number; roomId?: string; }; export declare type Card = { type: string; body: unknown[]; actions?: any[]; $schema: string; version: string; }; export declare type Message = string | number | Card | SpeedyCard; export declare type SpeedyFile = { url: string; name: string; extension: string; contentType: string; bytes: number; }; export declare type SpeedyFileUtils = SpeedyFile & { getData<T = unknown>(): Promise<T>; }; export declare type MessageTypes = "card" | "file" | "text"; interface commonData { next: boolean; end: boolean; messageType: "card" | "file" | "text"; id: string; author: { domain: string; email: string; id: string; org: string; name: string; type: "person" | "bot" | "appuser"; profilePic: string; }; msg: { parentId?: string; roomId: string; roomType: string; mentionedPeople: string[]; }; ctx: { [key: string]: string | number | boolean; }; } export declare type EventTypes = "text" | "file" | "card"; export declare type AttachedData = { [key: string]: boolean | number | string | Record<string, any> | AttachedData; }; interface CardData<T> extends commonData { messageType: MessageTypes; data?: T; file?: SpeedyFileUtils; text?: string; } interface TextData<T> extends commonData { messageType: MessageTypes; data?: T; file?: SpeedyFileUtils; text: string; } interface FileData<T> extends commonData { messageType: MessageTypes; data?: T; file: SpeedyFileUtils; text?: string; } export declare type IncomingItem<T> = TextData<T> | FileData<T> | CardData<T>; export declare type Destination = { roomId: string; } | { toPersonEmail: string; } | { toPersonId: string; }; export declare type NestedData = string | number | boolean | AttachedData; export declare type $Magic<T = AttachedData> = { buildDataSnippet(data: any, type?: string): string; debug(): DebugInfo; send(m: Message): Promise<MessageResponse>; reply(message: string): Promise<MessageResponse>; clearScreen(c?: number): Promise<MessageResponse>; fillTemplate(utterances: string[], template: { [key: string]: string | number; }): string; buildDMLink(target: string, label: string): string; card(config?: Partial<AbbreviatedSpeedyCard>): SpeedyCard; edit(m: MessageResponse, e: string): Promise<MessageResponse>; pickRandom<P>(list: P[]): P; pickRandom<P>(min: number, max: number): number; pickRandom<P>(listOrMin: P[] | number, max?: number): P | number; sendFile: <T = unknown>(data: T, fileExtension: string) => Promise<MessageResponse>; getFile(url: string, opts?: { responseType?: "arraybuffer" | "json"; }): Promise<{ getData<T = unknown>(): Promise<T>; url: string; name: string; extension: string; contentType: string; bytes: number; }>; thread(threadData: [string | SpeedyCard, ...string[]] & { length: 1 | 2 | 3 | 4 | 5 | 6; }): any; buildLink(destinationURL: string, label?: string, noBold?: boolean): string; } & IncomingItem<T>; export declare type Middleware<T = AttachedData> = ($: $Magic<T>) => boolean | Promise<boolean>; export declare type MessageResponse = { id: string; roomId: string; roomType: string; text: string; markdown?: string; html?: string; personId: string; personEmail: string; created: string; updated?: string; files?: string[]; }; export declare type DebugInfo = { messageType: string; messageId: string; text: string; hasFile: boolean; data?: unknown; author: { id: string; name: string; email: string; }; msg: { parentId?: string; roomId: string; roomType: string; mentionedPeople: string[]; }; }; export declare type ToMessage = { roomId?: string; parentId?: string; toPersonId?: string; toPersonEmail?: string; text?: string; markdown?: string; files?: string[]; attachments?: { contentType?: string; content?: unknown; }[]; }; export interface Webhook { id: string; name: string; targetUrl: string; resource: string; event: string; orgId: string; createdBy: string; appId: string; ownedBy: string; status: string; created: string; secret?: string; } export declare type Submit_Details<T = object> = { id: string; type: string; messageId: string; inputs: T; personId: string; personEmail: string; roomId: string; created: Date | string; }; export declare type SelfData = { id: string; emails: string[]; phoneNumbers: any[]; displayName: string; nickName: string; userName: string; avatar: string; orgId: string; created: Date; status: string; type: "person" | "bot" | "appuser"; firstName: string; lastName: string; lastModified: Date; lastActivity: string; }; export declare type DeepPartial<T> = { [P in keyof T]?: T[P] extends object ? DeepPartial<T[P]> : T[P]; }; export declare type ENVELOPES = MessageEnvelope | AA_Envelope; export declare type AA_Envelope = { id: string; name: string; targetUrl: string; resource: "attachmentActions"; event: string; orgId: string; createdBy: string; appId: string; ownedBy: string; status: string; created: Date | string; actorId: string; data: { id: string; type: string; messageId: string; personId: string; roomId: string; created: Date | string; }; }; export declare type MessageEnvelope = { id: string; name: string; targetUrl: string; resource: "messages"; event: string; orgId: string; createdBy: string; appId: string; ownedBy: string; status: string; created: Date | string; actorId: string; data: Message_Details; }; export declare type File_Details = Message_Details & { files: string[]; } & { text?: string; }; export declare type Message_Details = { id: string; roomId: string; roomType: string; text: string; personId: string; personEmail: string; html?: string; mentionedPeople?: string[]; created: Date | string; files?: string[]; parentId?: string; }; export declare type RequestOps = { "content-type"?: string; method?: "POST" | "PUT" | "GET" | "DELETE" | "HEAD" | "PATCH"; headers?: any; raw?: boolean; [key: string]: any; }; export declare type CoreMakerequest<T = unknown> = (url: string, body: any, opts: RequestOps) => Promise<T> | T; export declare type StubbedRes<T = unknown> = { headers: { get(q: string): string; }; arrayBuffer<T = any>(): Promise<T>; text(): Promise<string>; json(): Promise<T>; }; export declare type Room_Details = { id: string; title: string; type: string; isLocked: boolean; lastActivity: string; creatorId: string; created: string; ownerId: string; isPublic: boolean; isReadOnly: boolean; }; export declare type Chunk<T> = (messageChunk: T[]) => void; export declare type RoomConfig = { type: "group" | "direct"; sortBy: "id" | "lastactivity" | "created"; }; export {};