Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
02031ca
Fix Recognition returning the first instance for every new instance
LucasBassetti Sep 26, 2026
cba3fb8
Wait for input when the first step is a user step; guard localStorage
LucasBassetti Sep 26, 2026
994f23e
Modernize toolchain: webpack 5, Babel 7.29, ESLint 8, mocha 10, React…
LucasBassetti Sep 26, 2026
3cb86ce
Fix duplicated messages: trigger each step only once
LucasBassetti Sep 26, 2026
6a7eacb
Fix autoscroll on modern browsers and several small bugs
LucasBassetti Sep 26, 2026
abc9fc4
Support styled-components 6 without leaking style props to the DOM
LucasBassetti Sep 26, 2026
911f674
Don't crash the mic button with non-hex theme colors
LucasBassetti Sep 26, 2026
faaf66b
Apply steps prop updates and fix several step bugs
LucasBassetti Sep 26, 2026
ffa5290
Only autoscroll when the user is at the bottom; improve accessibility
LucasBassetti Sep 26, 2026
4e2346e
Add TypeScript declarations
LucasBassetti Sep 26, 2026
c85981c
Start a closed floating chatbot when it is opened
LucasBassetti Sep 26, 2026
bf5e59a
Filter the loading delay prop and update the example app
LucasBassetti Sep 26, 2026
0383550
Run the createRoot tests with React 19 in CI
LucasBassetti Sep 26, 2026
918b86f
Update README: install styled-components, supported versions and tips
LucasBassetti Sep 26, 2026
464f6f0
Publish an ES5 bundle and stop tracking dist
LucasBassetti Sep 26, 2026
8f5581c
Fix issues found in review
LucasBassetti Sep 26, 2026
49911c7
Add CAMARADES BR to the Build with list (from #347)
LucasBassetti Sep 26, 2026
e84172f
Release 0.7.0
LucasBassetti Sep 26, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 12 additions & 9 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -1,13 +1,8 @@
{
"extends": ["airbnb", "plugin:prettier/recommended", "prettier/react"],
"plugins": ["prettier"],
"parser": "babel-eslint",
"globals": {
"window": true,
"Audio": true,
"document": true,
"localStorage": true,
"navigator": true
"extends": ["airbnb", "airbnb/hooks", "plugin:prettier/recommended"],
"parser": "@babel/eslint-parser",
"env": {
"browser": true
},
"rules": {
"prettier/prettier": ["error"],
Expand All @@ -17,6 +12,14 @@
"no-restricted-syntax": 0,
"no-param-reassign": 0,
"react/no-will-update-set-state": 0,
"react/forbid-prop-types": 0,
"react/jsx-props-no-spreading": 0,
"react/function-component-definition": 0,
"react/require-default-props": 0,
"react/static-property-placement": 0,
"react/state-in-constructor": 0,
"react/destructuring-assignment": 0,
"prefer-object-spread": 0,
"new-cap": 0
}
}
44 changes: 29 additions & 15 deletions .github/workflows/nodejs.yml
Original file line number Diff line number Diff line change
@@ -1,26 +1,40 @@
name: Node CI

on: [push]
on:
push:
branches: [master]
pull_request:

jobs:
build:

runs-on: ubuntu-latest

strategy:
matrix:
node-version: [8.x, 10.x, 12.x]
node-version: [20.x, 22.x, 24.x]

steps:
- uses: actions/checkout@v4
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}
cache: npm
- run: npm ci
- run: npm run lint
- run: npm run test:coverage
- run: npm run test:types
- run: npm run build

react-19:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v1
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v1
with:
node-version: ${{ matrix.node-version }}
- name: npm install, build, and test
run: |
npm ci
npm run build --if-present
npm test
env:
CI: true
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 24.x
cache: npm
- run: npm ci
- run: npm install --no-save --legacy-peer-deps react@19 react-dom@19
- run: npm run test:dom
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,9 @@ pids
# Dependency directory
# https://www.npmjs.org/doc/misc/npm-faq.html#should-i-check-my-node_modules-folder-into-git
node_modules

# Coverage report
coverage.lcov

# Build output (generated on publish)
/dist
6 changes: 4 additions & 2 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
{
"printWidth": 100,
"singleQuote": true
}
"singleQuote": true,
"trailingComma": "none",
"arrowParens": "avoid"
}
5 changes: 0 additions & 5 deletions .travis.yml

This file was deleted.

27 changes: 17 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

# React Simple Chatbot

<a href="https://travis-ci.org/LucasBassetti/react-simple-chatbot"><img src="https://travis-ci.org/LucasBassetti/react-simple-chatbot.svg?branch=master" alt="Travis CI" /></a> <a href="https://badge.fury.io/js/react-simple-chatbot"><img src="https://badge.fury.io/js/react-simple-chatbot.svg" alt="npm version"></a>
<a href="https://github.com/LucasBassetti/react-simple-chatbot/actions/workflows/nodejs.yml"><img src="https://github.com/LucasBassetti/react-simple-chatbot/actions/workflows/nodejs.yml/badge.svg" alt="Node CI" /></a> <a href="https://badge.fury.io/js/react-simple-chatbot"><img src="https://badge.fury.io/js/react-simple-chatbot.svg" alt="npm version"></a>
<img src="https://codecov.io/gh/LucasBassetti/react-simple-chatbot/branch/master/graph/badge.svg" alt="Codecov" />
</a> <a href="https://beerpay.io/LucasBassetti/react-simple-chatbot"><img src="https://beerpay.io/LucasBassetti/react-simple-chatbot/badge.svg?style=flat" /></a>

