Skip to content

Commit 6aa7f23

Browse files
authored
Auto-retry from a 5XX Chat API response (#69)
- created a new hook, `useSendMessageWithRetries`, that sends a message to the chat API, and perform retries if the API returns a 5xx status code. - updated `ChatInput` and `MessageSuggestions` component to use the new hook to retry once for failed 5xx responses. - updated `ChatPanel` to show a retry text next to loading dots ("Error occurred. Retrying") Will deploy a new minor (0.9.0) once merged J=CLIP-1189 TEST=manual&auto see unit tests passed see that it works as expected in test-site https://github.com/yext/chat-ui-react/assets/36055303/272ee401-11cc-410e-a048-a3634b063917
1 parent 8601599 commit 6aa7f23

20 files changed

+347
-140
lines changed

THIRD-PARTY-NOTICES

Lines changed: 52 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
3131

3232
The following NPM package may be included in this product:
3333

34-
- @reduxjs/toolkit@1.9.5
34+
- @reduxjs/toolkit@1.9.7
3535

3636
This package contains the following license and notice below:
3737

@@ -62,6 +62,7 @@ SOFTWARE.
6262
The following NPM packages may be included in this product:
6363

6464
- @types/hast@2.3.4
65+
- @types/hoist-non-react-statics@3.3.5
6566
- @types/mdast@3.0.11
6667
- @types/parse5@5.0.3
6768
- @types/prop-types@15.7.5
@@ -99,37 +100,7 @@ MIT License
99100

100101
The following NPM package may be included in this product:
101102

102-
- @types/hoist-non-react-statics@3.3.1
103-
104-
This package contains the following license and notice below:
105-
106-
MIT License
107-
108-
Copyright (c) Microsoft Corporation. All rights reserved.
109-
110-
Permission is hereby granted, free of charge, to any person obtaining a copy
111-
of this software and associated documentation files (the "Software"), to deal
112-
in the Software without restriction, including without limitation the rights
113-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
114-
copies of the Software, and to permit persons to whom the Software is
115-
furnished to do so, subject to the following conditions:
116-
117-
The above copyright notice and this permission notice shall be included in all
118-
copies or substantial portions of the Software.
119-
120-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
121-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
122-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
123-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
124-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
125-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
126-
SOFTWARE
127-
128-
-----------
129-
130-
The following NPM package may be included in this product:
131-
132-
- @yext/analytics@0.6.4
103+
- @yext/analytics@0.6.6
133104

134105
This package contains the following license and notice below:
135106

@@ -170,9 +141,9 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
170141

171142
The following NPM packages may be included in this product:
172143

173-
- @yext/chat-core@0.7.6
174-
- @yext/chat-headless-react@0.6.1
175-
- @yext/chat-headless@0.7.1
144+
- @yext/chat-core@0.8.0
145+
- @yext/chat-headless-react@0.7.0
146+
- @yext/chat-headless@0.8.0
176147

177148
These packages each contain the following license and notice below:
178149

@@ -827,7 +798,7 @@ THE SOFTWARE.
827798

828799
The following NPM package may be included in this product:
829800

830-
- layerr@2.0.1
801+
- layerr@2.1.0
831802

832803
This package contains the following license and notice below:
833804

@@ -1236,7 +1207,7 @@ The following NPM packages may be included in this product:
12361207
- react-is@18.2.0
12371208
- react@18.2.0
12381209
- scheduler@0.23.0
1239-
- use-sync-external-store@1.2.0
1210+
- use-sync-external-store@1.2.2
12401211

12411212
These packages each contain the following license and notice below:
12421213

@@ -1296,31 +1267,31 @@ SOFTWARE.
12961267

12971268
The following NPM packages may be included in this product:
12981269

1299-
- react-redux@8.1.2
1300-
- redux@4.2.1
1270+
- react-redux@8.1.3
1271+
- redux-thunk@2.4.2
13011272

13021273
These packages each contain the following license and notice below:
13031274

1304-
The MIT License (MIT)
1305-
1306-
Copyright (c) 2015-present Dan Abramov
1307-
1308-
Permission is hereby granted, free of charge, to any person obtaining a copy
1309-
of this software and associated documentation files (the "Software"), to deal
1310-
in the Software without restriction, including without limitation the rights
1311-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
1312-
copies of the Software, and to permit persons to whom the Software is
1313-
furnished to do so, subject to the following conditions:
1314-
1315-
The above copyright notice and this permission notice shall be included in all
1316-
copies or substantial portions of the Software.
1317-
1318-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
1319-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
1320-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
1321-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
1322-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
1323-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
1275+
The MIT License (MIT)
1276+
1277+
Copyright (c) 2015-present Dan Abramov
1278+
1279+
Permission is hereby granted, free of charge, to any person obtaining a copy
1280+
of this software and associated documentation files (the "Software"), to deal
1281+
in the Software without restriction, including without limitation the rights
1282+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
1283+
copies of the Software, and to permit persons to whom the Software is
1284+
furnished to do so, subject to the following conditions:
1285+
1286+
The above copyright notice and this permission notice shall be included in all
1287+
copies or substantial portions of the Software.
1288+
1289+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
1290+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
1291+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
1292+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
1293+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
1294+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
13241295
SOFTWARE.
13251296

13261297
-----------
@@ -1356,30 +1327,30 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
13561327

13571328
The following NPM package may be included in this product:
13581329

1359-
- redux-thunk@2.4.2
1330+
- redux@4.2.1
13601331

13611332
This package contains the following license and notice below:
13621333

1363-
The MIT License (MIT)
1364-
1365-
Copyright (c) 2015-present Dan Abramov
1366-
1367-
Permission is hereby granted, free of charge, to any person obtaining a copy
1368-
of this software and associated documentation files (the "Software"), to deal
1369-
in the Software without restriction, including without limitation the rights
1370-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
1371-
copies of the Software, and to permit persons to whom the Software is
1372-
furnished to do so, subject to the following conditions:
1373-
1374-
The above copyright notice and this permission notice shall be included in all
1375-
copies or substantial portions of the Software.
1376-
1377-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
1378-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
1379-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
1380-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
1381-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
1382-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
1334+
The MIT License (MIT)
1335+
1336+
Copyright (c) 2015-present Dan Abramov
1337+
1338+
Permission is hereby granted, free of charge, to any person obtaining a copy
1339+
of this software and associated documentation files (the "Software"), to deal
1340+
in the Software without restriction, including without limitation the rights
1341+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
1342+
copies of the Software, and to permit persons to whom the Software is
1343+
furnished to do so, subject to the following conditions:
1344+
1345+
The above copyright notice and this permission notice shall be included in all
1346+
copies or substantial portions of the Software.
1347+
1348+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
1349+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
1350+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
1351+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
1352+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
1353+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
13831354
SOFTWARE.
13841355

13851356
-----------
@@ -1783,7 +1754,7 @@ THE SOFTWARE.
17831754

17841755
The following NPM package may be included in this product:
17851756

1786-
- ulidx@2.1.0
1757+
- ulidx@2.3.0
17871758

17881759
This package contains the following license and notice below:
17891760

docs/chat-ui-react.chatinput.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,14 @@ A component that allows user to input message and send to Chat API.
99
**Signature:**
1010

1111
```typescript
12-
export declare function ChatInput({ placeholder, stream, inputAutoFocus, handleError, sendButtonIcon, customCssClasses, onSend, }: ChatInputProps): React.JSX.Element;
12+
export declare function ChatInput({ placeholder, stream, inputAutoFocus, handleError, sendButtonIcon, customCssClasses, onSend, onRetry, }: ChatInputProps): React.JSX.Element;
1313
```
1414

1515
## Parameters
1616

1717
| Parameter | Type | Description |
1818
| --- | --- | --- |
19-
| { placeholder, stream, inputAutoFocus, handleError, sendButtonIcon, customCssClasses, onSend, } | [ChatInputProps](./chat-ui-react.chatinputprops.md) | |
19+
| { placeholder, stream, inputAutoFocus, handleError, sendButtonIcon, customCssClasses, onSend, onRetry, } | [ChatInputProps](./chat-ui-react.chatinputprops.md) | |
2020

2121
**Returns:**
2222

docs/chat-ui-react.chatinputprops.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ export interface ChatInputProps
1919
| [customCssClasses?](./chat-ui-react.chatinputprops.customcssclasses.md) | | [ChatInputCssClasses](./chat-ui-react.chatinputcssclasses.md) | _(Optional)_ CSS classes for customizing the component styling. |
2020
| [handleError?](./chat-ui-react.chatinputprops.handleerror.md) | | (e: unknown) => void | _(Optional)_ A function which is called when an error occurs from Chat API while processing the user's message. By default, the error is logged to the console and an error message is added to state. |
2121
| [inputAutoFocus?](./chat-ui-react.chatinputprops.inputautofocus.md) | | boolean | _(Optional)_ Enable auto focus for the input box. Defaults to false. |
22+
| [onRetry?](./chat-ui-react.chatinputprops.onretry.md) | | (e: unknown) => void | _(Optional)_ A function which is called when a retryable error occurs from Chat API while processing the user's message. |
2223
| [onSend?](./chat-ui-react.chatinputprops.onsend.md) | | (message: string) => void | _(Optional)_ A callback which is called when user sends a message. |
2324
| [placeholder?](./chat-ui-react.chatinputprops.placeholder.md) | | string | _(Optional)_ The input's placeholder text when no text has been entered by the user. Defaults to "Type a message...". |
2425
| [sendButtonIcon?](./chat-ui-react.chatinputprops.sendbuttonicon.md) | | JSX.Element | _(Optional)_ Custom icon for the send button. |
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<!-- Do not edit this file. It is automatically generated by API Documenter. -->
2+
3+
[Home](./index.md) &gt; [@yext/chat-ui-react](./chat-ui-react.md) &gt; [ChatInputProps](./chat-ui-react.chatinputprops.md) &gt; [onRetry](./chat-ui-react.chatinputprops.onretry.md)
4+
5+
## ChatInputProps.onRetry property
6+
7+
A function which is called when a retryable error occurs from Chat API while processing the user's message.
8+
9+
**Signature:**
10+
11+
```typescript
12+
onRetry?: (e: unknown) => void;
13+
```

docs/chat-ui-react.chatpanelprops.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,5 @@ export interface ChatPanelProps extends Omit<MessageBubbleProps, "customCssClass
2222
| [header?](./chat-ui-react.chatpanelprops.header.md) | | ReactNode | _(Optional)_ A header to render at the top of the panel. |
2323
| [messageSuggestions?](./chat-ui-react.chatpanelprops.messagesuggestions.md) | | string\[\] | _(Optional)_ A set of pre-written initial messages that the user can click on instead of typing their own. |
2424
| [onLinkClick?](./chat-ui-react.chatpanelprops.onlinkclick.md) | | (href?: string) =&gt; void | _(Optional)_ A callback which is called when user clicks a link. |
25+
| [retryText?](./chat-ui-react.chatpanelprops.retrytext.md) | | string | _(Optional)_ Text to display when retrying. Defaults to "Error occurred. Retrying". |
2526
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<!-- Do not edit this file. It is automatically generated by API Documenter. -->
2+
3+
[Home](./index.md) &gt; [@yext/chat-ui-react](./chat-ui-react.md) &gt; [ChatPanelProps](./chat-ui-react.chatpanelprops.md) &gt; [retryText](./chat-ui-react.chatpanelprops.retrytext.md)
4+
5+
## ChatPanelProps.retryText property
6+
7+
Text to display when retrying. Defaults to "Error occurred. Retrying".
8+
9+
**Signature:**
10+
11+
```typescript
12+
retryText?: string;
13+
```

docs/chat-ui-react.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
| Function | Description |
1010
| --- | --- |
1111
| [ChatHeader({ title, showRestartButton, restartButtonIcon, showCloseButton, closeButtonIcon, onClose, customCssClasses, })](./chat-ui-react.chatheader.md) | A component that renders the header of a chat bot panel, including the title and a button to reset the conversation. |
12-
| [ChatInput({ placeholder, stream, inputAutoFocus, handleError, sendButtonIcon, customCssClasses, onSend, })](./chat-ui-react.chatinput.md) | A component that allows user to input message and send to Chat API. |
12+
| [ChatInput({ placeholder, stream, inputAutoFocus, handleError, sendButtonIcon, customCssClasses, onSend, onRetry, })](./chat-ui-react.chatinput.md) | A component that allows user to input message and send to Chat API. |
1313
| [ChatPanel(props)](./chat-ui-react.chatpanel.md) | A component that renders a full panel for chat bot interactions. This includes the message bubbles for the conversation, input box with send button, and header (if provided). |
1414
| [ChatPopUp(props)](./chat-ui-react.chatpopup.md) | A component that renders a popup button that displays and hides a panel for chat bot interactions. |
1515
| [MessageBubble({ message, showFeedbackButtons, showTimestamp, customCssClasses, formatTimestamp, onLinkClick, })](./chat-ui-react.messagebubble.md) | A component that displays the provided message. |

docs/chat-ui-react.messagesuggestionsprops.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,5 +18,8 @@ export interface MessageSuggestionsProps
1818
| --- | --- | --- | --- |
1919
| [customCssClasses?](./chat-ui-react.messagesuggestionsprops.customcssclasses.md) | | [MessageSuggestionCssClasses](./chat-ui-react.messagesuggestioncssclasses.md) | _(Optional)_ CSS classes for customizing the component styling. |
2020
| [handleError?](./chat-ui-react.messagesuggestionsprops.handleerror.md) | | (e: unknown) =&gt; void | _(Optional)_ A function which is called when an error occurs from Chat API while processing the user's message. By default, the error is logged to the console and an error message is added to state. |
21+
| [onRetry?](./chat-ui-react.messagesuggestionsprops.onretry.md) | | (e: unknown) =&gt; void | _(Optional)_ A function which is called when a retryable error occurs from Chat API while processing the user's message. |
22+
| [onSend?](./chat-ui-react.messagesuggestionsprops.onsend.md) | | (message: string) =&gt; void | _(Optional)_ A callback which is called when user sends a message. |
23+
| [stream?](./chat-ui-react.messagesuggestionsprops.stream.md) | | boolean | _(Optional)_ Enable streaming behavior by making a request to Chat Streaming API. This feature is experimental, and is subject to change. Defaults to false. |
2124
| [suggestions](./chat-ui-react.messagesuggestionsprops.suggestions.md) | | string\[\] | List of clickable message suggestions to render. |
2225

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<!-- Do not edit this file. It is automatically generated by API Documenter. -->
2+
3+
[Home](./index.md) &gt; [@yext/chat-ui-react](./chat-ui-react.md) &gt; [MessageSuggestionsProps](./chat-ui-react.messagesuggestionsprops.md) &gt; [onRetry](./chat-ui-react.messagesuggestionsprops.onretry.md)
4+
5+
## MessageSuggestionsProps.onRetry property
6+
7+
A function which is called when a retryable error occurs from Chat API while processing the user's message.
8+
9+
**Signature:**
10+
11+
```typescript
12+
onRetry?: (e: unknown) => void;
13+
```
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<!-- Do not edit this file. It is automatically generated by API Documenter. -->
2+
3+
[Home](./index.md) &gt; [@yext/chat-ui-react](./chat-ui-react.md) &gt; [MessageSuggestionsProps](./chat-ui-react.messagesuggestionsprops.md) &gt; [onSend](./chat-ui-react.messagesuggestionsprops.onsend.md)
4+
5+
## MessageSuggestionsProps.onSend property
6+
7+
A callback which is called when user sends a message.
8+
9+
**Signature:**
10+
11+
```typescript
12+
onSend?: (message: string) => void;
13+
```

0 commit comments

Comments
 (0)