Skip to content

Commit

Permalink
Add message suggestions to state
Browse files Browse the repository at this point in the history
  • Loading branch information
nbramblett committed Nov 29, 2023
1 parent e1a2d54 commit 397b2c5
Show file tree
Hide file tree
Showing 14 changed files with 97 additions and 52 deletions.
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

58 changes: 13 additions & 45 deletions packages/chat-headless-react/THIRD-PARTY-NOTICES
Original file line number Diff line number Diff line change
Expand Up @@ -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:

Expand Down Expand Up @@ -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/[email protected].5
- @reduxjs/[email protected].7

This package contains the following license and notice below:

Expand Down Expand Up @@ -62,42 +62,12 @@ SOFTWARE.

-----------

The following npm package may be included in this product:

- @types/[email protected]

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/[email protected].5
- @types/[email protected]
- @types/[email protected].21
- @types/[email protected].3
- @types/[email protected].5
- @types/[email protected]
- @types/[email protected].39
- @types/[email protected].8
- @types/[email protected]

These packages each contain the following license and notice below:
Expand Down Expand Up @@ -128,7 +98,7 @@ MIT License

The following npm package may be included in this product:

- @yext/[email protected].4
- @yext/[email protected].5

This package contains the following license and notice below:

Expand Down Expand Up @@ -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/[email protected].0
- @yext/[email protected].1
- @yext/[email protected].5
- @yext/[email protected].2

These packages each contain the following license and notice below:

Expand Down Expand Up @@ -458,11 +428,9 @@ SOFTWARE.

The following npm packages may be included in this product:

- [email protected]
- [email protected]
- [email protected]
- [email protected]
- [email protected]
- [email protected]

These packages each contain the following license and notice below:
Expand Down Expand Up @@ -493,8 +461,8 @@ SOFTWARE.

The following npm packages may be included in this product:

- [email protected].2
- redux@4.2.1
- [email protected].3
- redux-thunk@2.4.2

These packages each contain the following license and notice below:

Expand Down Expand Up @@ -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:

Expand Down Expand Up @@ -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:

Expand Down
8 changes: 4 additions & 4 deletions packages/chat-headless/THIRD-PARTY-NOTICES
Original file line number Diff line number Diff line change
Expand Up @@ -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:

Expand Down Expand Up @@ -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/[email protected].5
- @reduxjs/[email protected].7

This package contains the following license and notice below:

Expand Down Expand Up @@ -64,7 +64,7 @@ SOFTWARE.

The following npm package may be included in this product:

- @yext/[email protected].4
- @yext/[email protected].5

This package contains the following license and notice below:

Expand Down Expand Up @@ -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:

Expand Down
1 change: 1 addition & 0 deletions packages/chat-headless/docs/chat-headless.chatheadless.md
Original file line number Diff line number Diff line change
Expand Up @@ -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. |

Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->

[Home](./index.md) &gt; [@yext/chat-headless](./chat-headless.md) &gt; [ChatHeadless](./chat-headless.chatheadless.md) &gt; [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

Original file line number Diff line number Diff line change
Expand Up @@ -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. |

Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<!-- Do not edit this file. It is automatically generated by API Documenter. -->

[Home](./index.md) &gt; [@yext/chat-headless](./chat-headless.md) &gt; [ConversationState](./chat-headless.conversationstate.md) &gt; [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[];
```
2 changes: 2 additions & 0 deletions packages/chat-headless/etc/chat-headless.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -63,6 +64,7 @@ export interface ConversationState {
conversationId?: string;
isLoading: boolean;
messages: Message[];
messageSuggestions?: string[];
notes?: MessageNotes;
}

Expand Down
2 changes: 1 addition & 1 deletion packages/chat-headless/package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
7 changes: 6 additions & 1 deletion packages/chat-headless/src/ChatHeadlessImpl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import {
setIsLoading,
setMessageNotes,
setMessages,
setMessageSuggestions,
addMessage,
STATE_SESSION_STORAGE_KEY,
} from "./slices/conversation";
Expand Down Expand Up @@ -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
*
Expand Down
8 changes: 8 additions & 0 deletions packages/chat-headless/src/models/ChatHeadless.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down
2 changes: 2 additions & 0 deletions packages/chat-headless/src/models/slices/ConversationState.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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[];
}
7 changes: 7 additions & 0 deletions packages/chat-headless/src/slices/conversation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,12 @@ export const conversationSlice = createSlice({
) => {
state.canSendMessage = action.payload;
},
setMessageSuggestions: (
state: ConversationState,
action: PayloadAction<string[] | undefined>
) => {
state.messageSuggestions = action.payload;
},
},
});

Expand All @@ -75,5 +81,6 @@ export const {
setIsLoading,
setConversationId,
setCanSendMessage,
setMessageSuggestions,
} = conversationSlice.actions;
export default conversationSlice.reducer;
14 changes: 14 additions & 0 deletions packages/chat-headless/tests/chatheadless.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down

0 comments on commit 397b2c5

Please sign in to comment.