Expand All @@ -15,15 +15,20 @@ A simple chatbot component to create conversation chats

## Getting Start

`react-simple-chatbot` uses [styled-components](https://styled-components.com) as a peer dependency, so install both:

```bash
npm install react-simple-chatbot --save
npm install react-simple-chatbot styled-components
```

It works with React 16.3 or newer (including React 18 and 19) and styled-components 4, 5 or 6. TypeScript declarations are included.

## Usage

There are several examples on the [website](http://lucasbassetti.com.br/react-simple-chatbot). Here is the first one to get you started:
There are several examples on the [website](https://lucasbassetti.github.io/react-simple-chatbot/). Here is the first one to get you started:

``` javascript
import { createRoot } from 'react-dom/client';
import ChatBot from 'react-simple-chatbot';

const steps = [
Expand All @@ -39,14 +44,15 @@ const steps = [
},
];

ReactDOM.render(
<div>
<ChatBot steps={steps} />
</div>,
document.getElementById('root')
);
createRoot(document.getElementById('root')).render(<ChatBot steps={steps} />);
```

### Tips

- **Restart the conversation**: render the chatbot with a new `key` (e.g. `<ChatBot key={conversationId} steps={steps} />`). If `cache` is enabled, also clear it with `localStorage.removeItem(cacheName)`.
- **Change steps after mount**: updates to `steps`, the avatars, the delays and `botName` are used by the steps that were not rendered yet.
- **Style the chatbot**: every element has a stable `rsc-*` class name (e.g. `.rsc-ts-bubble`, `.rsc-input`) that you can target with CSS, and the `*Style` props accept inline styles.

## React Simple Chatbot with AI

1. [CodeParrot AI](https://codeparrot.ai/oracle?owner=LucasBassetti&repo=react-simple-chatbot) - Bot will help you understand this repository better. You can ask for code examples, installation guide, debugging help and much more.
Expand All @@ -64,6 +70,7 @@ ReactDOM.render(
3. [Cisco Partner Support API Chatbot](https://github.com/btotharye/cisco-pss-api-chatbot) - Code with screenshots to have your own Cisco Serial lookup chatbot.
4. [Chatcompose](https://www.chatcompose.com/en.html) - Chatbot Platform for Conversational Marketing and Support.
5. [Mixat](https://www.svt.se/mixat) - News Chatbot for tweenies. Also as app ([iOS](https://apps.apple.com/se/app/mixat-h%C3%A4r-f%C3%A5r-du-koll/id1239444432) or [Android](https://play.google.com/store/apps/details?id=se.svt.mixat))
6. [CAMARADES BR](https://camaradesbrasil.bio.br/) - CAMARADES' brazilian research group

Built something with `react-simple-chatbot`? Submit a PR and add it to this list!

Expand All @@ -81,4 +88,4 @@ See also the list of [contributors](https://github.com/LucasBassetti/react-simpl

## License

MIT · [Lucas Bassetti](http://lucasbassetti.com.br)
MIT · [Lucas Bassetti](https://lucasbassetti.com)
12 changes: 4 additions & 8 deletions babel.config.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
const presets = ['@babel/env', '@babel/preset-react'];
const plugins = [
'@babel/plugin-transform-arrow-functions',
'@babel/plugin-proposal-class-properties',
'@babel/plugin-transform-object-assign'
];

module.exports = { presets, plugins };
module.exports = {
// the published bundle is ES5, so older bundlers (webpack 4) and browsers can parse it
presets: [['@babel/preset-env', { targets: 'ie 11' }], '@babel/preset-react']
};
Empty file removed coverage.lcov
Empty file.
2 changes: 0 additions & 2 deletions dist/react-simple-chatbot.js

This file was deleted.

1 change: 0 additions & 1 deletion dist/react-simple-chatbot.js.map

This file was deleted.

25 changes: 18 additions & 7 deletions example/components/Example.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,30 @@ const otherFontTheme = {
userFontColor: '#4a4a4a'
};

const Summary = ({ steps }) => (
<div>
<strong>{steps.name.value}</strong> likes <strong>{steps.fruit.value}</strong>
</div>
);

const steps = [
{ id: '1', message: 'Hello! What is your name?', trigger: 'name' },
{ id: 'name', user: true, trigger: '3' },
{ id: '3', message: 'Hi {previousValue}! Which fruit do you like?', trigger: 'fruit' },
{
id: '1',
message: 'Hello World',
end: true
}
id: 'fruit',
options: [
{ label: 'Apple', trigger: 'summary' },
{ label: 'Banana', trigger: 'summary' }
]
},
{ id: 'summary', component: <Summary />, asMessage: true, trigger: 'end' },
{ id: 'end', message: 'Thanks!', end: true }
];

const ThemedExample = () => (
<ThemeProvider theme={otherFontTheme}>
<React.StrictMode>
<ChatBot steps={steps} />
</React.StrictMode>
<ChatBot steps={steps} />
</ThemeProvider>
);

Expand Down
10 changes: 7 additions & 3 deletions example/main.jsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
import React from 'react';
import { render } from 'react-dom';
import React, { StrictMode } from 'react';
import { createRoot } from 'react-dom/client';
import Example from './components/Example';

render(<Example />, document.getElementById('root'));
createRoot(document.getElementById('root')).render(
<StrictMode>
<Example />
</StrictMode>
);
152 changes: 152 additions & 0 deletions index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,152 @@
import * as React from 'react';

export type StepId = string | number;

export interface RenderedStep {
id: StepId;
message?: string;
value?: any;
metadata?: Record<string, any>;
}

export type RenderedSteps = Record<string, RenderedStep>;

export type Trigger = StepId | ((args: { value: any; steps: RenderedSteps }) => StepId);

export type Message = string | ((args: { previousValue: any; steps: RenderedSteps }) => string);

interface BaseStep {
id: StepId;
end?: boolean;
placeholder?: string;
inputAttributes?: React.InputHTMLAttributes<HTMLInputElement>;
metadata?: Record<string, any>;
}

export interface TextStep extends BaseStep {
message: Message;
avatar?: string;
trigger?: Trigger;
delay?: number;
hideInput?: boolean;
hideExtraControl?: boolean;
}

export interface UserStep extends BaseStep {
user: true;
trigger?: Trigger;
hideExtraControl?: boolean;
/** Return true when the value is valid, or the error message to show */
validator?: (value: string) => boolean | string;
}

export interface Option {
label: string;
/** Defaults to the label */
value?: any;
trigger: Trigger;
}

export interface OptionsStep extends BaseStep {
options: Option[];
hideInput?: boolean;
hideExtraControl?: boolean;
}

export interface CustomStep extends BaseStep {
component: React.ReactElement;
avatar?: string;
replace?: boolean;
waitAction?: boolean;
asMessage?: boolean;
trigger?: Trigger;
delay?: number;
hideInput?: boolean;
hideExtraControl?: boolean;
}

export interface UpdateStep extends BaseStep {
update: StepId;
trigger: Trigger;
}

export type Step = TextStep | UserStep | OptionsStep | CustomStep | UpdateStep;

export interface TriggerNextStepData {
value?: any;
trigger?: Trigger;
hideInput?: boolean;
hideExtraControl?: boolean;
}

/** Props injected in the components of custom steps */
export interface CustomComponentProps {
step?: Step & { value?: any };
steps?: RenderedSteps;
previousStep?: Step & { value?: any };
triggerNextStep?: (data?: TriggerNextStepData) => void;
}

export interface HandleEndArgs {
renderedSteps: RenderedStep[];
steps: RenderedSteps;
values: any[];
}

export interface SpeechSynthesisOptions {
enable?: boolean;
lang?: string;
voice?: SpeechSynthesisVoice | null;
}

export interface ChatBotProps {
steps: Step[];
avatarStyle?: React.CSSProperties;
botAvatar?: string;
botDelay?: number;
botName?: string;
bubbleOptionStyle?: React.CSSProperties;
bubbleStyle?: React.CSSProperties;
cache?: boolean;
cacheName?: string;
className?: string;
contentStyle?: React.CSSProperties;
controlStyle?: React.CSSProperties;
customDelay?: number;
customStyle?: React.CSSProperties;
enableMobileAutoFocus?: boolean;
enableSmoothScroll?: boolean;
extraControl?: React.ReactElement;
floating?: boolean;
floatingIcon?: string | React.ReactElement;
floatingStyle?: React.CSSProperties;
footerStyle?: React.CSSProperties;
handleEnd?: (args: HandleEndArgs) => void;
headerComponent?: React.ReactElement;
headerTitle?: string;
height?: string;
hideBotAvatar?: boolean;
hideHeader?: boolean;
hideSubmitButton?: boolean;
hideUserAvatar?: boolean;
inputAttributes?: React.InputHTMLAttributes<HTMLInputElement>;
inputStyle?: React.CSSProperties;
opened?: boolean;
placeholder?: string;
recognitionEnable?: boolean;
recognitionLang?: string;
recognitionPlaceholder?: string;
speechSynthesis?: SpeechSynthesisOptions;
style?: React.CSSProperties;
submitButtonStyle?: React.CSSProperties;
toggleFloating?: (args: { opened: boolean }) => void;
userAvatar?: string;
userDelay?: number;
width?: string;
}

declare class ChatBot extends React.Component<ChatBotProps> {}

export declare const Loading: React.ComponentType;

export default ChatBot;
Loading
Loading