UNPKG

@humany/widget-chat

Version:

Humany Widget Chat Platform

71 lines 2.58 kB
import { TextManager } from '@humany/utils'; import { Container, EventManager } from '@webprovisions/platform'; import { Agent, Chat, User } from '../chat-components'; import { DataWriter } from '../data'; import { PLATFORM_STATE, PlatformSettings, SubmissionData } from '../typings'; /** * Platform for handling a Chat session within a Humany Widget. */ export default class ChatPlatform { container: Container; private inputChangeTimeout; private componentResolvers; settings: PlatformSettings; events: EventManager; texts: TextManager; chat: Chat | null; agent: Agent | null; user: User | null; writer: DataWriter | null; state: PLATFORM_STATE; constructor(container: Container, settings: PlatformSettings); /** * Registers component resolvers (Header, MessageBox) * and creates chat components (Chat, Agent, User). */ initialize(): Promise<PLATFORM_STATE>; /** * Initializes the Chat Platform and returns its state. */ connect(): Promise<PLATFORM_STATE>; /** * Initializes the Chat Platform, * and dispatches the 'chat:reconnect' event. */ reconnect(): Promise<PLATFORM_STATE>; /** * Removes registered component resolvers (Header, MessageBox), * destroys chat components (Chat, Agent, User), * dispatches the 'chat:disconnect' event * and disconnects the Chat Platform. */ disconnect(): Promise<PLATFORM_STATE>; /** * Prompts user using confirm whether or not to end the chat session using. */ handleEndChat(): void; /** * Dispatches the 'chat:user-submit' event with data. * Clears the input change timer and * dispatches the 'chat:user-typing' event with empty text. * @param data Submitted chat message, html, text and files. */ handleChatSubmit: (data: SubmissionData) => void; /** * After a 400ms delay, if the Chat Platform is connected, * triggers the 'chat:user-typing' event with current text input value. * If called during the last 400ms, the input change timer will reset. * @param text Current text input value. */ handleInputChange(text: string): void; /** * Gets the widget routing service from the widget container * and navigates to the 'chat'-route. */ handleRouting(): Promise<void>; /** * Pushing the pending chat messages to the data source stream. */ commit(): Promise<void>; } //# sourceMappingURL=platform.d.ts.map