diff --git a/package-lock.json b/package-lock.json index b4c1cb8..e6a857c 100644 --- a/package-lock.json +++ b/package-lock.json @@ -18700,7 +18700,7 @@ }, "packages/chat-headless": { "name": "@yext/chat-headless", - "version": "0.7.2", + "version": "0.7.3", "license": "BSD-3-Clause", "dependencies": { "@reduxjs/toolkit": "^1.9.5", diff --git a/packages/chat-headless-react/THIRD-PARTY-NOTICES b/packages/chat-headless-react/THIRD-PARTY-NOTICES index 1a80238..b7414c1 100644 --- a/packages/chat-headless-react/THIRD-PARTY-NOTICES +++ b/packages/chat-headless-react/THIRD-PARTY-NOTICES @@ -3,7 +3,7 @@ https://www.npmjs.com/package/generate-license-file The following npm package may be included in this product: - - @babel/runtime@7.22.15 + - @babel/runtime@7.23.5 This package contains the following license and notice below: @@ -34,7 +34,7 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. The following npm package may be included in this product: - - @reduxjs/toolkit@1.9.5 + - @reduxjs/toolkit@1.9.7 This package contains the following license and notice below: @@ -62,42 +62,12 @@ SOFTWARE. ----------- -The following npm package may be included in this product: - - - @types/hoist-non-react-statics@3.3.1 - -This package contains the following license and notice below: - -MIT License - - Copyright (c) Microsoft Corporation. All rights reserved. - - Permission is hereby granted, free of charge, to any person obtaining a copy - of this software and associated documentation files (the "Software"), to deal - in the Software without restriction, including without limitation the rights - to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - copies of the Software, and to permit persons to whom the Software is - furnished to do so, subject to the following conditions: - - The above copyright notice and this permission notice shall be included in all - copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - SOFTWARE - ------------ - The following npm packages may be included in this product: - - @types/prop-types@15.7.5 - - @types/react-dom@18.2.7 - - @types/react@18.2.21 - - @types/scheduler@0.16.3 + - @types/hoist-non-react-statics@3.3.5 + - @types/prop-types@15.7.11 + - @types/react@18.2.39 + - @types/scheduler@0.16.8 - @types/use-sync-external-store@0.0.3 These packages each contain the following license and notice below: @@ -128,7 +98,7 @@ MIT License The following npm package may be included in this product: - - @yext/analytics@0.6.4 + - @yext/analytics@0.6.5 This package contains the following license and notice below: @@ -169,8 +139,8 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. The following npm packages may be included in this product: - - @yext/chat-core@0.7.0 - - @yext/chat-headless@0.7.1 + - @yext/chat-core@0.7.5 + - @yext/chat-headless@0.7.2 These packages each contain the following license and notice below: @@ -458,11 +428,9 @@ SOFTWARE. The following npm packages may be included in this product: - - react-dom@18.2.0 - react-is@16.13.1 - react-is@18.2.0 - react@18.2.0 - - scheduler@0.23.0 - use-sync-external-store@1.2.0 These packages each contain the following license and notice below: @@ -493,8 +461,8 @@ SOFTWARE. The following npm packages may be included in this product: - - react-redux@8.1.2 - - redux@4.2.1 + - react-redux@8.1.3 + - redux-thunk@2.4.2 These packages each contain the following license and notice below: @@ -524,7 +492,7 @@ SOFTWARE. The following npm package may be included in this product: - - redux-thunk@2.4.2 + - redux@4.2.1 This package contains the following license and notice below: @@ -624,7 +592,7 @@ This package contains the following license and notice below: The following npm package may be included in this product: - - ulidx@2.1.0 + - ulidx@2.2.1 This package contains the following license and notice below: diff --git a/packages/chat-headless/THIRD-PARTY-NOTICES b/packages/chat-headless/THIRD-PARTY-NOTICES index 5348428..788154a 100644 --- a/packages/chat-headless/THIRD-PARTY-NOTICES +++ b/packages/chat-headless/THIRD-PARTY-NOTICES @@ -3,7 +3,7 @@ https://www.npmjs.com/package/generate-license-file The following npm package may be included in this product: - - @babel/runtime@7.22.15 + - @babel/runtime@7.23.5 This package contains the following license and notice below: @@ -34,7 +34,7 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. The following npm package may be included in this product: - - @reduxjs/toolkit@1.9.5 + - @reduxjs/toolkit@1.9.7 This package contains the following license and notice below: @@ -64,7 +64,7 @@ SOFTWARE. The following npm package may be included in this product: - - @yext/analytics@0.6.4 + - @yext/analytics@0.6.5 This package contains the following license and notice below: @@ -397,7 +397,7 @@ This package contains the following license and notice below: The following npm package may be included in this product: - - ulidx@2.1.0 + - ulidx@2.2.1 This package contains the following license and notice below: diff --git a/packages/chat-headless/docs/chat-headless.chatheadless.md b/packages/chat-headless/docs/chat-headless.chatheadless.md index e5275c9..1fe0190 100644 --- a/packages/chat-headless/docs/chat-headless.chatheadless.md +++ b/packages/chat-headless/docs/chat-headless.chatheadless.md @@ -27,6 +27,7 @@ export interface ChatHeadless | [setContext(context)](./chat-headless.chatheadless.setcontext.md) | Sets [MetaState.context](./chat-headless.metastate.context.md) to the specified context. | | [setMessageNotes(notes)](./chat-headless.chatheadless.setmessagenotes.md) | Sets [ConversationState.notes](./chat-headless.conversationstate.notes.md) to the specified notes | | [setMessages(messages)](./chat-headless.chatheadless.setmessages.md) | Sets [ConversationState.messages](./chat-headless.conversationstate.messages.md) to the specified messages | +| [setMessageSuggestions(messageSuggestions)](./chat-headless.chatheadless.setmessagesuggestions.md) | Sets [ConversationState.messageSuggestions](./chat-headless.conversationstate.messagesuggestions.md) to the specified string array | | [setState(state)](./chat-headless.chatheadless.setstate.md) | Sets the [State](./chat-headless.state.md) to the specified state. | | [streamNextMessage(text, source)](./chat-headless.chatheadless.streamnextmessage.md) | Performs a Chat Stream API request for the next message generated by chat bot using the conversation state (e.g. message history and notes). The new message's "text" field is continously updated as tokens from the stream are consumed. Remaining conversation state are updated once the final event from the stream is recieved. | diff --git a/packages/chat-headless/docs/chat-headless.chatheadless.setmessagesuggestions.md b/packages/chat-headless/docs/chat-headless.chatheadless.setmessagesuggestions.md new file mode 100644 index 0000000..62d7c76 --- /dev/null +++ b/packages/chat-headless/docs/chat-headless.chatheadless.setmessagesuggestions.md @@ -0,0 +1,24 @@ + + +[Home](./index.md) > [@yext/chat-headless](./chat-headless.md) > [ChatHeadless](./chat-headless.chatheadless.md) > [setMessageSuggestions](./chat-headless.chatheadless.setmessagesuggestions.md) + +## ChatHeadless.setMessageSuggestions() method + +Sets [ConversationState.messageSuggestions](./chat-headless.conversationstate.messagesuggestions.md) to the specified string array + +**Signature:** + +```typescript +setMessageSuggestions(messageSuggestions: string[] | undefined): void; +``` + +## Parameters + +| Parameter | Type | Description | +| --- | --- | --- | +| messageSuggestions | string\[\] \| undefined | the list of strings to be given as suggested messages | + +**Returns:** + +void + diff --git a/packages/chat-headless/docs/chat-headless.conversationstate.md b/packages/chat-headless/docs/chat-headless.conversationstate.md index 790af63..414c804 100644 --- a/packages/chat-headless/docs/chat-headless.conversationstate.md +++ b/packages/chat-headless/docs/chat-headless.conversationstate.md @@ -20,5 +20,6 @@ export interface ConversationState | [conversationId?](./chat-headless.conversationstate.conversationid.md) | | string | _(Optional)_ The id of the current conversation. | | [isLoading](./chat-headless.conversationstate.isloading.md) | | boolean | Whether the next message is currently processing or has started responding. | | [messages](./chat-headless.conversationstate.messages.md) | | Message\[\] | The messages in a conversation. | +| [messageSuggestions?](./chat-headless.conversationstate.messagesuggestions.md) | | string\[\] | _(Optional)_ A set of strings that can be provided to the user as pre-written messages to send. | | [notes?](./chat-headless.conversationstate.notes.md) | | MessageNotes | _(Optional)_ Information relevant to the current state of the conversation, generated and provided by Chat API. | diff --git a/packages/chat-headless/docs/chat-headless.conversationstate.messagesuggestions.md b/packages/chat-headless/docs/chat-headless.conversationstate.messagesuggestions.md new file mode 100644 index 0000000..eb25f4d --- /dev/null +++ b/packages/chat-headless/docs/chat-headless.conversationstate.messagesuggestions.md @@ -0,0 +1,13 @@ + + +[Home](./index.md) > [@yext/chat-headless](./chat-headless.md) > [ConversationState](./chat-headless.conversationstate.md) > [messageSuggestions](./chat-headless.conversationstate.messagesuggestions.md) + +## ConversationState.messageSuggestions property + +A set of strings that can be provided to the user as pre-written messages to send. + +**Signature:** + +```typescript +messageSuggestions?: string[]; +``` diff --git a/packages/chat-headless/etc/chat-headless.api.md b/packages/chat-headless/etc/chat-headless.api.md index 072d3ac..c2b00fb 100644 --- a/packages/chat-headless/etc/chat-headless.api.md +++ b/packages/chat-headless/etc/chat-headless.api.md @@ -50,6 +50,7 @@ export interface ChatHeadless { setContext(context: unknown): void; setMessageNotes(notes: MessageNotes): void; setMessages(messages: Message[]): void; + setMessageSuggestions(messageSuggestions: string[] | undefined): void; setState(state: State): void; get state(): State; // @internal @@ -63,6 +64,7 @@ export interface ConversationState { conversationId?: string; isLoading: boolean; messages: Message[]; + messageSuggestions?: string[]; notes?: MessageNotes; } diff --git a/packages/chat-headless/package.json b/packages/chat-headless/package.json index 0b3345f..6a4cd26 100644 --- a/packages/chat-headless/package.json +++ b/packages/chat-headless/package.json @@ -1,6 +1,6 @@ { "name": "@yext/chat-headless", - "version": "0.7.2", + "version": "0.7.3", "description": "A library for powering UI components for Yext Chat integrations", "main": "./dist/commonjs/src/index.js", "module": "./dist/esm/src/index.mjs", diff --git a/packages/chat-headless/src/ChatHeadlessImpl.ts b/packages/chat-headless/src/ChatHeadlessImpl.ts index e0ec9a0..23da6d3 100644 --- a/packages/chat-headless/src/ChatHeadlessImpl.ts +++ b/packages/chat-headless/src/ChatHeadlessImpl.ts @@ -15,6 +15,7 @@ import { setIsLoading, setMessageNotes, setMessages, + setMessageSuggestions, addMessage, STATE_SESSION_STORAGE_KEY, } from "./slices/conversation"; @@ -170,11 +171,15 @@ export class ChatHeadlessImpl implements ChatHeadless { setChatLoadingStatus(isLoading: boolean) { this.stateManager.dispatch(setIsLoading(isLoading)); } - + setCanSendMessage(canSendMessage: boolean) { this.stateManager.dispatch(setCanSendMessage(canSendMessage)); } + setMessageSuggestions(messageSuggestions: string[] | undefined) { + this.stateManager.dispatch(setMessageSuggestions(messageSuggestions)); + } + /** * Sets {@link ConversationState.conversationId} to the specified id * diff --git a/packages/chat-headless/src/models/ChatHeadless.ts b/packages/chat-headless/src/models/ChatHeadless.ts index da832a9..be4f333 100644 --- a/packages/chat-headless/src/models/ChatHeadless.ts +++ b/packages/chat-headless/src/models/ChatHeadless.ts @@ -88,6 +88,14 @@ export interface ChatHeadless { * @param canSendMessage - the state to set */ setCanSendMessage(canSendMessage: boolean): void; + /** + * Sets {@link ConversationState.messageSuggestions} to the specified string array + * + * @public + * + * @param messageSuggestions - the list of strings to be given as suggested messages + */ + setMessageSuggestions(messageSuggestions: string[] | undefined): void; /** * Adds additional client SDKs to the base event payload for Yext Analytics API. * diff --git a/packages/chat-headless/src/models/slices/ConversationState.ts b/packages/chat-headless/src/models/slices/ConversationState.ts index df5e2dc..c7bf6bc 100644 --- a/packages/chat-headless/src/models/slices/ConversationState.ts +++ b/packages/chat-headless/src/models/slices/ConversationState.ts @@ -19,4 +19,6 @@ export interface ConversationState { * This is set to false when a previous message is being processed. */ canSendMessage: boolean; + /** A set of strings that can be provided to the user as pre-written messages to send. */ + messageSuggestions?: string[]; } diff --git a/packages/chat-headless/src/slices/conversation.ts b/packages/chat-headless/src/slices/conversation.ts index 7e10720..90b374f 100644 --- a/packages/chat-headless/src/slices/conversation.ts +++ b/packages/chat-headless/src/slices/conversation.ts @@ -65,6 +65,12 @@ export const conversationSlice = createSlice({ ) => { state.canSendMessage = action.payload; }, + setMessageSuggestions: ( + state: ConversationState, + action: PayloadAction + ) => { + state.messageSuggestions = action.payload; + }, }, }); @@ -75,5 +81,6 @@ export const { setIsLoading, setConversationId, setCanSendMessage, + setMessageSuggestions, } = conversationSlice.actions; export default conversationSlice.reducer; diff --git a/packages/chat-headless/tests/chatheadless.test.ts b/packages/chat-headless/tests/chatheadless.test.ts index eb3fdbf..1648655 100644 --- a/packages/chat-headless/tests/chatheadless.test.ts +++ b/packages/chat-headless/tests/chatheadless.test.ts @@ -149,6 +149,20 @@ describe("setters work as expected", () => { }); }); + it("setMessageSuggestions works as expected", () => { + const chatHeadless = provideChatHeadless(config); + const stateDispatchSpy = jest.spyOn( + ReduxStateManager.prototype, + "dispatch" + ); + chatHeadless.setMessageSuggestions(["foo", "bar"]); + expect(stateDispatchSpy).toBeCalledTimes(1); + expect(stateDispatchSpy).toBeCalledWith({ + type: "conversation/setMessageSuggestions", + payload: ["foo", "bar"], + }); + }); + it("setChatLoadingStatus works as expected", () => { const chatHeadless = provideChatHeadless(config); const stateDispatchSpy = jest.spyOn(