A simple plugin for rendering html messages in React ChatBotify.
npm install @rcb-plugins/html-renderer
bash
npm install @rcb-plugins/html-renderer
`
2. Import the plugin:
`javascript
import HtmlRenderer from "@rcb-plugins/html-renderer";
`
3. Initialize the plugin within the plugins prop of ChatBot:
`javascript
import ChatBot from "react-chatbotify";
import HtmlRenderer from "@rcb-plugins/html-renderer";
const MyComponent = () => {
return (
);
};
`
4. Add the renderHtml attribute to the Block that requires html rendering:
`javascript
import ChatBot from "react-chatbotify";
import HtmlRenderer, { HtmlRendererBlock } from "@rcb-plugins/html-renderer";
const MyComponent = () => {
const flow = {
start: {
message: "What is your age?
",
renderHtml: ["BOT", "USER"]
} as HtmlRendererBlock
}
return (
);
};
`
The quickstart above shows how rendering of html can be done for both bot and user messages within the start block. The documentation website for the React ChatBotify Core Library also contains a live html renderer example that uses this plugin. You may wish to check it out!
$3
Html Renderer is a lightweight plugin that provides the following features to your chatbot:
- Render html in bot chat messages
- Render html in user chat messages
- Optionally pass in your own custom html component to render html your way
$3
#### Plugin Configuration
The HtmlRenderer plugin accepts a configuration object that allows you to customize its behavior and appearance. An example configuration is passed in below to initialize the plugin:
`javascript
import ChatBot from "react-chatbotify";
import HtmlRenderer from "@rcb-plugins/html-renderer";
const MyComponent = () => {
const pluginConfig = {
// defaults to true, auto enable events required for plugin to work
autoConfig: true,
}
return (
)
}
`
As you may be able to tell from above, there are 5 configurable sections within the plugin configuration which are autoConfig, promptBaseColors, promptHoveredColors, textAreaHighlightColors and advancedStyles. These are described in the table below:
| Configuration Option | Type | Default Value | Description |
|------------------------------|----------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|---------------------------------------------------------------------------------------------------------------------------|
| autoConfig | boolean | true | Enables automatic configuration of required events for html rendering. Recommended to keep as true. If set to false, you need to configure events manually. |
| htmlComponent | React.ComponentType<{ children: React.ReactNode }> | null | A React component to wrap around the message's content to customize its styling, layout, or behavior. The component will receive the message's content as its children prop, so you can design it to add custom formatting, animations, or other UI enhancements. If not provided, a default wrapper from react-html will be used. |
#### Rendering Html
To render html in messages, add the renderHtml attribute to any Block that requires html rendering. The renderHtml attribute is an array that accepts senders such as "USER" and/or "BOT". An example can be seen below:
`javascript
import ChatBot from "react-chatbotify";
import HtmlRenderer from "@rcb-plugins/html-renderer";
const MyComponent = () => {
const flow = {
start: {
message: "What is your age?
",
renderHtml: ["USER", "BOT"],
},
// ... other blocks
};
return (
)
}
`
As you can see from the example above containing a start block, renderHtml contains both "USER" and "BOT", which means it will render html messages for both user and bot messages within the start` block.