Skip to content

Commit 86493ac

Browse files
committed
docs: Update docs
1 parent 22a2d50 commit 86493ac

File tree

10 files changed

+168
-70
lines changed

10 files changed

+168
-70
lines changed

docs/api/events.md

+44-3
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ Below is a list of available events with a brief description for each one. You c
3131
| RcbShowToastEvent | Emitted when a toast message is displayed. |
3232
| RcbStartStreamMessageEvent | Emitted when the chatbot starts streaming a message. |
3333
| RcbStopStreamMessageEvent | Emitted when the chatbot stops streaming a message. |
34+
| RcbStartSpeakAudioEvent | Emitted when a message is read out (audio starts to play) |
3435
| RcbToggleAudioEvent | Emitted when the audio is toggled on or off. |
3536
| RcbToggleChatWindowEvent | Emitted when the chat window is toggled open or closed. |
3637
| RcbToggleNotificationsEvent | Emitted when notifications are toggled on or off. |
@@ -253,9 +254,12 @@ Emitted before a message is injected into the chat.
253254
- Event is **preventable** with `event.preventDefault()`.
254255

255256
#### Data
256-
| Name | Type | Description |
257-
|-----------|-----------|-----------------------------------------------------------------|
258-
| message | `Message` | The message being sent into the chat. |
257+
| Name | Type | Description |
258+
|------------------|----------------------|-----------------------------------------------------------------|
259+
| message | `Message` | The message being sent into the chat. |
260+
| simStreamChunker | `function` \| `null` | A custom function to parse messages for simulated streaming |
261+
262+
Note: The `simStreamChunker` function takes in a string and returns an array of strings. By default, this field is null and strings are split per-character. A custom function can be passed in to control how simulated streaming is carried out. For example, in the implementation of the [**HTML Renderer Plugin**](https://www.npmjs.com/package/@rcb-plugins/html-renderer), a custom function is passed in to skip over html tags when simulating message stream.
259263

260264
#### Code Example
261265
```jsx
@@ -428,6 +432,43 @@ const MyComponent = () => {
428432
};
429433
```
430434

435+
### RcbStartSpeakAudioEvent
436+
437+
#### Description
438+
Emitted when a message is read out (audio starts to play).
439+
440+
#### Note
441+
- Requires `settings.event.rcbStartSpeakAudio` to be set to true.
442+
- Event is **preventable** with `event.preventDefault()`.
443+
444+
#### Data
445+
| Name | Type | Description |
446+
|------------|-----------|-----------------------------------------------------------------------|
447+
| textToRead | `string` | The message string that is to be read out. |
448+
449+
#### Code Example
450+
```jsx
451+
import { useEffect } from "react";
452+
import { RcbStartSpeakAudioEvent } from "react-chatbotify";
453+
454+
const MyComponent = () => {
455+
useEffect(() => {
456+
const handleStartSpeakAudio = (event: RcbStartSpeakAudioEvent) => {
457+
// handle the start speak audio event
458+
};
459+
460+
window.addEventListener("rcb-start-speak-audio", handleStartSpeakAudio);
461+
return () => {
462+
window.removeEventListener("rcb-start-speak-audio", handleStartSpeakAudio);
463+
};
464+
}, []);
465+
466+
return (
467+
<ExampleComponent/>
468+
);
469+
};
470+
```
471+
431472
### RcbToggleAudioEvent
432473

433474
#### Description

docs/api/hooks.md

+6-5
Original file line numberDiff line numberDiff line change
@@ -156,11 +156,12 @@ const MyNestedComponent = () => {
156156
The `useChatHistory` hook allows you to show, retrieve and set chat history messages.
157157

158158
#### Return Values
159-
| Name | Type | Description |
160-
| ------------------- | ---------- | ------------------------------------------------------------- |
161-
| showChatHistory | `function` | Shows the chat history messages on the chatbot. |
162-
| getHistoryMessages | `function` | Retrieves the chat history messages. |
163-
| setHistoryMessages | `function` | Sets the chat history messages (note that this is permanent). |
159+
| Name | Type | Description |
160+
| -------------------- | ---------- | ------------------------------------------------------------- |
161+
| showChatHistory | `function` | Shows the chat history messages on the chatbot. |
162+
| getHistoryMessages | `function` | Retrieves the chat history messages. |
163+
| setHistoryMessages | `function` | Sets the chat history messages (note that this is permanent). |
164+
| hasChatHistoryLoaded | `boolean` | Boolean indicating if chat history has been loaded. |
164165

165166
#### Code Example
166167
```jsx

docs/api/settings.md

-4
Original file line numberDiff line numberDiff line change
@@ -110,15 +110,13 @@ const DefaultSettings: Settings = {
110110
avatar: userAvatar,
111111
simStream: false,
112112
streamSpeed: 30,
113-
dangerouslySetInnerHtml: false,
114113
},
115114
botBubble: {
116115
animate: true,
117116
showAvatar: false,
118117
avatar: botAvatar,
119118
simStream: false,
120119
streamSpeed: 30,
121-
dangerouslySetInnerHtml: false,
122120
},
123121
voice: {
124122
disabled: true,
@@ -298,7 +296,6 @@ Properties here handle the chat bubble for messages sent by the bot.
298296
| avatar | `string` | - | Image import or URL for the avatar to be displayed for bot chat bubbles. | |
299297
| simStream | `boolean` | false | Specifies whether to simulate text messages from the bot as a stream. |
300298
| streamSpeed | `number` | 30 | Specifies the interval in milliseconds between streaming each character (ignored if `simStream` is false). | |
301-
| dangerouslySetInnerHtml | `boolean` | false | Specifies whether to allow setting of raw HTML content within a bot message bubble (if `true`, do sanitize input strings and use with caution). |
302299

303300
### chatButton
304301

@@ -506,7 +503,6 @@ Properties here handle the chat bubble for messages sent by the user.
506503
| avatar | `string` | - | Image import or URL for the avatar to be displayed for user chat bubbles. |
507504
| simStream | `boolean` | false | Specifies whether to simulate text messages from the user as a stream. |
508505
| streamSpeed | `number` | 30 | Specifies the interval in milliseconds between streaming each character (ignored if `simStream` is false). |
509-
| dangerouslySetInnerHtml | `boolean` | false | Specifies whether to allow setting of raw HTML content within a user message bubble (if `true`, do sanitize input strings and use with caution). |
510506

511507
### voice
512508

docs/concepts/conversations.md

+7-6
Original file line numberDiff line numberDiff line change
@@ -158,12 +158,13 @@ For details and usage on each of these parameters, you may consult the [**API do
158158

159159
Not to be confused with `message` from the section on [**Attributes**](/docs/concepts/conversations#attributes), the `Message` component here represents the interactions between the user and the bot. Every element in the chatbot body (including custom components) are considered a Message (as **outlined in red** on the image above). Within a message you will find **5 properties**:
160160

161-
- id (required) - an auto-generated uuidv4 `string`, uniquely identifying a message
162-
- content (required) - a `string` or `JSX.Element`, representing the content of the message
163-
- contentWrapper (optional) - a react component that wraps the message content (received via children) to enable custom styling or layout (niche use-case)
164-
- sender (required) - a `string` representing message sender (can be `user`, `bot` or `system`)
165-
- type (required) - a `string` that specifies "string" (for plain text) or "object" (for JSX elements)
166-
- timestamp (required) - a `string` representing the time the message was sent in UTC
161+
- id **(required)** - an auto-generated uuidv4 `string`, uniquely identifying a message
162+
- content **(required)** - a `string` or `JSX.Element`, representing the content of the message
163+
- sender **(required)** - a `string` representing message sender (can be `user`, `bot` or `system`)
164+
- type **(required)** - a `string` that specifies "string" (for plain text) or "object" (for JSX elements)
165+
- timestamp **(required)** - a `string` representing the time the message was sent in UTC
166+
- contentWrapper **(optional)** - a react component that wraps the message content (received via children) to enable custom styling or layout (niche use-case)
167+
- tags **(optional)** - an array of strings, typically used by plugins to tag and identify messages that are processed
167168

168169
:::info Info
169170

docs/examples/html_render.md

+54
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
---
2+
sidebar_position: 17
3+
title: HTML Render
4+
description: html render chatbot example
5+
keywords: [react, chat, chatbot, chatbotify]
6+
---
7+
8+
# HTML Render
9+
10+
The following is an example showing how you may allow markup syntax (e.g. `<br/>`, `<b>`, `<hr/>`) in user chat bubbles and bot chat bubbles. It leverages on the [**HTML Renderer Plugin**](https://www.npmjs.com/package/@rcb-plugins/html-renderer), which is maintained separately on the [**React ChatBotify Plugins**](https://github.com/orgs/React-ChatBotify-Plugins) organization. If you require support with the plugin, please reach out to support on the [**plugins discord**](https://discord.gg/J6pA4v3AMW) instead.
11+
12+
:::tip
13+
14+
If you're looking to render markdown messages, you may refer to the [**markdown render example**](/docs/examples/markdown_render.md) instead.
15+
16+
:::
17+
18+
```jsx live noInline title=MyChatBot.js
19+
const MyChatBot = () => {
20+
// loads html renderer plugin to be passed into chatbot
21+
const plugins = [HtmlRenderer()];
22+
23+
const flow: Flow = {
24+
start: {
25+
message: "<b>Hey there, I am a bolded sentence!</b> Try typing a bolded message to me!",
26+
path: "reply",
27+
renderHtml: ["BOT", "USER"],
28+
} as HtmlRendererBlock,
29+
reply: {
30+
message: "Interesting, let's try again?",
31+
options: ["Try again"],
32+
chatDisabled: true,
33+
path: "start",
34+
renderHtml: ["BOT", "USER"],
35+
} as HtmlRendererBlock,
36+
}
37+
38+
const settings = {
39+
general: {
40+
embedded: true
41+
},
42+
chatHistory: {
43+
storageKey: "example_html_render"
44+
}
45+
}
46+
47+
return (
48+
<ChatBot plugins={plugins} settings={settings} flow={flow}
49+
/>
50+
);
51+
};
52+
53+
render(<MyChatBot/>)
54+
```

docs/examples/markdown_render.md

+6
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,12 @@ keywords: [react, chat, chatbot, chatbotify]
99

1010
The following is an example for rendering markdown messages. It leverages on the [**Markdown Renderer Plugin**](https://www.npmjs.com/package/@rcb-plugins/markdown-renderer), which is maintained separately on the [**React ChatBotify Plugins**](https://github.com/orgs/React-ChatBotify-Plugins) organization. If you require support with the plugin, please reach out to support on the [**plugins discord**](https://discord.gg/J6pA4v3AMW) instead.
1111

12+
:::tip
13+
14+
If you're looking to render html markup messages, you may refer to the [**html render example**](/docs/examples/html_render.md) instead.
15+
16+
:::
17+
1218
```jsx live noInline title=MyChatBot.js
1319
const MyChatBot = () => {
1420
// loads markdown renderer plugin to be passed into chatbot

docs/examples/markup_message.md

-41
This file was deleted.

package-lock.json

+43-9
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+3-2
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,14 @@
2222
"@docusaurus/theme-live-codeblock": "^3.2.0",
2323
"@google/generative-ai": "^0.2.1",
2424
"@mdx-js/react": "^3.0.1",
25+
"@rcb-plugins/html-renderer": "^0.1.0",
2526
"@rcb-plugins/input-validator": "^0.1.1",
26-
"@rcb-plugins/markdown-renderer": "^0.1.0",
27+
"@rcb-plugins/markdown-renderer": "^0.1.1",
2728
"clsx": "^1.2.1",
2829
"openai": "^4.47.1",
2930
"prism-react-renderer": "^2.3.1",
3031
"react": "^18.2.0",
31-
"react-chatbotify": "^2.0.0-beta.29",
32+
"react-chatbotify": "^2.0.0-beta.31",
3233
"react-dom": "^18.2.0",
3334
"react-github-btn": "^1.4.0"
3435
},

src/theme/ReactLiveScope/index.js

+5
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import ExecutionEnvironment from "@docusaurus/ExecutionEnvironment";
66
let ChatBot = null;
77
let InputValidator = null;
88
let MarkdownRenderer = null;
9+
let HtmlRenderer = null;
910
let reactChatbotify = {};
1011

1112
if (ExecutionEnvironment.canUseDOM) {
@@ -20,6 +21,9 @@ if (ExecutionEnvironment.canUseDOM) {
2021

2122
// imports rcb plugin - markdown renderer
2223
MarkdownRenderer = require("@rcb-plugins/markdown-renderer");
24+
25+
// imports rcb plugin - html renderer
26+
HtmlRenderer = require("@rcb-plugins/html-renderer");
2327
}
2428

2529
const ReactLiveScope = {
@@ -28,6 +32,7 @@ const ReactLiveScope = {
2832
...reactChatbotify,
2933
InputValidator,
3034
MarkdownRenderer,
35+
HtmlRenderer,
3136
GoogleGenerativeAI,
3237
OpenAI,
3338
};

0 commit comments

Comments
 (0)