Skip to content

Commit c1dfd69

Browse files
committed
feat: Expand support for senders
1 parent 61f0717 commit c1dfd69

18 files changed

+241
-320
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 `renderMarkdown` attribute now accepts **any** sender types (previously only `BOT` and `USER`)
5+
16
## v0.2.0 (23-04-2025)
27

38
**Added:**

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ As you may be able to tell from above, there are 5 configurable sections within
114114

115115
#### Rendering Markdown
116116

117-
To render markdown in messages, add the `renderMarkdown` attribute to any Block that requires markdown rendering. The `renderMarkdown` attribute is an array that accepts `"USER"` and/or `"BOT"`. An example can be seen below:
117+
To render markdown in messages, add the `renderMarkdown` attribute to any Block that requires markdown rendering. The `renderMarkdown` attribute is an array that accepts senders such as `"USER"` and/or `"BOT"`. An example can be seen below:
118118

119119
```javascript
120120
import ChatBot from "react-chatbotify";

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/markdown-renderer",
44
"keywords": [
55
"react",
6-
"chat",
7-
"chatbot",
8-
"conversational-bot",
9-
"conversational-ui",
106
"frontend-library",
11-
"plugins"
7+
"plugins",
8+
"markdown",
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 markdown 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
},
@@ -44,8 +44,8 @@
4444
},
4545
"peerDependencies": {
4646
"react": ">=16.14.0",
47-
"react-dom": ">=16.14.0",
48-
"react-chatbotify": "^2.0.0-beta.33"
47+
"react-chatbotify": "^2.0.0-beta.38",
48+
"react-dom": ">=16.14.0"
4949
},
5050
"devDependencies": {
5151
"@eslint/js": "^9.20.0",
@@ -56,6 +56,7 @@
5656
"eslint-plugin-react-hooks": "^5.1.0",
5757
"eslint-plugin-react-refresh": "^0.4.19",
5858
"globals": "^15.15.0",
59+
"prettier": "^3.5.3",
5960
"typescript": "^5.7.3",
6061
"typescript-eslint": "^8.24.0",
6162
"vite": "^6.1.0",

src/App.tsx

Lines changed: 35 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,35 @@
1-
import ChatBot, { Flow, Params } from "react-chatbotify";
2-
3-
import RcbPlugin from "./factory/RcbPluginFactory";
4-
import { MarkdownRendererBlock } from "./types/MarkdownRendererBlock";
5-
import MarkdownWrapper from "./components/MarkdownWrapper";
6-
7-
const App = () => {
8-
// initialize the plugin
9-
const plugins = [RcbPlugin({markdownComponent: MarkdownWrapper})];
10-
11-
// example flow for testing
12-
const flow: Flow = {
13-
start: {
14-
message: "#### Hello! I'm rendering messages in markdown, you can type to me in markdown too!",
15-
path: "loop",
16-
renderMarkdown: ["BOT", "USER"],
17-
} as MarkdownRendererBlock,
18-
loop : {
19-
message: async (params: Params) => {
20-
await params.injectMessage(`Hey, here's a simple code block below:\\\
21-
22-
\`\`\`const greeting = "hello!";\`\`\`\\\
23-
24-
Pretty cool isn't it? Try again!`);
25-
},
26-
chatDisabled: false,
27-
path: "loop",
28-
renderMarkdown: ["BOT", "USER"],
29-
} as MarkdownRendererBlock,
30-
}
31-
32-
return (
33-
<ChatBot
34-
id="chatbot-id"
35-
plugins={plugins}
36-
flow={flow}
37-
></ChatBot>
38-
);
39-
}
40-
41-
export default App;
1+
import ChatBot, { Flow, Params } from 'react-chatbotify';
2+
3+
import RcbPlugin from './factory/RcbPluginFactory';
4+
import { MarkdownRendererBlock } from './types/MarkdownRendererBlock';
5+
import MarkdownWrapper from './components/MarkdownWrapper';
6+
7+
const App = () => {
8+
// initialize the plugin
9+
const plugins = [RcbPlugin({ markdownComponent: MarkdownWrapper })];
10+
11+
// example flow for testing
12+
const flow: Flow = {
13+
start: {
14+
message: "#### Hello! I'm rendering messages in markdown, you can type to me in markdown too!",
15+
path: 'loop',
16+
renderMarkdown: ['BOT', 'USER'],
17+
} as MarkdownRendererBlock,
18+
loop: {
19+
message: async (params: Params) => {
20+
await params.injectMessage(`Hey, here's a simple code block below:\\\
21+
22+
\`\`\`const greeting = "hello!";\`\`\`\\\
23+
24+
Pretty cool isn't it? Try again!`);
25+
},
26+
chatDisabled: false,
27+
path: 'loop',
28+
renderMarkdown: ['BOT', 'USER'],
29+
} as MarkdownRendererBlock,
30+
};
31+
32+
return <ChatBot id="chatbot-id" plugins={plugins} flow={flow}></ChatBot>;
33+
};
34+
35+
export default App;

src/components/MarkdownWrapper.tsx

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,13 @@
1-
import ReactMarkdown from "react-markdown";
1+
import ReactMarkdown from 'react-markdown';
22

33
/**
44
* Renders markdown content passed as children.
55
*
66
* @param children markdown text to render
77
*/
8-
const MarkdownWrapper = ({
9-
children
10-
}: {
11-
children: React.ReactNode
12-
}) => {
13-
// ensures that markdownText is a string
14-
const markdownText = typeof children === "string" ? children : "";
8+
const MarkdownWrapper = ({ children }: { children: React.ReactNode }) => {
9+
// ensures that markdownText is a string
10+
const markdownText = typeof children === 'string' ? children : '';
1511
return (
1612
<ReactMarkdown
1713
components={{

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)