import { IncomingHttpHeaders } from 'http'; import { JsonObject } from 'type-fest'; import Bot, { OnRequest } from './bot/Bot'; import Context from './context/Context'; import SessionStore from './session/SessionStore'; import { Connector } from './bot/Connector'; import { LineConnectorOptions } from './line/LineConnector'; import { MessengerConnectorOptions } from './messenger/MessengerConnector'; import { SlackConnectorOptions } from './slack/SlackConnector'; import { TelegramConnectorOptions } from './telegram/TelegramConnector'; import { ViberConnectorOptions } from './viber/ViberConnector'; import { WhatsappConnectorOptions } from './whatsapp/WhatsappConnector'; export type Action< C extends Context, P extends Record = {}, RAP extends Record = {} > = ( context: C, props: Props & P ) => void | Action | Promise | void>; export type Props = { next?: Action; error?: Error; }; export type Plugin = (context: C) => void; export enum Channel { Messenger = 'messenger', Line = 'line', Slack = 'slack', Telegram = 'telegram', Viber = 'viber', Whatsapp = 'whatsapp', } export enum SessionDriver { Memory = 'memory', File = 'file', Redis = 'redis', Mongo = 'mongo', } export type SessionConfig = { driver: string; expiresIn?: number; stores: | { memory?: { maxSize?: number; }; file?: { dirname?: string; }; redis?: { port?: number; host?: string; password?: string; db?: number; }; mongo?: { url?: string; collectionName?: string; }; } | { [P in Exclude]?: SessionStore; }; }; type ChannelCommonConfig = { enabled: boolean; path?: string; sync?: boolean; onRequest?: OnRequest; }; export type BottenderConfig = { plugins?: Plugin[]; session?: SessionConfig; initialState?: JsonObject; channels?: | { messenger?: MessengerConnectorOptions & ChannelCommonConfig; line?: LineConnectorOptions & ChannelCommonConfig; telegram?: TelegramConnectorOptions & ChannelCommonConfig; slack?: SlackConnectorOptions & ChannelCommonConfig; viber?: ViberConnectorOptions & ChannelCommonConfig; whatsapp?: WhatsappConnectorOptions & ChannelCommonConfig; } | { [key in Exclude< string, 'messenger' | 'line' | 'telegram' | 'slack' | 'viber' | 'whatsapp' >]?: { connector: Connector; } & ChannelCommonConfig; }; }; export type RequestContext< B extends JsonObject = JsonObject, H extends Record = {} > = { id?: string; method: string; path: string; query: Record; headers: IncomingHttpHeaders & H; rawBody: string; body: B; params: Record; url: string; }; export type Client = object; export { Event } from './context/Event'; export type ChannelBot = { webhookPath: string; bot: Bot; };