Quick start
In this page you build a chatbot that asks for the user’s name and greets them by name. It takes three steps.
Build the chatbot
Section titled “Build the chatbot”-
Install React Simple Chatbot and styled-components, its peer dependency:
Terminal window npm install react-simple-chatbot styled-componentsSee installation for yarn, pnpm and bun, and for the supported versions.
-
Describe the conversation as an array of steps. Each step has a unique
idand atriggerpointing to the next step:steps.ts import type { Step } from 'react-simple-chatbot';export const steps: Step[] = [{ id: '1', message: 'What is your name?', trigger: '2' },{ id: '2', user: true, trigger: '3' },{ id: '3', message: 'Hi {previousValue}, nice to meet you!', end: true }];Step
1is a bot message, step2waits for the user to type, and step3answers with what the user typed. -
Render the
ChatBotcomponent with your steps:App.tsx import ChatBot from 'react-simple-chatbot';import { steps } from './steps';export default function App() {return <ChatBot headerTitle="Previous value" steps={steps} />;}
The result
Section titled “The result”import ChatBot, { type Step } from 'react-simple-chatbot';
const steps: Step[] = [ { id: '1', message: 'What is your name?', trigger: '2' }, { id: '2', user: true, trigger: '3' }, { id: '3', message: 'Hi {previousValue}, nice to meet you!', end: true }];
export default function PreviousValue() { return <ChatBot headerTitle="Previous value" steps={steps} />;}How it works
Section titled “How it works”triggertells the chatbot which step comes next. The conversation starts with the first step of the array and follows the triggers. A trigger can also be a function that picks the next step from the user’s answer; see dynamic content.user: truemakes a step wait for the user. The chatbot enables the input, and when the user submits, the typed text becomes the value of that step.{previousValue}in a message is replaced with the value of the previous step, here the name the user typed. For more control,messagecan be a function that receivespreviousValueand the answers given so far.end: truemarks the last step. When it is reached, the conversation stops and the chatbot callshandleEndif you passed one.
Next steps
Section titled “Next steps”StepsAll kinds of steps: messages, user input, options, custom components and updates.
ExamplesOptions, validation, forms, API calls and more.
ThemingChange the colors and fonts of the chatbot.
ChatBot propsEvery prop of the ChatBot component and its default value.