@microsoft/omnichannel-chat-sdk
Version:
Microsoft Omnichannel Chat SDK
199 lines (198 loc) • 10 kB
TypeScript
import ACSClient from "./core/messaging/ACSClient";
import { VoiceVideoCallingOptionalParams } from "./types/config";
import { ChatAdapter, GetAgentAvailabilityResponse, GetCurrentLiveChatContextResponse, GetLiveChatTranscriptResponse, GetMessagesResponse, GetPersistentChatHistoryResponse, GetPreChatSurveyResponse, GetVoiceVideoCallingResponse, MaskingRules, UploadFileAttachmentResponse } from "./types/response";
import { ParticipantsRemovedEvent } from '@azure/communication-signaling';
import ChatAdapterOptionalParams from "./core/messaging/ChatAdapterOptionalParams";
import ChatConfig from "./core/ChatConfig";
import ChatReconnectContext from "./core/ChatReconnectContext";
import ChatReconnectOptionalParams from "./core/ChatReconnectOptionalParams";
import ChatSDKConfig from "./core/ChatSDKConfig";
import ChatSDKMessage from "./core/messaging/ChatSDKMessage";
import ChatTranscriptBody from "./core/ChatTranscriptBody";
import DebugOptionalParams from "./core/DebugOptionalParams";
import EmailLiveChatTranscriptOptionaParams from "./core/EmailLiveChatTranscriptOptionalParams";
import EndChatOptionalParams from "./core/EndChatOptionalParams";
import FetchChatTokenResponse from "@microsoft/ocsdk/lib/Model/FetchChatTokenResponse";
import FileMetadata from "@microsoft/omnichannel-amsclient/lib/FileMetadata";
import FramedClient from "@microsoft/omnichannel-amsclient/lib/FramedClient";
import FramedlessClient from "@microsoft/omnichannel-amsclient/lib/FramedlessClient";
import GetAgentAvailabilityOptionalParams from "./core/GetAgentAvailabilityOptionalParams";
import GetChatTokenOptionalParams from "./core/GetChatTokenOptionalParams";
import GetConversationDetailsOptionalParams from "./core/GetConversationDetailsOptionalParams";
import GetLiveChatConfigOptionalParams from "./core/GetLiveChatConfigOptionalParams";
import GetLiveChatTranscriptOptionalParams from "./core/GetLiveChatTranscriptOptionalParams";
import GetPersistentChatHistoryOptionalParams from "./core/GetPersistentChatHistoryOptionalParams";
import IChatToken from "./external/IC3Adapter/IChatToken";
import IFileInfo from "@microsoft/omnichannel-ic3core/lib/interfaces/IFileInfo";
import IFileMetadata from "@microsoft/omnichannel-ic3core/lib/model/IFileMetadata";
import IRawThread from "@microsoft/omnichannel-ic3core/lib/interfaces/IRawThread";
import InitializeOptionalParams from "./core/InitializeOptionalParams";
import LiveWorkItemDetails from "./core/LiveWorkItemDetails";
import OmnichannelConfig from "./core/OmnichannelConfig";
import OmnichannelMessage from "./core/messaging/OmnichannelMessage";
import OnNewMessageOptionalParams from "./core/messaging/OnNewMessageOptionalParams";
import PostChatContext from "./core/PostChatContext";
import StartChatOptionalParams from "./core/StartChatOptionalParams";
declare class OmnichannelChatSDK {
private debug;
runtimeId: string;
OCSDKProvider: unknown;
IC3SDKProvider: unknown;
OCClient: any;
IC3Client: any;
ACSClient: ACSClient | null;
AMSClient: FramedClient | FramedlessClient | null;
omnichannelConfig: OmnichannelConfig;
chatSDKConfig: ChatSDKConfig;
isInitialized: boolean;
localeId: string;
requestId: string;
sessionId: string | null;
private chatOperationInProgress;
private pendingOperations;
private unqServicesOrgUrl;
private coreServicesOrgUrl;
private dynamicsLocationCode;
private chatToken;
private liveChatConfig;
private widgetSnippetBaseUrl;
private liveChatVersion;
private dataMaskingRules;
private authSettings;
private authenticatedUserToken;
private preChatSurvey;
private conversation;
private callingOption;
private telemetry;
private scenarioMarker;
private ic3ClientLogger;
private ocSdkLogger;
private acsClientLogger;
private acsAdapterLogger;
private callingSdkLogger;
private amsClientLogger;
private isPersistentChat;
private isChatReconnect;
private reconnectId;
private refreshTokenTimer;
private AMSClientLoadCurrentState;
private isMaskingDisabled;
private maskingCharacter;
private botCSPId;
private isAMSClientAllowed;
private debugSDK;
private debugAMS;
private debugACS;
private detailedDebugEnabled;
private regexCompiledForDataMasking;
constructor(omnichannelConfig: OmnichannelConfig, chatSDKConfig?: ChatSDKConfig);
/**
* Executes an operation with mutual exclusion to prevent race conditions
* between startChat and endChat operations
*/
private executeWithLock;
/**
* Processes the next pending operation in the queue
*/
private processNextOperation;
/**
*
* @param flag Flag to enable/disable debug log telemetry, will be applied to all components
* @description Set the debug flag to enable/disable debug log telemetry
*/
setDebug(flag: boolean): void;
/**
* @description Allow to target specific components to enable/disable debug log telemetry, reducing the noise in the logs.
* @param flagSDK Flag to enable disable SDK debug log telemetry
* @param flagAcs Flag to enable/disable debugg log telemetry for Acs components (ACSClient and ACSAdapter)
* @param flagAttachment Flag to enable/disable debug log telemetry for Attachment components)
*/
setDebugDetailed(optionalParams: DebugOptionalParams): void;
private retryLoadAMSClient;
private getAMSClient;
private loadInitComponents;
private evaluateAMSAvailability;
private loadAmsClient;
private parallelInitialization;
private sequentialInitialization;
/**
*
* @param optionalParams
* @param parallel if true , it will run in parallel (fastest version) with components loaded in the background
* @returns livechatConfig
*/
initialize(optionalParams?: InitializeOptionalParams): Promise<ChatConfig>;
private loadChatConfig;
private getChatReconnectContextWithAuthToken;
private getChatReconnectContextWithReconnectId;
getChatReconnectContext(optionalParams?: ChatReconnectOptionalParams): Promise<ChatReconnectContext>;
startChat(optionalParams?: StartChatOptionalParams): Promise<void>;
private internalStartChat;
private closeChat;
endChat(endChatOptionalParams?: EndChatOptionalParams): Promise<void>;
private internalEndChat;
getCurrentLiveChatContext(): Promise<GetCurrentLiveChatContextResponse>;
getConversationDetails(optionalParams?: GetConversationDetailsOptionalParams): Promise<LiveWorkItemDetails>;
/**
* Gets PreChat Survey.
* @param parse Whether to parse PreChatSurvey to JSON or not.
*/
getPreChatSurvey(parse?: boolean): Promise<GetPreChatSurveyResponse>;
getLiveChatConfig(optionalParams?: GetLiveChatConfigOptionalParams): Promise<ChatConfig>;
getChatToken(cached?: boolean, optionalParams?: GetChatTokenOptionalParams): Promise<IChatToken>;
setChatToken(chatToken: FetchChatTokenResponse): void;
getCallingToken(): Promise<string>;
private recordMessages;
getMessages(): Promise<GetMessagesResponse>;
getDataMaskingRules(): Promise<MaskingRules>;
private transformMessage;
sendMessage(message: ChatSDKMessage): Promise<OmnichannelMessage | void>;
onNewMessage(onNewMessageCallback: CallableFunction, optionalParams?: OnNewMessageOptionalParams): Promise<void>;
sendTypingEvent(): Promise<void>;
onTypingEvent(onTypingEventCallback: CallableFunction): Promise<void>;
onAgentEndSession(onAgentEndSessionCallback: (message: IRawThread | ParticipantsRemovedEvent) => void): Promise<void>;
uploadFileAttachment(fileInfo: IFileInfo | File): Promise<UploadFileAttachmentResponse>;
downloadFileAttachment(fileMetadata: FileMetadata | IFileMetadata): Promise<Blob>;
emailLiveChatTranscript(body: ChatTranscriptBody, optionalParams?: EmailLiveChatTranscriptOptionaParams): Promise<void>;
getLiveChatTranscript(optionalParams?: GetLiveChatTranscriptOptionalParams): Promise<GetLiveChatTranscriptResponse>;
createChatAdapter(optionalParams?: ChatAdapterOptionalParams): Promise<ChatAdapter>;
isVoiceVideoCallingEnabled(): boolean;
getVoiceVideoCalling(voiceVideoCallingOptionalParams?: VoiceVideoCallingOptionalParams): Promise<GetVoiceVideoCallingResponse>;
getPostChatSurveyContext(): Promise<PostChatContext>;
getAgentAvailability(optionalParams?: GetAgentAvailabilityOptionalParams): Promise<GetAgentAvailabilityResponse>;
startPolling(): Promise<void>;
stopPolling(): Promise<void>;
private populateInitChatOptionalParam;
private getIC3Client;
private setPrechatConfigurations;
private setDataMaskingConfiguration;
private compileDataMaskingRegex;
private setAuthSettingConfig;
private setPersistentChatConfiguration;
private setLocaleIdConfiguration;
private setCallingOptionConfiguration;
private setLiveChatVersionConfiguration;
private setWidgetSnippetBaseUrl;
private getChatConfig;
private buildConfigurations;
private resolveIC3ClientUrl;
private resolveChatAdapterUrl;
private updateChatToken;
private setAuthTokenProvider;
private useCoreServicesOrgUrlIfNotSet;
/**
* Handles cleanup of failed conversation join attempts.
* Only cleans up conversations that were freshly created and failed to join.
*
* @param error - The error that occurred during conversation join
* @param optionalParams - Start chat optional parameters
* @private
*/
private handleConversationJoinFailure;
/**
* Get persistent chat history for authenticated users.
* @param getPersistentChatHistoryOptionalParams Optional parameters for persistent chat history retrieval.
*/
getPersistentChatHistory(getPersistentChatHistoryOptionalParams?: GetPersistentChatHistoryOptionalParams): Promise<GetPersistentChatHistoryResponse | undefined>;
}
export default OmnichannelChatSDK;