UNPKG

@ovotech/genesys-web-messaging-tester

Version:
125 lines (124 loc) 5.29 kB
/// <reference types="node" /> import { WebMessengerSession } from './genesys/WebMessengerGuestSession'; import { StructuredMessageStructuredBody, StructuredMessageTextBody } from './genesys/StructuredMessage'; export declare class TimeoutWaitingForResponseError extends Error { private readonly _timeoutInMs; private readonly _expectedResponse; private readonly _responsesReceived; constructor(_timeoutInMs: number, _expectedResponse: string, _responsesReceived?: ReadonlyArray<StructuredMessageTextBody | StructuredMessageStructuredBody>); private static createFailureMessage; get expectedResponse(): string; get responsesReceived(): ReadonlyArray<StructuredMessageTextBody | StructuredMessageStructuredBody>; get timeoutInMs(): number; } export declare class BotDisconnectedWaitingForResponseError extends Error { private readonly _expectedResponse; private readonly _responsesReceived; constructor(_expectedResponse: string, _responsesReceived?: ReadonlyArray<StructuredMessageTextBody | StructuredMessageStructuredBody>); private static createFailureMessage; get expectedResponse(): string; get responsesReceived(): ReadonlyArray<StructuredMessageTextBody | StructuredMessageStructuredBody>; } export declare class TimeoutWaitingForDisconnectionError extends Error { constructor(); } /** * Provides an API to simplify sending and receiving messages in a Web Messenger * session. * * ```typescript * const convo = new Conversation( * new WebMessengerGuestSession({ * deploymentId: 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx', * region: 'xxxx.pure.cloud', * }), * ); * * await convo.waitForConversationToStart(); * await convo.sendText('hi'); * * await convo.waitForResponseContaining('Is this an example?'); * * await convo.sendText('yes'); * * const reply = await convo.waitForResponse(); * console.log(reply); * ``` */ export declare class Conversation { private readonly messengerSession; private readonly timeoutSet; private readonly timeoutClear; private sessionStarted; /** * When defining timeout durations we need to take into consideration the delay that occurs in the * WebMessengerSession to correct for out of order messages; * @private */ private readonly timeoutCompensation; private disconnectedByGenesys; constructor(messengerSession: WebMessengerSession, timeoutSet?: typeof setTimeout, timeoutClear?: typeof clearTimeout); private static containsDisconnectEvent; waitForConversationToClose(timeoutInMs?: number): Promise<void>; /** * Returns whether the conversation has been disconnected */ get isDisconnected(): boolean; /** * Resolves when the conversation has started. * * Starting a conversation is an automatic process that happens in the * background. This method allows you to wait for this process to finish. */ waitForConversationToStart(): Promise<Conversation>; /** * Sends text to the conversation * @param text Text containing at least one character * @param delayInMs Delay in milliseconds between calling this method and the text being sent. * Without a delay some messages are sent so quickly after the original message * that Genesys Cloud doesn't acknowledge them. * A delay of 0 will result in the text being sent immediately. */ sendText(text: string, delayInMs?: number): Promise<void>; /** * Resolves on the next response from the other participant in the conversation that contains text. * * If you want to wait for a specific message use {@link waitForResponseWithTextContaining}. */ waitForResponseText(): Promise<string>; /** * Wait for all responses until there is a predefined amount of 'silence'. */ waitForResponses(timeToWaitAfterLastMessageInMs?: number): Promise<string[]>; /** * Resolves when a response is received that contains a specific piece of text. * If no response is received that contains the text within the timeout period * then an exception is thrown. * * Case-insensitive by default. * * If you want to wait for the next response, regardless of what it contains * use {@link waitForResponseText}. */ waitForResponseWithTextContaining(text: string, { timeoutInSeconds, caseInsensitive, }?: { timeoutInSeconds?: number; caseInsensitive?: boolean; }): Promise<string>; /** * Resolves when a response is received that matches a regular expression. * If no response is received that matches the pattern within the timeout period * then an exception is thrown. * * If you want to wait for the next response, regardless of what it contains * use {@link waitForResponseText}. */ waitForResponseWithTextMatchingPattern(pattern: string | RegExp, { timeoutInSeconds }?: { timeoutInSeconds?: number; }): Promise<string>; /** * Resolves when a response is received that matches a check. * If no response is received that the check matches within the timeout period * then an exception is thrown. */ private waitForResponseWithCheck; }