UNPKG

@yext/chat-headless

Version:

A state manager library powered by Redux for Yext Chat integrations

82 lines 3.23 kB
import { Message, MessageNotes, MessageResponse, MessageSource } from "@yext/chat-core"; import { ChatClient, ChatHeadless, HeadlessConfig, State, StateListener } from "./models"; import { Store, Unsubscribe } from "@reduxjs/toolkit"; import { EventPayload } from "@yext/analytics"; import { RecursivePartial } from "./models/ChatHeadless"; /** * Concrete implementation of {@link ChatHeadless} * * @internal */ export declare class ChatHeadlessImpl implements ChatHeadless { private config; private chatClient; private botClient; private clients; private stateManager; private analyticsService; private credentialsSessionStorageKey; private isImpressionAnalyticEventSent; /** * Constructs a new instance of the {@link ChatHeadlessImpl} class. * * @internal * * @param config - The configuration for the {@link ChatHeadlessImpl} instance * @param chatClient - An optional override for the default {@link ChatClient} instance */ constructor(config: HeadlessConfig, botClient?: ChatClient, agentClient?: ChatClient); private get sessionAgentCredentials(); private setSessionAgentCredentials; private removeSessionAgentCredentials; get state(): State; setState(state: State): void; get store(): Store; /** * Sets up event listeners to update state for event-driven clients. */ private setClientEventListeners; /** * Switches the current chat client with the next client, if available. */ private handoff; private reinitializeAgentSession; addClientSdk(additionalClientSdk: Record<string, string>): void; initLocalStorage(): void; report(eventPayload: Omit<EventPayload, "chat"> & RecursivePartial<Pick<EventPayload, "chat">>): Promise<void>; setContext(context: unknown): void; setMessages(messages: Message[]): void; addMessage(message: Message): void; setMessageNotes(notes: MessageNotes): void; setChatLoadingStatus(isLoading: boolean): void; setCanSendMessage(canSendMessage: boolean): void; /** * Sets {@link ConversationState.conversationId} to the specified id * * @internal * * @param id - the id to set */ private setConversationId; restartConversation(): void; addListener<T>(listener: StateListener<T>): Unsubscribe; getNextMessage(text?: string, source?: MessageSource): Promise<MessageResponse | undefined>; streamNextMessage(text?: string, source?: MessageSource): Promise<MessageResponse | undefined>; /** * Setup relevant state before hitting Chat API endpoint for next message, such as * setting loading status, "canSendMessage" status, and appending new user's message * in conversation state. * * @remarks * If the response contains integration details, it will trigger a handoff to the next client. * * @internal * * @param nextMessageFn - function to invoke to get next message * @param text - the text of the next message * @param source - the source of the message * @returns a Promise of a response from the Chat API */ private nextMessageHandler; } //# sourceMappingURL=ChatHeadlessImpl.d.ts.map