diff --git a/docs/api/README.md b/docs/api/README.md index 950c669..58ba6e0 100644 --- a/docs/api/README.md +++ b/docs/api/README.md @@ -10,6 +10,7 @@ Genesys Web Messaging Tester - [Conversation](classes/Conversation.md) - [ReorderedMessageDelayer](classes/ReorderedMessageDelayer.md) - [SessionTranscriber](classes/SessionTranscriber.md) +- [TimeoutWaitingForDisconnectionError](classes/TimeoutWaitingForDisconnectionError.md) - [TimeoutWaitingForResponseError](classes/TimeoutWaitingForResponseError.md) - [WebMessageServerConnectionFixture](classes/WebMessageServerConnectionFixture.md) - [WebMessageServerFixture](classes/WebMessageServerFixture.md) diff --git a/docs/api/classes/BotDisconnectedWaitingForResponseError.md b/docs/api/classes/BotDisconnectedWaitingForResponseError.md index e0f4df4..cb7d255 100644 --- a/docs/api/classes/BotDisconnectedWaitingForResponseError.md +++ b/docs/api/classes/BotDisconnectedWaitingForResponseError.md @@ -35,7 +35,7 @@ ### constructor -• **new BotDisconnectedWaitingForResponseError**(`_expectedResponse`, `_responsesReceived?`) +• **new BotDisconnectedWaitingForResponseError**(`_expectedResponse`, `_responsesReceived?`): [`BotDisconnectedWaitingForResponseError`](BotDisconnectedWaitingForResponseError.md) #### Parameters @@ -44,6 +44,10 @@ | `_expectedResponse` | `string` | `undefined` | | `_responsesReceived` | readonly (`StructuredMessageTextBody` \| `StructuredMessageStructuredBody`)[] | `[]` | +#### Returns + +[`BotDisconnectedWaitingForResponseError`](BotDisconnectedWaitingForResponseError.md) + #### Overrides Error.constructor @@ -64,7 +68,7 @@ Error.message #### Defined in -node_modules/typescript/lib/lib.es5.d.ts:1068 +node_modules/typescript/lib/lib.es5.d.ts:1076 ___ @@ -78,7 +82,7 @@ Error.name #### Defined in -node_modules/typescript/lib/lib.es5.d.ts:1067 +node_modules/typescript/lib/lib.es5.d.ts:1075 ___ @@ -92,7 +96,7 @@ Error.stack #### Defined in -node_modules/typescript/lib/lib.es5.d.ts:1069 +node_modules/typescript/lib/lib.es5.d.ts:1077 ___ @@ -100,6 +104,12 @@ ___ ▪ `Static` `Optional` **prepareStackTrace**: (`err`: `Error`, `stackTraces`: `CallSite`[]) => `any` +Optional override for formatting stack traces + +**`See`** + +https://v8.dev/docs/stack-trace-api#customizing-stack-traces + #### Type declaration ▸ (`err`, `stackTraces`): `any` @@ -175,7 +185,7 @@ readonly (`StructuredMessageTextBody` \| `StructuredMessageStructuredBody`)[] ### captureStackTrace -▸ `Static` **captureStackTrace**(`targetObject`, `constructorOpt?`): `void` +▸ **captureStackTrace**(`targetObject`, `constructorOpt?`): `void` Create .stack property on a target object diff --git a/docs/api/classes/Conversation.md b/docs/api/classes/Conversation.md index 16814a8..acdf68f 100644 --- a/docs/api/classes/Conversation.md +++ b/docs/api/classes/Conversation.md @@ -30,9 +30,14 @@ console.log(reply); - [constructor](Conversation.md#constructor) +### Accessors + +- [isDisconnected](Conversation.md#isdisconnected) + ### Methods - [sendText](Conversation.md#sendtext) +- [waitForConversationToClose](Conversation.md#waitforconversationtoclose) - [waitForConversationToStart](Conversation.md#waitforconversationtostart) - [waitForResponseText](Conversation.md#waitforresponsetext) - [waitForResponseWithTextContaining](Conversation.md#waitforresponsewithtextcontaining) @@ -43,7 +48,7 @@ console.log(reply); ### constructor -• **new Conversation**(`messengerSession`, `timeoutSet?`, `timeoutClear?`) +• **new Conversation**(`messengerSession`, `timeoutSet?`, `timeoutClear?`): [`Conversation`](Conversation.md) #### Parameters @@ -53,9 +58,29 @@ console.log(reply); | `timeoutSet` | typeof `setTimeout` | `setTimeout` | | `timeoutClear` | (`timeoutId`: `undefined` \| `string` \| `number` \| `Timeout`) => `void` | `clearTimeout` | +#### Returns + +[`Conversation`](Conversation.md) + #### Defined in -[packages/genesys-web-messaging-tester/src/Conversation.ts:133](https://github.com/ovotech/genesys-web-messaging-tester/blob/main/packages/genesys-web-messaging-tester/src/Conversation.ts#L133) +[packages/genesys-web-messaging-tester/src/Conversation.ts:142](https://github.com/ovotech/genesys-web-messaging-tester/blob/main/packages/genesys-web-messaging-tester/src/Conversation.ts#L142) + +## Accessors + +### isDisconnected + +• `get` **isDisconnected**(): `boolean` + +Returns whether the conversation has been disconnected + +#### Returns + +`boolean` + +#### Defined in + +[packages/genesys-web-messaging-tester/src/Conversation.ts:198](https://github.com/ovotech/genesys-web-messaging-tester/blob/main/packages/genesys-web-messaging-tester/src/Conversation.ts#L198) ## Methods @@ -78,7 +103,27 @@ Sends text to the conversation #### Defined in -[packages/genesys-web-messaging-tester/src/Conversation.ts:175](https://github.com/ovotech/genesys-web-messaging-tester/blob/main/packages/genesys-web-messaging-tester/src/Conversation.ts#L175) +[packages/genesys-web-messaging-tester/src/Conversation.ts:229](https://github.com/ovotech/genesys-web-messaging-tester/blob/main/packages/genesys-web-messaging-tester/src/Conversation.ts#L229) + +___ + +### waitForConversationToClose + +▸ **waitForConversationToClose**(`timeoutInMs?`): `Promise`\<`void`\> + +#### Parameters + +| Name | Type | Default value | +| :------ | :------ | :------ | +| `timeoutInMs` | `number` | `2000` | + +#### Returns + +`Promise`\<`void`\> + +#### Defined in + +[packages/genesys-web-messaging-tester/src/Conversation.ts:168](https://github.com/ovotech/genesys-web-messaging-tester/blob/main/packages/genesys-web-messaging-tester/src/Conversation.ts#L168) ___ @@ -97,7 +142,7 @@ background. This method allows you to wait for this process to finish. #### Defined in -[packages/genesys-web-messaging-tester/src/Conversation.ts:154](https://github.com/ovotech/genesys-web-messaging-tester/blob/main/packages/genesys-web-messaging-tester/src/Conversation.ts#L154) +[packages/genesys-web-messaging-tester/src/Conversation.ts:208](https://github.com/ovotech/genesys-web-messaging-tester/blob/main/packages/genesys-web-messaging-tester/src/Conversation.ts#L208) ___ @@ -115,7 +160,7 @@ If you want to wait for a specific message use [waitForResponseWithTextContainin #### Defined in -[packages/genesys-web-messaging-tester/src/Conversation.ts:197](https://github.com/ovotech/genesys-web-messaging-tester/blob/main/packages/genesys-web-messaging-tester/src/Conversation.ts#L197) +[packages/genesys-web-messaging-tester/src/Conversation.ts:255](https://github.com/ovotech/genesys-web-messaging-tester/blob/main/packages/genesys-web-messaging-tester/src/Conversation.ts#L255) ___ @@ -134,12 +179,12 @@ use [waitForResponseText](Conversation.md#waitforresponsetext). #### Parameters -| Name | Type | -| :------ | :------ | -| `text` | `string` | -| `«destructured»` | `Object` | -| › `caseInsensitive?` | `boolean` | -| › `timeoutInSeconds?` | `number` | +| Name | Type | Default value | +| :------ | :------ | :------ | +| `text` | `string` | `undefined` | +| `«destructured»` | `Object` | `{}` | +| › `caseInsensitive?` | `boolean` | `true` | +| › `timeoutInSeconds?` | `number` | `10` | #### Returns @@ -147,7 +192,7 @@ use [waitForResponseText](Conversation.md#waitforresponsetext). #### Defined in -[packages/genesys-web-messaging-tester/src/Conversation.ts:255](https://github.com/ovotech/genesys-web-messaging-tester/blob/main/packages/genesys-web-messaging-tester/src/Conversation.ts#L255) +[packages/genesys-web-messaging-tester/src/Conversation.ts:313](https://github.com/ovotech/genesys-web-messaging-tester/blob/main/packages/genesys-web-messaging-tester/src/Conversation.ts#L313) ___ @@ -164,11 +209,11 @@ use [waitForResponseText](Conversation.md#waitforresponsetext). #### Parameters -| Name | Type | -| :------ | :------ | -| `pattern` | `string` \| `RegExp` | -| `«destructured»` | `Object` | -| › `timeoutInSeconds?` | `number` | +| Name | Type | Default value | +| :------ | :------ | :------ | +| `pattern` | `string` \| `RegExp` | `undefined` | +| `«destructured»` | `Object` | `{}` | +| › `timeoutInSeconds?` | `number` | `10` | #### Returns @@ -176,7 +221,7 @@ use [waitForResponseText](Conversation.md#waitforresponsetext). #### Defined in -[packages/genesys-web-messaging-tester/src/Conversation.ts:286](https://github.com/ovotech/genesys-web-messaging-tester/blob/main/packages/genesys-web-messaging-tester/src/Conversation.ts#L286) +[packages/genesys-web-messaging-tester/src/Conversation.ts:344](https://github.com/ovotech/genesys-web-messaging-tester/blob/main/packages/genesys-web-messaging-tester/src/Conversation.ts#L344) ___ @@ -198,4 +243,4 @@ Wait for all responses until there is a predefined amount of 'silence'. #### Defined in -[packages/genesys-web-messaging-tester/src/Conversation.ts:213](https://github.com/ovotech/genesys-web-messaging-tester/blob/main/packages/genesys-web-messaging-tester/src/Conversation.ts#L213) +[packages/genesys-web-messaging-tester/src/Conversation.ts:271](https://github.com/ovotech/genesys-web-messaging-tester/blob/main/packages/genesys-web-messaging-tester/src/Conversation.ts#L271) diff --git a/docs/api/classes/ReorderedMessageDelayer.md b/docs/api/classes/ReorderedMessageDelayer.md index 2a650df..1416e37 100644 --- a/docs/api/classes/ReorderedMessageDelayer.md +++ b/docs/api/classes/ReorderedMessageDelayer.md @@ -63,7 +63,7 @@ timestamps. ### constructor -• **new ReorderedMessageDelayer**(`delayBeforeEmittingInMs?`, `intervalInMs?`, `intervalSet?`, `intervalClear?`) +• **new ReorderedMessageDelayer**(`delayBeforeEmittingInMs?`, `intervalInMs?`, `intervalSet?`, `intervalClear?`): [`ReorderedMessageDelayer`](ReorderedMessageDelayer.md) #### Parameters @@ -74,6 +74,10 @@ timestamps. | `intervalSet` | (`callback`: (...`args`: `any`[]) => `void`, `ms?`: `number`, ...`args`: `any`[]) => `NodeJS.Timeout` | `setInterval` | | `intervalClear` | (`intervalId`: `undefined` \| `string` \| `number` \| `Timeout`) => `void` | `clearInterval` | +#### Returns + +[`ReorderedMessageDelayer`](ReorderedMessageDelayer.md) + #### Overrides EventEmitter.constructor @@ -212,7 +216,7 @@ ___ ### addListener -▸ **addListener**(`event`, `listener`): [`ReorderedMessageDelayer`](ReorderedMessageDelayer.md) +▸ **addListener**(`event`, `listener`): `this` #### Parameters @@ -223,7 +227,7 @@ ___ #### Returns -[`ReorderedMessageDelayer`](ReorderedMessageDelayer.md) +`this` #### Implementation of @@ -370,7 +374,7 @@ ___ ### off -▸ **off**(`event`, `listener`): [`ReorderedMessageDelayer`](ReorderedMessageDelayer.md) +▸ **off**(`event`, `listener`): `this` #### Parameters @@ -381,7 +385,7 @@ ___ #### Returns -[`ReorderedMessageDelayer`](ReorderedMessageDelayer.md) +`this` #### Implementation of @@ -399,7 +403,7 @@ ___ ### on -▸ **on**(`event`, `listener`): [`ReorderedMessageDelayer`](ReorderedMessageDelayer.md) +▸ **on**(`event`, `listener`): `this` #### Parameters @@ -410,7 +414,7 @@ ___ #### Returns -[`ReorderedMessageDelayer`](ReorderedMessageDelayer.md) +`this` #### Implementation of @@ -428,7 +432,7 @@ ___ ### once -▸ **once**(`event`, `listener`): [`ReorderedMessageDelayer`](ReorderedMessageDelayer.md) +▸ **once**(`event`, `listener`): `this` #### Parameters @@ -439,7 +443,7 @@ ___ #### Returns -[`ReorderedMessageDelayer`](ReorderedMessageDelayer.md) +`this` #### Implementation of @@ -457,7 +461,7 @@ ___ ### prependListener -▸ **prependListener**(`event`, `listener`): [`ReorderedMessageDelayer`](ReorderedMessageDelayer.md) +▸ **prependListener**(`event`, `listener`): `this` #### Parameters @@ -468,7 +472,7 @@ ___ #### Returns -[`ReorderedMessageDelayer`](ReorderedMessageDelayer.md) +`this` #### Implementation of @@ -486,7 +490,7 @@ ___ ### prependOnceListener -▸ **prependOnceListener**(`event`, `listener`): [`ReorderedMessageDelayer`](ReorderedMessageDelayer.md) +▸ **prependOnceListener**(`event`, `listener`): `this` #### Parameters @@ -497,7 +501,7 @@ ___ #### Returns -[`ReorderedMessageDelayer`](ReorderedMessageDelayer.md) +`this` #### Implementation of @@ -543,7 +547,7 @@ ___ ### removeAllListeners -▸ **removeAllListeners**(`event?`): [`ReorderedMessageDelayer`](ReorderedMessageDelayer.md) +▸ **removeAllListeners**(`event?`): `this` #### Parameters @@ -553,7 +557,7 @@ ___ #### Returns -[`ReorderedMessageDelayer`](ReorderedMessageDelayer.md) +`this` #### Implementation of @@ -571,7 +575,7 @@ ___ ### removeListener -▸ **removeListener**(`event`, `listener`): [`ReorderedMessageDelayer`](ReorderedMessageDelayer.md) +▸ **removeListener**(`event`, `listener`): `this` #### Parameters @@ -582,7 +586,7 @@ ___ #### Returns -[`ReorderedMessageDelayer`](ReorderedMessageDelayer.md) +`this` #### Implementation of @@ -600,7 +604,7 @@ ___ ### setMaxListeners -▸ **setMaxListeners**(`n`): [`ReorderedMessageDelayer`](ReorderedMessageDelayer.md) +▸ **setMaxListeners**(`n`): `this` #### Parameters @@ -610,7 +614,7 @@ ___ #### Returns -[`ReorderedMessageDelayer`](ReorderedMessageDelayer.md) +`this` #### Implementation of @@ -628,7 +632,7 @@ ___ ### listenerCount -▸ `Static` **listenerCount**(`emitter`, `event`): `number` +▸ **listenerCount**(`emitter`, `event`): `number` #### Parameters @@ -657,7 +661,7 @@ ___ ### on -▸ `Static` **on**(`emitter`, `event`): `AsyncIterableIterator`\<`any`\> +▸ **on**(`emitter`, `event`): `AsyncIterableIterator`\<`any`\> #### Parameters @@ -682,7 +686,7 @@ ___ ### once -▸ `Static` **once**(`emitter`, `event`): `Promise`\<`any`[]\> +▸ **once**(`emitter`, `event`): `Promise`\<`any`[]\> #### Parameters @@ -703,7 +707,7 @@ EventEmitter.once node_modules/@types/node/events.d.ts:21 -▸ `Static` **once**(`emitter`, `event`): `Promise`\<`any`[]\> +▸ **once**(`emitter`, `event`): `Promise`\<`any`[]\> #### Parameters diff --git a/docs/api/classes/SessionTranscriber.md b/docs/api/classes/SessionTranscriber.md index c296f19..571c4cb 100644 --- a/docs/api/classes/SessionTranscriber.md +++ b/docs/api/classes/SessionTranscriber.md @@ -49,16 +49,20 @@ Transcribes a Web Messenger session into an array of transcribed messages. ### constructor -• **new SessionTranscriber**(`messengerSession`, `«destructured»?`) +• **new SessionTranscriber**(`messengerSession`, `«destructured»?`): [`SessionTranscriber`](SessionTranscriber.md) #### Parameters -| Name | Type | -| :------ | :------ | -| `messengerSession` | [`WebMessengerSession`](../interfaces/WebMessengerSession.md) | -| `«destructured»` | `Object` | -| › `nameForClient?` | `string` | -| › `nameForServer?` | `string` | +| Name | Type | Default value | +| :------ | :------ | :------ | +| `messengerSession` | [`WebMessengerSession`](../interfaces/WebMessengerSession.md) | `undefined` | +| `«destructured»` | `Object` | `{}` | +| › `nameForClient?` | `string` | `'You'` | +| › `nameForServer?` | `string` | `'Them'` | + +#### Returns + +[`SessionTranscriber`](SessionTranscriber.md) #### Overrides @@ -138,7 +142,7 @@ node_modules/@types/node/events.d.ts:37 ### addListener -▸ **addListener**(`event`, `listener`): [`SessionTranscriber`](SessionTranscriber.md) +▸ **addListener**(`event`, `listener`): `this` #### Parameters @@ -149,7 +153,7 @@ node_modules/@types/node/events.d.ts:37 #### Returns -[`SessionTranscriber`](SessionTranscriber.md) +`this` #### Inherited from @@ -286,7 +290,7 @@ ___ ### off -▸ **off**(`event`, `listener`): [`SessionTranscriber`](SessionTranscriber.md) +▸ **off**(`event`, `listener`): `this` #### Parameters @@ -297,7 +301,7 @@ ___ #### Returns -[`SessionTranscriber`](SessionTranscriber.md) +`this` #### Inherited from @@ -311,7 +315,7 @@ ___ ### on -▸ **on**(`event`, `listener`): [`SessionTranscriber`](SessionTranscriber.md) +▸ **on**(`event`, `listener`): `this` #### Parameters @@ -322,7 +326,7 @@ ___ #### Returns -[`SessionTranscriber`](SessionTranscriber.md) +`this` #### Inherited from @@ -336,7 +340,7 @@ ___ ### once -▸ **once**(`event`, `listener`): [`SessionTranscriber`](SessionTranscriber.md) +▸ **once**(`event`, `listener`): `this` #### Parameters @@ -347,7 +351,7 @@ ___ #### Returns -[`SessionTranscriber`](SessionTranscriber.md) +`this` #### Inherited from @@ -361,7 +365,7 @@ ___ ### prependListener -▸ **prependListener**(`event`, `listener`): [`SessionTranscriber`](SessionTranscriber.md) +▸ **prependListener**(`event`, `listener`): `this` #### Parameters @@ -372,7 +376,7 @@ ___ #### Returns -[`SessionTranscriber`](SessionTranscriber.md) +`this` #### Inherited from @@ -386,7 +390,7 @@ ___ ### prependOnceListener -▸ **prependOnceListener**(`event`, `listener`): [`SessionTranscriber`](SessionTranscriber.md) +▸ **prependOnceListener**(`event`, `listener`): `this` #### Parameters @@ -397,7 +401,7 @@ ___ #### Returns -[`SessionTranscriber`](SessionTranscriber.md) +`this` #### Inherited from @@ -435,7 +439,7 @@ ___ ### removeAllListeners -▸ **removeAllListeners**(`event?`): [`SessionTranscriber`](SessionTranscriber.md) +▸ **removeAllListeners**(`event?`): `this` #### Parameters @@ -445,7 +449,7 @@ ___ #### Returns -[`SessionTranscriber`](SessionTranscriber.md) +`this` #### Inherited from @@ -459,7 +463,7 @@ ___ ### removeListener -▸ **removeListener**(`event`, `listener`): [`SessionTranscriber`](SessionTranscriber.md) +▸ **removeListener**(`event`, `listener`): `this` #### Parameters @@ -470,7 +474,7 @@ ___ #### Returns -[`SessionTranscriber`](SessionTranscriber.md) +`this` #### Inherited from @@ -484,7 +488,7 @@ ___ ### setMaxListeners -▸ **setMaxListeners**(`n`): [`SessionTranscriber`](SessionTranscriber.md) +▸ **setMaxListeners**(`n`): `this` #### Parameters @@ -494,7 +498,7 @@ ___ #### Returns -[`SessionTranscriber`](SessionTranscriber.md) +`this` #### Inherited from @@ -508,7 +512,7 @@ ___ ### listenerCount -▸ `Static` **listenerCount**(`emitter`, `event`): `number` +▸ **listenerCount**(`emitter`, `event`): `number` #### Parameters @@ -537,7 +541,7 @@ ___ ### on -▸ `Static` **on**(`emitter`, `event`): `AsyncIterableIterator`\<`any`\> +▸ **on**(`emitter`, `event`): `AsyncIterableIterator`\<`any`\> #### Parameters @@ -562,7 +566,7 @@ ___ ### once -▸ `Static` **once**(`emitter`, `event`): `Promise`\<`any`[]\> +▸ **once**(`emitter`, `event`): `Promise`\<`any`[]\> #### Parameters @@ -583,7 +587,7 @@ EventEmitter.once node_modules/@types/node/events.d.ts:21 -▸ `Static` **once**(`emitter`, `event`): `Promise`\<`any`[]\> +▸ **once**(`emitter`, `event`): `Promise`\<`any`[]\> #### Parameters diff --git a/docs/api/classes/TimeoutWaitingForDisconnectionError.md b/docs/api/classes/TimeoutWaitingForDisconnectionError.md new file mode 100644 index 0000000..fd90cbc --- /dev/null +++ b/docs/api/classes/TimeoutWaitingForDisconnectionError.md @@ -0,0 +1,169 @@ +[Genesys Web Messaging Tester](../README.md) / TimeoutWaitingForDisconnectionError + +# Class: TimeoutWaitingForDisconnectionError + +## Hierarchy + +- `Error` + + ↳ **`TimeoutWaitingForDisconnectionError`** + +## Table of contents + +### Constructors + +- [constructor](TimeoutWaitingForDisconnectionError.md#constructor) + +### Properties + +- [message](TimeoutWaitingForDisconnectionError.md#message) +- [name](TimeoutWaitingForDisconnectionError.md#name) +- [stack](TimeoutWaitingForDisconnectionError.md#stack) +- [prepareStackTrace](TimeoutWaitingForDisconnectionError.md#preparestacktrace) +- [stackTraceLimit](TimeoutWaitingForDisconnectionError.md#stacktracelimit) + +### Methods + +- [captureStackTrace](TimeoutWaitingForDisconnectionError.md#capturestacktrace) + +## Constructors + +### constructor + +• **new TimeoutWaitingForDisconnectionError**(): [`TimeoutWaitingForDisconnectionError`](TimeoutWaitingForDisconnectionError.md) + +#### Returns + +[`TimeoutWaitingForDisconnectionError`](TimeoutWaitingForDisconnectionError.md) + +#### Overrides + +Error.constructor + +#### Defined in + +[packages/genesys-web-messaging-tester/src/Conversation.ts:101](https://github.com/ovotech/genesys-web-messaging-tester/blob/main/packages/genesys-web-messaging-tester/src/Conversation.ts#L101) + +## Properties + +### message + +• **message**: `string` + +#### Inherited from + +Error.message + +#### Defined in + +node_modules/typescript/lib/lib.es5.d.ts:1076 + +___ + +### name + +• **name**: `string` + +#### Inherited from + +Error.name + +#### Defined in + +node_modules/typescript/lib/lib.es5.d.ts:1075 + +___ + +### stack + +• `Optional` **stack**: `string` + +#### Inherited from + +Error.stack + +#### Defined in + +node_modules/typescript/lib/lib.es5.d.ts:1077 + +___ + +### prepareStackTrace + +▪ `Static` `Optional` **prepareStackTrace**: (`err`: `Error`, `stackTraces`: `CallSite`[]) => `any` + +Optional override for formatting stack traces + +**`See`** + +https://v8.dev/docs/stack-trace-api#customizing-stack-traces + +#### Type declaration + +▸ (`err`, `stackTraces`): `any` + +Optional override for formatting stack traces + +##### Parameters + +| Name | Type | +| :------ | :------ | +| `err` | `Error` | +| `stackTraces` | `CallSite`[] | + +##### Returns + +`any` + +**`See`** + +https://v8.dev/docs/stack-trace-api#customizing-stack-traces + +#### Inherited from + +Error.prepareStackTrace + +#### Defined in + +node_modules/@types/node/globals.d.ts:11 + +___ + +### stackTraceLimit + +▪ `Static` **stackTraceLimit**: `number` + +#### Inherited from + +Error.stackTraceLimit + +#### Defined in + +node_modules/@types/node/globals.d.ts:13 + +## Methods + +### captureStackTrace + +▸ **captureStackTrace**(`targetObject`, `constructorOpt?`): `void` + +Create .stack property on a target object + +#### Parameters + +| Name | Type | +| :------ | :------ | +| `targetObject` | `object` | +| `constructorOpt?` | `Function` | + +#### Returns + +`void` + +#### Inherited from + +Error.captureStackTrace + +#### Defined in + +node_modules/@types/node/globals.d.ts:4 diff --git a/docs/api/classes/TimeoutWaitingForResponseError.md b/docs/api/classes/TimeoutWaitingForResponseError.md index 7bda25c..6f36633 100644 --- a/docs/api/classes/TimeoutWaitingForResponseError.md +++ b/docs/api/classes/TimeoutWaitingForResponseError.md @@ -36,7 +36,7 @@ ### constructor -• **new TimeoutWaitingForResponseError**(`_timeoutInMs`, `_expectedResponse`, `_responsesReceived?`) +• **new TimeoutWaitingForResponseError**(`_timeoutInMs`, `_expectedResponse`, `_responsesReceived?`): [`TimeoutWaitingForResponseError`](TimeoutWaitingForResponseError.md) #### Parameters @@ -46,6 +46,10 @@ | `_expectedResponse` | `string` | `undefined` | | `_responsesReceived` | readonly (`StructuredMessageTextBody` \| `StructuredMessageStructuredBody`)[] | `[]` | +#### Returns + +[`TimeoutWaitingForResponseError`](TimeoutWaitingForResponseError.md) + #### Overrides Error.constructor @@ -66,7 +70,7 @@ Error.message #### Defined in -node_modules/typescript/lib/lib.es5.d.ts:1068 +node_modules/typescript/lib/lib.es5.d.ts:1076 ___ @@ -80,7 +84,7 @@ Error.name #### Defined in -node_modules/typescript/lib/lib.es5.d.ts:1067 +node_modules/typescript/lib/lib.es5.d.ts:1075 ___ @@ -94,7 +98,7 @@ Error.stack #### Defined in -node_modules/typescript/lib/lib.es5.d.ts:1069 +node_modules/typescript/lib/lib.es5.d.ts:1077 ___ @@ -102,6 +106,12 @@ ___ ▪ `Static` `Optional` **prepareStackTrace**: (`err`: `Error`, `stackTraces`: `CallSite`[]) => `any` +Optional override for formatting stack traces + +**`See`** + +https://v8.dev/docs/stack-trace-api#customizing-stack-traces + #### Type declaration ▸ (`err`, `stackTraces`): `any` @@ -191,7 +201,7 @@ ___ ### captureStackTrace -▸ `Static` **captureStackTrace**(`targetObject`, `constructorOpt?`): `void` +▸ **captureStackTrace**(`targetObject`, `constructorOpt?`): `void` Create .stack property on a target object diff --git a/docs/api/classes/WebMessageServerConnectionFixture.md b/docs/api/classes/WebMessageServerConnectionFixture.md index 7c8ffcb..7689d91 100644 --- a/docs/api/classes/WebMessageServerConnectionFixture.md +++ b/docs/api/classes/WebMessageServerConnectionFixture.md @@ -21,7 +21,7 @@ ### constructor -• **new WebMessageServerConnectionFixture**(`ws`) +• **new WebMessageServerConnectionFixture**(`ws`): [`WebMessageServerConnectionFixture`](WebMessageServerConnectionFixture.md) #### Parameters @@ -29,6 +29,10 @@ | :------ | :------ | | `ws` | `WebSocket` | +#### Returns + +[`WebMessageServerConnectionFixture`](WebMessageServerConnectionFixture.md) + #### Defined in [packages/genesys-web-messaging-tester/src/testFixtures/WebMessageServerConnectionFixture.ts:5](https://github.com/ovotech/genesys-web-messaging-tester/blob/main/packages/genesys-web-messaging-tester/src/testFixtures/WebMessageServerConnectionFixture.ts#L5) diff --git a/docs/api/classes/WebMessageServerFixture.md b/docs/api/classes/WebMessageServerFixture.md index bf324d0..925f4c0 100644 --- a/docs/api/classes/WebMessageServerFixture.md +++ b/docs/api/classes/WebMessageServerFixture.md @@ -21,7 +21,7 @@ ### constructor -• **new WebMessageServerFixture**(`port`) +• **new WebMessageServerFixture**(`port`): [`WebMessageServerFixture`](WebMessageServerFixture.md) #### Parameters @@ -29,6 +29,10 @@ | :------ | :------ | | `port` | `number` | +#### Returns + +[`WebMessageServerFixture`](WebMessageServerFixture.md) + #### Defined in [packages/genesys-web-messaging-tester/src/testFixtures/WebMessageServerFixture.ts:8](https://github.com/ovotech/genesys-web-messaging-tester/blob/main/packages/genesys-web-messaging-tester/src/testFixtures/WebMessageServerFixture.ts#L8) diff --git a/docs/api/classes/WebMessengerGuestSession.md b/docs/api/classes/WebMessengerGuestSession.md index 59c7d6a..b2319f2 100644 --- a/docs/api/classes/WebMessengerGuestSession.md +++ b/docs/api/classes/WebMessengerGuestSession.md @@ -57,7 +57,7 @@ https://developer.genesys.cloud/api/digital/webmessaging/websocketapi#configure- ### constructor -• **new WebMessengerGuestSession**(`config`, `participantData?`, `messageDelayer?`, `wsFactory?`) +• **new WebMessengerGuestSession**(`config`, `participantData?`, `messageDelayer?`, `wsFactory?`): [`WebMessengerGuestSession`](WebMessengerGuestSession.md) #### Parameters @@ -68,6 +68,10 @@ https://developer.genesys.cloud/api/digital/webmessaging/websocketapi#configure- | `messageDelayer` | [`MessageDelayer`](../interfaces/MessageDelayer.md) | | `wsFactory` | (`url`: `string`, `options?`: `ClientRequestArgs` \| `ClientOptions`) => `WebSocket` | +#### Returns + +[`WebMessengerGuestSession`](WebMessengerGuestSession.md) + #### Overrides EventEmitter.constructor @@ -185,7 +189,7 @@ node_modules/@types/node/events.d.ts:37 ### addListener -▸ **addListener**(`event`, `listener`): [`WebMessengerGuestSession`](WebMessengerGuestSession.md) +▸ **addListener**(`event`, `listener`): `this` #### Parameters @@ -196,7 +200,7 @@ node_modules/@types/node/events.d.ts:37 #### Returns -[`WebMessengerGuestSession`](WebMessengerGuestSession.md) +`this` #### Inherited from @@ -333,7 +337,7 @@ ___ ### off -▸ **off**(`event`, `listener`): [`WebMessengerGuestSession`](WebMessengerGuestSession.md) +▸ **off**(`event`, `listener`): `this` #### Parameters @@ -344,7 +348,7 @@ ___ #### Returns -[`WebMessengerGuestSession`](WebMessengerGuestSession.md) +`this` #### Inherited from @@ -358,7 +362,7 @@ ___ ### on -▸ **on**(`event`, `listener`): [`WebMessengerGuestSession`](WebMessengerGuestSession.md) +▸ **on**(`event`, `listener`): `this` #### Parameters @@ -369,7 +373,7 @@ ___ #### Returns -[`WebMessengerGuestSession`](WebMessengerGuestSession.md) +`this` #### Inherited from @@ -383,7 +387,7 @@ ___ ### once -▸ **once**(`event`, `listener`): [`WebMessengerGuestSession`](WebMessengerGuestSession.md) +▸ **once**(`event`, `listener`): `this` #### Parameters @@ -394,7 +398,7 @@ ___ #### Returns -[`WebMessengerGuestSession`](WebMessengerGuestSession.md) +`this` #### Inherited from @@ -408,7 +412,7 @@ ___ ### prependListener -▸ **prependListener**(`event`, `listener`): [`WebMessengerGuestSession`](WebMessengerGuestSession.md) +▸ **prependListener**(`event`, `listener`): `this` #### Parameters @@ -419,7 +423,7 @@ ___ #### Returns -[`WebMessengerGuestSession`](WebMessengerGuestSession.md) +`this` #### Inherited from @@ -433,7 +437,7 @@ ___ ### prependOnceListener -▸ **prependOnceListener**(`event`, `listener`): [`WebMessengerGuestSession`](WebMessengerGuestSession.md) +▸ **prependOnceListener**(`event`, `listener`): `this` #### Parameters @@ -444,7 +448,7 @@ ___ #### Returns -[`WebMessengerGuestSession`](WebMessengerGuestSession.md) +`this` #### Inherited from @@ -482,7 +486,7 @@ ___ ### removeAllListeners -▸ **removeAllListeners**(`event?`): [`WebMessengerGuestSession`](WebMessengerGuestSession.md) +▸ **removeAllListeners**(`event?`): `this` #### Parameters @@ -492,7 +496,7 @@ ___ #### Returns -[`WebMessengerGuestSession`](WebMessengerGuestSession.md) +`this` #### Inherited from @@ -506,7 +510,7 @@ ___ ### removeListener -▸ **removeListener**(`event`, `listener`): [`WebMessengerGuestSession`](WebMessengerGuestSession.md) +▸ **removeListener**(`event`, `listener`): `this` #### Parameters @@ -517,7 +521,7 @@ ___ #### Returns -[`WebMessengerGuestSession`](WebMessengerGuestSession.md) +`this` #### Inherited from @@ -551,7 +555,7 @@ ___ ### setMaxListeners -▸ **setMaxListeners**(`n`): [`WebMessengerGuestSession`](WebMessengerGuestSession.md) +▸ **setMaxListeners**(`n`): `this` #### Parameters @@ -561,7 +565,7 @@ ___ #### Returns -[`WebMessengerGuestSession`](WebMessengerGuestSession.md) +`this` #### Inherited from @@ -575,7 +579,7 @@ ___ ### listenerCount -▸ `Static` **listenerCount**(`emitter`, `event`): `number` +▸ **listenerCount**(`emitter`, `event`): `number` #### Parameters @@ -604,7 +608,7 @@ ___ ### on -▸ `Static` **on**(`emitter`, `event`): `AsyncIterableIterator`\<`any`\> +▸ **on**(`emitter`, `event`): `AsyncIterableIterator`\<`any`\> #### Parameters @@ -629,7 +633,7 @@ ___ ### once -▸ `Static` **once**(`emitter`, `event`): `Promise`\<`any`[]\> +▸ **once**(`emitter`, `event`): `Promise`\<`any`[]\> #### Parameters @@ -650,7 +654,7 @@ EventEmitter.once node_modules/@types/node/events.d.ts:21 -▸ `Static` **once**(`emitter`, `event`): `Promise`\<`any`[]\> +▸ **once**(`emitter`, `event`): `Promise`\<`any`[]\> #### Parameters diff --git a/docs/api/interfaces/MessageDelayer.md b/docs/api/interfaces/MessageDelayer.md index 271d429..50036ce 100644 --- a/docs/api/interfaces/MessageDelayer.md +++ b/docs/api/interfaces/MessageDelayer.md @@ -80,7 +80,7 @@ ___ ### addListener -▸ **addListener**(`event`, `listener`): [`MessageDelayer`](MessageDelayer.md) +▸ **addListener**(`event`, `listener`): `this` #### Parameters @@ -91,7 +91,7 @@ ___ #### Returns -[`MessageDelayer`](MessageDelayer.md) +`this` #### Inherited from @@ -214,7 +214,7 @@ ___ ### off -▸ **off**(`event`, `listener`): [`MessageDelayer`](MessageDelayer.md) +▸ **off**(`event`, `listener`): `this` #### Parameters @@ -225,7 +225,7 @@ ___ #### Returns -[`MessageDelayer`](MessageDelayer.md) +`this` #### Inherited from @@ -239,7 +239,7 @@ ___ ### on -▸ **on**(`event`, `listener`): [`MessageDelayer`](MessageDelayer.md) +▸ **on**(`event`, `listener`): `this` #### Parameters @@ -250,7 +250,7 @@ ___ #### Returns -[`MessageDelayer`](MessageDelayer.md) +`this` #### Inherited from @@ -264,7 +264,7 @@ ___ ### once -▸ **once**(`event`, `listener`): [`MessageDelayer`](MessageDelayer.md) +▸ **once**(`event`, `listener`): `this` #### Parameters @@ -275,7 +275,7 @@ ___ #### Returns -[`MessageDelayer`](MessageDelayer.md) +`this` #### Inherited from @@ -289,7 +289,7 @@ ___ ### prependListener -▸ **prependListener**(`event`, `listener`): [`MessageDelayer`](MessageDelayer.md) +▸ **prependListener**(`event`, `listener`): `this` #### Parameters @@ -300,7 +300,7 @@ ___ #### Returns -[`MessageDelayer`](MessageDelayer.md) +`this` #### Inherited from @@ -314,7 +314,7 @@ ___ ### prependOnceListener -▸ **prependOnceListener**(`event`, `listener`): [`MessageDelayer`](MessageDelayer.md) +▸ **prependOnceListener**(`event`, `listener`): `this` #### Parameters @@ -325,7 +325,7 @@ ___ #### Returns -[`MessageDelayer`](MessageDelayer.md) +`this` #### Inherited from @@ -363,7 +363,7 @@ ___ ### removeAllListeners -▸ **removeAllListeners**(`event?`): [`MessageDelayer`](MessageDelayer.md) +▸ **removeAllListeners**(`event?`): `this` #### Parameters @@ -373,7 +373,7 @@ ___ #### Returns -[`MessageDelayer`](MessageDelayer.md) +`this` #### Inherited from @@ -387,7 +387,7 @@ ___ ### removeListener -▸ **removeListener**(`event`, `listener`): [`MessageDelayer`](MessageDelayer.md) +▸ **removeListener**(`event`, `listener`): `this` #### Parameters @@ -398,7 +398,7 @@ ___ #### Returns -[`MessageDelayer`](MessageDelayer.md) +`this` #### Inherited from @@ -412,7 +412,7 @@ ___ ### setMaxListeners -▸ **setMaxListeners**(`n`): [`MessageDelayer`](MessageDelayer.md) +▸ **setMaxListeners**(`n`): `this` #### Parameters @@ -422,7 +422,7 @@ ___ #### Returns -[`MessageDelayer`](MessageDelayer.md) +`this` #### Inherited from diff --git a/docs/api/interfaces/WebMessengerSession.md b/docs/api/interfaces/WebMessengerSession.md index e0516df..9b3a837 100644 --- a/docs/api/interfaces/WebMessengerSession.md +++ b/docs/api/interfaces/WebMessengerSession.md @@ -59,7 +59,7 @@ This delay should be taken into account for any timeout values of downstream fun ### addListener -▸ **addListener**(`event`, `listener`): [`WebMessengerSession`](WebMessengerSession.md) +▸ **addListener**(`event`, `listener`): `this` #### Parameters @@ -70,7 +70,7 @@ This delay should be taken into account for any timeout values of downstream fun #### Returns -[`WebMessengerSession`](WebMessengerSession.md) +`this` #### Inherited from @@ -207,7 +207,7 @@ ___ ### off -▸ **off**(`event`, `listener`): [`WebMessengerSession`](WebMessengerSession.md) +▸ **off**(`event`, `listener`): `this` #### Parameters @@ -218,7 +218,7 @@ ___ #### Returns -[`WebMessengerSession`](WebMessengerSession.md) +`this` #### Inherited from @@ -232,7 +232,7 @@ ___ ### on -▸ **on**(`event`, `listener`): [`WebMessengerSession`](WebMessengerSession.md) +▸ **on**(`event`, `listener`): `this` #### Parameters @@ -243,7 +243,7 @@ ___ #### Returns -[`WebMessengerSession`](WebMessengerSession.md) +`this` #### Inherited from @@ -257,7 +257,7 @@ ___ ### once -▸ **once**(`event`, `listener`): [`WebMessengerSession`](WebMessengerSession.md) +▸ **once**(`event`, `listener`): `this` #### Parameters @@ -268,7 +268,7 @@ ___ #### Returns -[`WebMessengerSession`](WebMessengerSession.md) +`this` #### Inherited from @@ -282,7 +282,7 @@ ___ ### prependListener -▸ **prependListener**(`event`, `listener`): [`WebMessengerSession`](WebMessengerSession.md) +▸ **prependListener**(`event`, `listener`): `this` #### Parameters @@ -293,7 +293,7 @@ ___ #### Returns -[`WebMessengerSession`](WebMessengerSession.md) +`this` #### Inherited from @@ -307,7 +307,7 @@ ___ ### prependOnceListener -▸ **prependOnceListener**(`event`, `listener`): [`WebMessengerSession`](WebMessengerSession.md) +▸ **prependOnceListener**(`event`, `listener`): `this` #### Parameters @@ -318,7 +318,7 @@ ___ #### Returns -[`WebMessengerSession`](WebMessengerSession.md) +`this` #### Inherited from @@ -356,7 +356,7 @@ ___ ### removeAllListeners -▸ **removeAllListeners**(`event?`): [`WebMessengerSession`](WebMessengerSession.md) +▸ **removeAllListeners**(`event?`): `this` #### Parameters @@ -366,7 +366,7 @@ ___ #### Returns -[`WebMessengerSession`](WebMessengerSession.md) +`this` #### Inherited from @@ -380,7 +380,7 @@ ___ ### removeListener -▸ **removeListener**(`event`, `listener`): [`WebMessengerSession`](WebMessengerSession.md) +▸ **removeListener**(`event`, `listener`): `this` #### Parameters @@ -391,7 +391,7 @@ ___ #### Returns -[`WebMessengerSession`](WebMessengerSession.md) +`this` #### Inherited from @@ -425,7 +425,7 @@ ___ ### setMaxListeners -▸ **setMaxListeners**(`n`): [`WebMessengerSession`](WebMessengerSession.md) +▸ **setMaxListeners**(`n`): `this` #### Parameters @@ -435,7 +435,7 @@ ___ #### Returns -[`WebMessengerSession`](WebMessengerSession.md) +`this` #### Inherited from diff --git a/examples/api/__tests__/using-jest.spec.ts b/examples/api/__tests__/using-jest.spec.ts index e011fd6..ac0e17c 100644 --- a/examples/api/__tests__/using-jest.spec.ts +++ b/examples/api/__tests__/using-jest.spec.ts @@ -66,6 +66,14 @@ describe('Using jest to perform the test', () => { 'Can we ask you some questions about your experience today?', ); + await convo.sendText('Yes'); + + await expect(convo.waitForResponseText()).resolves.toContain( + 'Thank you! Now for the next question...', + ); + + await expect(convo.waitForConversationToClose()).resolves.toBeUndefined(); + // Log the transcript for the entire conversation console.log(transcriber.getTranscript().map((t) => t.toString())); }); diff --git a/examples/api/package.json b/examples/api/package.json index 87353d3..e14fde7 100644 --- a/examples/api/package.json +++ b/examples/api/package.json @@ -10,7 +10,7 @@ "test:ts": "node -r ts-node/register ../api/src/ts-script.ts" }, "devDependencies": { - "@ovotech/genesys-web-messaging-tester": "2.0.6", + "@ovotech/genesys-web-messaging-tester": "2.0.7", "@types/jest": "^29.0.3", "@types/node": "^14.14.2", "@typescript-eslint/eslint-plugin": "^6.17.0", diff --git a/examples/cli-scripted-tests/example-pass.yml b/examples/cli-scripted-tests/example-pass.yml index 192ff51..a920aa6 100644 --- a/examples/cli-scripted-tests/example-pass.yml +++ b/examples/cli-scripted-tests/example-pass.yml @@ -5,16 +5,15 @@ scenarios: "Accept Survey": - say: hi - waitForReplyContaining: Can we ask you some questions about your experience today? - - say: Yes + - say: 'Yes' - waitForReplyMatching: Thank you! Now for the next question[\.]+ "Decline Survey": - say: hi - waitForReplyContaining: Can we ask you some questions about your experience today? - - say: No + - say: 'No' - waitForReplyContaining: Maybe next time. Goodbye "Provide Incorrect Answer to Survey Question": - say: hi - waitForReplyContaining: Can we ask you some questions about your experience today? - - say: Not sure - - waitForReplyContaining: Sorry I didn't understand you. Please answer with either 'yes' or 'no' - - waitForReplyContaining: Can we ask you some questions about your experience today? + - say: Example + - waitForReplyContaining: Sorry. Please input "Yes" or "No". Do you want to proceed? diff --git a/packages/genesys-web-messaging-tester-cli/README.md b/packages/genesys-web-messaging-tester-cli/README.md index c9c83a4..8215063 100644 --- a/packages/genesys-web-messaging-tester-cli/README.md +++ b/packages/genesys-web-messaging-tester-cli/README.md @@ -151,6 +151,8 @@ Then run the AI test by pointing to the scenario file in the terminal: web-messaging-tester ai tests/example.yml ``` +For a slightly more detailed guide see: [Let's test a Genesys chatbot with AI](https://www.linkedin.com/pulse/lets-test-genesys-chatbot-ai-lucas-woodward-dvrpc). + ## Example commands ``` diff --git a/packages/genesys-web-messaging-tester-cli/package.json b/packages/genesys-web-messaging-tester-cli/package.json index e2ab1b6..cfa644c 100644 --- a/packages/genesys-web-messaging-tester-cli/package.json +++ b/packages/genesys-web-messaging-tester-cli/package.json @@ -1,6 +1,6 @@ { "name": "@ovotech/genesys-web-messaging-tester-cli", - "version": "2.0.2", + "version": "2.0.3", "main": "lib/index.js", "types": "lib/index.d.ts", "license": "Apache-2.0", @@ -30,7 +30,7 @@ "web-messaging-tester": "lib/index.js" }, "dependencies": { - "@ovotech/genesys-web-messaging-tester": "^2.0.6", + "@ovotech/genesys-web-messaging-tester": "^2.0.7", "chalk": "^4.1.2", "ci-info": "^3.5.0", "commander": "^11.0.0", diff --git a/packages/genesys-web-messaging-tester/package.json b/packages/genesys-web-messaging-tester/package.json index 6d25e26..4dab884 100644 --- a/packages/genesys-web-messaging-tester/package.json +++ b/packages/genesys-web-messaging-tester/package.json @@ -1,6 +1,6 @@ { "name": "@ovotech/genesys-web-messaging-tester", - "version": "2.0.6", + "version": "2.0.7", "main": "lib/index.js", "types": "lib/index.d.ts", "license": "Apache-2.0", diff --git a/packages/genesys-web-messaging-tester/src/Conversation.ts b/packages/genesys-web-messaging-tester/src/Conversation.ts index b80dcc2..c00c9ef 100644 --- a/packages/genesys-web-messaging-tester/src/Conversation.ts +++ b/packages/genesys-web-messaging-tester/src/Conversation.ts @@ -97,6 +97,13 @@ Received before disconnection: } } +export class TimeoutWaitingForDisconnectionError extends Error { + constructor() { + super('Bot did not disconnect from the conversation within the timeout period'); + Object.setPrototypeOf(this, TimeoutWaitingForDisconnectionError.prototype); + } +} + /** * Provides an API to simplify sending and receiving messages in a Web Messenger * session. @@ -130,6 +137,8 @@ export class Conversation { */ private readonly timeoutCompensation: number; + private disconnectedByGenesys: boolean = false; + constructor( private readonly messengerSession: WebMessengerSession, private readonly timeoutSet: typeof setTimeout = setTimeout, @@ -137,14 +146,64 @@ export class Conversation { ) { this.sessionStarted = false; this.messengerSession.once('sessionStarted', () => (this.sessionStarted = true)); - this.timeoutCompensation = messengerSession.messageDelayInMs; + + const detectDisconnectFunc = (event: StructuredMessage) => { + if ( + event.body.direction === 'Outbound' && + event.body.type === 'Event' && + Conversation.containsDisconnectEvent(event.body) + ) { + this.disconnectedByGenesys = true; + this.messengerSession.off('structuredMessage', detectDisconnectFunc); + } + }; + this.messengerSession.on('structuredMessage', detectDisconnectFunc); } private static containsDisconnectEvent(event: StructuredMessageEventBody): boolean { return event.events.some((e) => e.eventType === 'Presence' && e.presence.type === 'Disconnect'); } + public async waitForConversationToClose(timeoutInMs = 2000): Promise { + return new Promise((resolve, reject) => { + if (this.disconnectedByGenesys) { + resolve(); + return; + } + + let timeout: NodeJS.Timeout | undefined = undefined; + + const checkMessage = (event: StructuredMessage): void => { + if ( + event.body.direction === 'Outbound' && + event.body.type === 'Event' && + Conversation.containsDisconnectEvent(event.body) + ) { + if (timeout) { + this.timeoutClear(timeout); + } + resolve(); + } + }; + + this.messengerSession.on('structuredMessage', checkMessage); + + timeout = this.timeoutSet(() => { + this.messengerSession.off('structuredMessage', checkMessage); + + reject(new TimeoutWaitingForDisconnectionError()); + }, timeoutInMs); + }); + } + + /** + * Returns whether the conversation has been disconnected + */ + public get isDisconnected(): boolean { + return this.disconnectedByGenesys; + } + /** * Resolves when the conversation has started. * @@ -177,6 +236,10 @@ export class Conversation { throw new Error('Text cannot be empty'); } + if (this.disconnectedByGenesys) { + throw new Error('Cannot send text as conversation was disconnected by Genesys'); + } + if (delayInMs > 0) { return new Promise((resolve) => { setTimeout(() => { diff --git a/packages/genesys-web-messaging-tester/src/index.ts b/packages/genesys-web-messaging-tester/src/index.ts index a5b6891..5df7b48 100644 --- a/packages/genesys-web-messaging-tester/src/index.ts +++ b/packages/genesys-web-messaging-tester/src/index.ts @@ -12,6 +12,7 @@ export { Conversation, TimeoutWaitingForResponseError, BotDisconnectedWaitingForResponseError, + TimeoutWaitingForDisconnectionError, } from './Conversation'; export { SessionTranscriber, TranscribedMessage } from './transcribe/Transcriber'; diff --git a/yarn.lock b/yarn.lock index 1760694..a885bff 100644 --- a/yarn.lock +++ b/yarn.lock @@ -490,7 +490,7 @@ __metadata: version: 0.0.0-use.local resolution: "@examples/api@workspace:examples/api" dependencies: - "@ovotech/genesys-web-messaging-tester": 2.0.6 + "@ovotech/genesys-web-messaging-tester": 2.0.7 "@types/jest": ^29.0.3 "@types/node": ^14.14.2 "@typescript-eslint/eslint-plugin": ^6.17.0 @@ -920,7 +920,7 @@ __metadata: version: 0.0.0-use.local resolution: "@ovotech/genesys-web-messaging-tester-cli@workspace:packages/genesys-web-messaging-tester-cli" dependencies: - "@ovotech/genesys-web-messaging-tester": ^2.0.6 + "@ovotech/genesys-web-messaging-tester": ^2.0.7 "@types/humanize-duration": ^3.27.1 "@types/jest": ^29.0.3 "@types/jest-when": ^3.5.2 @@ -965,7 +965,7 @@ __metadata: languageName: unknown linkType: soft -"@ovotech/genesys-web-messaging-tester@2.0.6, @ovotech/genesys-web-messaging-tester@^2.0.6, @ovotech/genesys-web-messaging-tester@workspace:packages/genesys-web-messaging-tester": +"@ovotech/genesys-web-messaging-tester@2.0.7, @ovotech/genesys-web-messaging-tester@^2.0.7, @ovotech/genesys-web-messaging-tester@workspace:packages/genesys-web-messaging-tester": version: 0.0.0-use.local resolution: "@ovotech/genesys-web-messaging-tester@workspace:packages/genesys-web-messaging-tester" dependencies: