Skip to content

Commit 6d6b2eb

Browse files
committed
feat: Expand support for senders
1 parent 48091fd commit 6d6b2eb

17 files changed

+349
-360
lines changed

.prettierrc

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"useTabs": true,
3+
"tabWidth": 4,
4+
"printWidth": 120,
5+
"singleQuote": true,
6+
"trailingComma": "es5"
7+
}

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
## v0.3.0 (11-06-2025)
2+
3+
**Added:**
4+
- The `renderHtml` attribute now accepts **any** sender types (previously only `BOT` and `USER`)
5+
16
## v0.2.0 (23-04-2025)
27

38
**Added:**

package-lock.json

Lines changed: 23 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,16 @@
33
"homepage": "https://github.com/React-ChatBotify-Plugins/html-renderer",
44
"keywords": [
55
"react",
6-
"chat",
7-
"chatbot",
8-
"conversational-bot",
9-
"conversational-ui",
106
"frontend-library",
11-
"plugins"
7+
"plugins",
8+
"html",
9+
"react-chatbotify",
10+
"react-chatbotify-plugin"
1211
],
1312
"files": [
1413
"./dist"
1514
],
16-
"version": "0.2.0",
15+
"version": "0.3.0",
1716
"description": "A simple plugin for rendering html messages in React ChatBotify.",
1817
"type": "module",
1918
"main": "./dist/index.cjs",
@@ -33,6 +32,7 @@
3332
"start": "vite serve",
3433
"build": "tsc -b && vite build",
3534
"lint": "eslint --fix \"**/*.{ts,tsx}\"",
35+
"format": "prettier --write \"{src,test,types}/**/*.{ts,tsx,js,json,md}\"",
3636
"preview": "vite preview",
3737
"prepack": "tsc && vite build",
3838
"unit:test": "jest __tests__/"
@@ -45,8 +45,8 @@
4545
},
4646
"peerDependencies": {
4747
"react": ">=16.14.0",
48-
"react-dom": ">=16.14.0",
49-
"react-chatbotify": "^2.0.0-beta.33"
48+
"react-chatbotify": "^2.0.0-beta.38",
49+
"react-dom": ">=16.14.0"
5050
},
5151
"devDependencies": {
5252
"@eslint/js": "^9.20.0",
@@ -60,6 +60,7 @@
6060
"globals": "^15.15.0",
6161
"jest": "^29.7.0",
6262
"jest-environment-jsdom": "^29.7.0",
63+
"prettier": "^3.5.3",
6364
"ts-jest": "^29.2.6",
6465
"typescript": "^5.7.3",
6566
"typescript-eslint": "^8.24.0",

src/App.tsx

Lines changed: 31 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,31 @@
1-
import ChatBot, { Flow, Params } from "react-chatbotify";
2-
3-
import RcbPlugin from "./factory/RcbPluginFactory";
4-
import { HtmlRendererBlock } from "./types/HtmlRendererBlock";
5-
import HtmlWrapper from "./components/HtmlWrapper";
6-
7-
const App = () => {
8-
// initialize the plugin
9-
const plugins = [RcbPlugin({htmlComponent: HtmlWrapper})];
10-
11-
// example flow for testing
12-
const flow: Flow = {
13-
start: {
14-
message: "<h4>Hello! I'm rendering messages in html, you can type to me in html too!</h4>",
15-
path: "loop",
16-
renderHtml: ["BOT", "USER"],
17-
} as HtmlRendererBlock,
18-
loop : {
19-
message: async (params: Params) => {
20-
await params.injectMessage(`This is pretty cool <b>isn't it?</b>!`);
21-
},
22-
chatDisabled: false,
23-
path: "loop",
24-
renderHtml: ["BOT", "USER"],
25-
} as HtmlRendererBlock,
26-
}
27-
28-
return (
29-
<ChatBot
30-
id="chatbot-id"
31-
plugins={plugins}
32-
flow={flow}
33-
></ChatBot>
34-
);
35-
}
36-
37-
export default App;
1+
import ChatBot, { Flow, Params } from 'react-chatbotify';
2+
3+
import RcbPlugin from './factory/RcbPluginFactory';
4+
import { HtmlRendererBlock } from './types/HtmlRendererBlock';
5+
import HtmlWrapper from './components/HtmlWrapper';
6+
7+
const App = () => {
8+
// initialize the plugin
9+
const plugins = [RcbPlugin({ htmlComponent: HtmlWrapper })];
10+
11+
// example flow for testing
12+
const flow: Flow = {
13+
start: {
14+
message: "<h4>Hello! I'm rendering messages in html, you can type to me in html too!</h4>",
15+
path: 'loop',
16+
renderHtml: ['BOT', 'USER'],
17+
} as HtmlRendererBlock,
18+
loop: {
19+
message: async (params: Params) => {
20+
await params.injectMessage(`This is pretty cool <b>isn't it?</b>!`);
21+
},
22+
chatDisabled: false,
23+
path: 'loop',
24+
renderHtml: ['BOT', 'USER'],
25+
} as HtmlRendererBlock,
26+
};
27+
28+
return <ChatBot id="chatbot-id" plugins={plugins} flow={flow}></ChatBot>;
29+
};
30+
31+
export default App;

src/components/HtmlWrapper.tsx

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,14 @@
1-
import { Interweave } from "interweave";
1+
import { Interweave } from 'interweave';
22

33
/**
44
* Renders html content passed as children.
55
*
66
* @param children html text to render
77
*/
8-
const HtmlWrapper = ({
9-
children
10-
}: {
11-
children: React.ReactNode
12-
}) => {
13-
// ensures that htmlText is a string
14-
const htmlText = typeof children === "string" ? children : "";
15-
return (
16-
<Interweave content={htmlText} />
17-
);
8+
const HtmlWrapper = ({ children }: { children: React.ReactNode }) => {
9+
// ensures that htmlText is a string
10+
const htmlText = typeof children === 'string' ? children : '';
11+
return <Interweave content={htmlText} />;
1812
};
1913

2014
export default HtmlWrapper;

src/constants/DefaultPluginConfig.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@
22
* Default values for plugin config.
33
*/
44
export const DefaultPluginConfig = {
5-
autoConfig: true,
6-
}
5+
autoConfig: true,
6+
};

0 commit comments

Comments
 (0)