@kgdata/use-chat
Version:
use-chat
41 lines (40 loc) • 1.68 kB
TypeScript
import type { FC } from 'react';
import { IStorage } from '../interface/IStorage';
import { ChatMessage } from '../types/ChatMessage';
declare type ChatRequestType = 'http' | 'ws';
declare type ChatContextProps = {
messagesList: ChatMessage[];
chatRequestType: ChatRequestType;
sendMessage: (params: any) => void;
setChatRequestType: (chatType: ChatRequestType) => void;
addMessageList: (message: ChatMessage | ChatMessage[], addType?: string) => void;
upDateMessageItem: (message: ChatMessage) => void;
getMessageItem: (key: string, callback: (item: ChatMessage) => void) => void;
setMessageList: (messageList: ChatMessage[]) => void;
removeMessageList: (keys: string | string[]) => void;
handleRequest: (params: ChatMessage, service: (params: any) => Promise<any>, callback: (res: any) => void) => void;
};
declare type WsServiceRes = {
send: (params: any) => void;
close: () => void;
};
declare type ChatProviderConfig = {
initChatRequestType: ChatRequestType;
requests: {
send: (params: any) => Promise<any>;
[key: string]: (params: any) => Promise<any>;
};
wsRequest?: (cxt: Pick<ChatContextProps, 'addMessageList' | 'upDateMessageItem'>) => WsServiceRes;
};
declare type ChatProviderProps = {
config: ChatProviderConfig;
storage: IStorage;
};
declare type UseStoragProps = {
initMessageList?: ChatMessage[];
};
declare type UseStorage = (param: UseStoragProps) => void;
export declare const useChat: () => ChatContextProps;
export declare const useStorage: UseStorage;
export declare const ChatProvider: FC<ChatProviderProps>;
export {};