@botonic/react
Version:
Build Chatbots using React
115 lines (114 loc) • 3.96 kB
TypeScript
import type { BotRequest as CoreBotRequest, Input as CoreInput, InputType as CoreInputType, Plugin as CorePlugin, Route as CoreRoute, Routes as CoreRoutes, Session as CoreSession, SessionUser as CoreSessionUser } from '@botonic/core/lib/esm/models/legacy-types';
import React from 'react';
import { BlockInputOption, ButtonProps, CoverComponentOptions, PersistentMenuTheme, ReplyProps, ThemeProps, WebchatSettingsProps, Webview } from './components/index-types';
import { WebchatState } from './webchat';
import { WebchatApp } from './webchat-app';
/**
* See @botonic/core's Response for the description of the Response's semantics*/
export interface BotResponse extends CoreBotRequest {
response: [React.ReactNode];
}
export interface Route extends CoreRoute {
action?: React.ComponentType<any>;
retryAction?: React.ComponentType<any>;
}
export type Routes = CoreRoutes<Route>;
export interface ActionRequest {
defaultDelay: number;
defaultTyping: number;
input: CoreInput;
lastRoutePath: string;
params: {
[key: string]: string;
};
plugins: {
[id: string]: CorePlugin;
};
session: CoreSession;
}
export interface RequestContextInterface extends ActionRequest {
getString: (stringId: string) => string;
setLocale: (locale: string) => string;
}
export interface CustomMessageType {
customTypeName: string;
}
export interface WebchatArgs {
blockInputs?: BlockInputOption[];
coverComponent?: CoverComponentOptions;
defaultDelay?: number;
defaultTyping?: number;
enableAnimations?: boolean;
enableAttachments?: boolean;
enableEmojiPicker?: boolean;
enableUserInput?: boolean;
shadowDOM?: boolean | (() => boolean);
hostId?: string;
getString?: (stringId: string, session: CoreSession) => string;
onClose?: (app: WebchatApp, args: any) => void;
onInit?: (app: WebchatApp, args: any) => void;
onMessage?: (app: WebchatApp, message: WebchatMessage) => void;
onOpen?: (app: WebchatApp, args: any) => void;
onConnectionChange?: (app: WebchatApp, isOnline: boolean) => void;
persistentMenu?: PersistentMenuTheme;
storage?: Storage | null;
storageKey?: any;
theme?: ThemeProps;
}
export interface WebchatAppArgs {
appId?: string;
visibility?: () => boolean;
}
export interface WebchatMessage {
ack: 0 | 1;
buttons: ButtonProps[];
data: any;
delay: number;
display: boolean;
from: 'user' | 'bot';
id: string;
markdown: boolean;
replies: ReplyProps[];
timestamp: string;
type: CoreInputType;
typing: number;
}
export interface OnUserInputArgs {
input: CoreInput;
lastRoutePath?: string;
session?: CoreSession;
user: CoreSessionUser;
}
export interface OnStateChangeArgs {
messagesJSON: WebchatMessage[];
user: CoreSessionUser;
}
export interface MessageInfo {
data: any | 'typing_on';
id: string;
type: 'update_webchat_settings' | 'sender_action';
}
export interface Event {
action?: 'update_message_info';
isError?: boolean;
message?: MessageInfo;
}
export interface WebchatContextProps {
addMessage: (message: WebchatMessage) => void;
closeWebview: () => void;
getThemeProperty: (property: string, defaultValue?: string | boolean) => any;
openWebview: (webviewComponent: Webview) => void;
resolveCase: () => void;
sendAttachment: (attachment: File) => void;
sendInput: (input: CoreInput) => void;
sendPayload: (payload: string) => void;
sendText: (text: string, payload?: string) => void;
theme: ThemeProps;
toggleWebchat: (toggle: boolean) => void;
updateLatestInput: (input: CoreInput) => void;
updateMessage: (message: WebchatMessage) => void;
updateReplies: (replies: boolean) => void;
updateUser: (user: Partial<CoreSessionUser>) => void;
updateWebchatDevSettings: (settings: WebchatSettingsProps) => void;
webchatState: WebchatState;
}