Skip to content
geeksforgeeks
  • Courses
    • DSA to Development
    • Get IBM Certification
    • Newly Launched!
      • Master Django Framework
      • Become AWS Certified
    • For Working Professionals
      • Interview 101: DSA & System Design
      • Data Science Training Program
      • JAVA Backend Development (Live)
      • DevOps Engineering (LIVE)
      • Data Structures & Algorithms in Python
    • For Students
      • Placement Preparation Course
      • Data Science (Live)
      • Data Structure & Algorithm-Self Paced (C++/JAVA)
      • Master Competitive Programming (Live)
      • Full Stack Development with React & Node JS (Live)
    • Full Stack Development
    • Data Science Program
    • All Courses
  • Tutorials
    • Data Structures & Algorithms
    • ML & Data Science
    • Interview Corner
    • Programming Languages
    • Web Development
    • CS Subjects
    • DevOps And Linux
    • School Learning
  • Practice
    • Build your AI Agent
    • GfG 160
    • Problem of the Day
    • Practice Coding Problems
    • GfG SDE Sheet
  • Contests
    • Accenture Hackathon (Ending Soon!)
    • GfG Weekly [Rated Contest]
    • Job-A-Thon Hiring Challenge
    • All Contests and Events
  • React Tutorial
  • React Exercise
  • React Basic Concepts
  • React Components
  • React Props
  • React Hooks
  • React Router
  • React Advanced
  • React Examples
  • React Interview Questions
  • React Projects
  • Next.js Tutorial
  • React Bootstrap
  • React Material UI
  • React Ant Design
  • React Desktop
  • React Rebass
  • React Blueprint
  • JavaScript
  • Web Technology
Open In App
Next Article:
How to create Popup box in React JS ?
Next article icon

How to add Chatbot in React JS Project ?

Last Updated : 24 Jul, 2024
Comments
Improve
Suggest changes
Like Article
Like
Report

In today’s digital world, chatbots have become an integral part of many websites and applications. They provide a convenient and efficient way to interact with users, answer their queries, and improve overall user experience. If you’re working on a React JS project and want to incorporate a chatbot, you’re in the right place. In this article, we’ll guide you through the process of adding a chatbot to your React JS project.

Prerequisite:

  • Knowledge about React JS
  • Understanding of styled-components

Steps to create React application and Module installation:

Step 1: Create a React application using the following command:

npx create-react-app project

Step 2: After creating your project folder(i.e. project), move to it by using the following command:

cd project

Step 3: now install the dependency react-simple-chatbot by using the following command:

npm i react-simple-chatbot

Project Structure:

Example: For the chatBot to work, we need to create a steps array. The ChatBot takes steps which is an array of objects as its props. Although there are a number of options we can pass as props to our chatBot without the steps props it will show a blank screen.

JavaScript
//App.js  import ChatBot from 'react-simple-chatbot';  const steps = [     {         id: '0',         message: 'Hey Geek!',         end: true     } ];  function App() {     return (         <div className="App">             <h1>Welcome to Geeksforgeeks</h1>             <ChatBot steps={steps} />         </div>     ); }  export default App; 

Step to Run Application: Run the application using the following command from the root directory of the project.

npm start

Output:

In order to provide a theme to our project let’s import ThemeProvider from ‘styled-components’.

Note: The ‘styled-components’ gets installed along with ‘react-simple-chatbot’.

  • We will create a const theme with all the props available to change the styling of our chatbot. After that, we are wrapping the ChatBot within the ThemeProvider passing theme as props.
  • Now to show the chatbot icon and to change the bot avatar we need to create a config that will have floating set to true so that the bot icon appears on the website and we have set an image in the botAvatar, we are passing config as a prop to our ChatBot as well. We are also passing headerTitle as props to ChatBot.
JavaScript
//App.js  import ChatBot from 'react-simple-chatbot'; import { ThemeProvider } from 'styled-components';  const steps = [     {         id: '0',         message: 'Hey Geek!',          // This calls the next id         // i.e. id 1 in this case         trigger: '1',     }, {         id: '1',          // This message appears in         // the bot chat bubble         message: 'Please write your username',         trigger: '2'     }, {         id: '2',          // Here we want the user         // to enter input         user: true,         trigger: '3',     }, {         id: '3',         message: " hi {previousValue}, how can I help you?",         trigger: 4     }, {         id: '4',         options: [              // When we need to show a number of             // options to choose we create alist             // like this             { value: 1, label: 'View Courses' },             { value: 2, label: 'Read Articles' },          ],         end: true     } ];  // Creating our own theme const theme = {     background: '#C9FF8F',     headerBgColor: '#197B22',     headerFontSize: '20px',     botBubbleColor: '#0F3789',     headerFontColor: 'white',     botFontColor: 'white',     userBubbleColor: '#FF5733',     userFontColor: 'white', };  // Set some properties of the bot const config = {     botAvatar: "img.png",     floating: true, };  function App() {     return (         <div className="App">             <ThemeProvider theme={theme}>                 <ChatBot                      // This appears as the header                     // text for the chat bot                     headerTitle="GeekBot"                     steps={steps}                     {...config}                  />             </ThemeProvider>         </div>     ); }  export default App; 

Step to Run Application: Run the application using the following command from the root directory of the project.

npm start

Output:

https://media.geeksforgeeks.org/wp-content/uploads/20240724161636/20220218120731-ezgifcom-gif-to-mp4-converter.mp4


Next Article
How to create Popup box in React JS ?
author
aniluom
Improve
Article Tags :
  • Geeks Premier League
  • ReactJS
  • Web Technologies
  • Geeks-Premier-League-2022
  • React-Questions
  • Web technologies

Similar Reads

  • How to Setup a Modern React Chatbot
    Integrating a chatbot into your React application can enhance user experience and provide valuable assistance to your users. With the availability of various libraries and tools, setting up a modern chatbot in a React project has become more straightforward. In this article, we'll explore how to set
    2 min read
  • How to create Popup box in React JS ?
    Popup boxes, also known as modal or dialog boxes, are common UI elements used to display additional content or interactions on top of the main page. Creating a popup box in React can be achieved using various approaches, including libraries or custom implementations. We will use the Reactjs-popup li
    2 min read
  • How to add code input in React JS?
    In this article, we are going to learn how we can add Code Input in React JS. React is a front-end JavaScript library for constructing user interfaces or UI components. It is maintained by Facebook and a community of individual developers and companies. Approach to add code input: To incorporate our
    2 min read
  • How to Deploy React project on Firebase?
    When developing any project we must host it somewhere so that the whole world can see our hard-work. Hosting websites can be hectic sometimes, but you don't need to worry as we can now host our React project on Firebase within a minute or two with a very simple setup. The Steps to deploy react proje
    2 min read
  • How to install React-Bootstrap in React Application ?
    React Bootstrap is a popular library that let us use the Bootstrap framework's power and flexibility to React.js applications. By combining the flexibility of React with the UI components provided by Bootstrap, you can create responsive and visually appealing user interfaces with ease. In this artic
    4 min read
  • How to Add Auto-Complete Search Box in ReactJS?
    An autocomplete search box is a user interface feature that offers suggestions as users type their queries. It enhances the user experience by providing real-time suggestions and help users find what they're looking for more quickly. In this article, we will explore how to implement an autocomplete
    5 min read
  • How to add CodeBlock in Next.js ?
    In this article, we are going to learn how we can add CodeBlock in NextJS. NextJS is a React-based framework. It has the power to Develop beautiful Web applications for different platforms like Windows, Linux, and mac. The linking of dynamic paths helps in rendering your NextJS components conditiona
    2 min read
  • How to add Share button in React Native ?
    React Native is an open-source UI software framework created by Meta Platforms, Inc. It is used to develop applications for Android, Android TV, iOS, macOS, tvOS, Web, Windows, and UWP by enabling developers to use the React framework along with native platform capabilities. In this article, we will
    2 min read
  • How to create an event in React ?
    In the development of contemporary webpages, user interactions play a pivotal role. These interactions include mouse clicks, keypresses, or even uncommon events like connecting a battery to a charger. As developers, our task is to actively "listen" to these events and subsequently ensure that our ap
    2 min read
  • How to add Web Share in Next.js ?
    The Web Share API enables web applications to share content (like URLs, text, or files) to other apps installed on a user's device, such as social media platforms, messaging apps, or email clients. Integrating the Web Share API into a Next.js project enhances user experience by providing a seamless
    2 min read
geeksforgeeks-footer-logo
Corporate & Communications Address:
A-143, 7th Floor, Sovereign Corporate Tower, Sector- 136, Noida, Uttar Pradesh (201305)
Registered Address:
K 061, Tower K, Gulshan Vivante Apartment, Sector 137, Noida, Gautam Buddh Nagar, Uttar Pradesh, 201305
GFG App on Play Store GFG App on App Store
Advertise with us
  • Company
  • About Us
  • Legal
  • Privacy Policy
  • In Media
  • Contact Us
  • Advertise with us
  • GFG Corporate Solution
  • Placement Training Program
  • Languages
  • Python
  • Java
  • C++
  • PHP
  • GoLang
  • SQL
  • R Language
  • Android Tutorial
  • Tutorials Archive
  • DSA
  • Data Structures
  • Algorithms
  • DSA for Beginners
  • Basic DSA Problems
  • DSA Roadmap
  • Top 100 DSA Interview Problems
  • DSA Roadmap by Sandeep Jain
  • All Cheat Sheets
  • Data Science & ML
  • Data Science With Python
  • Data Science For Beginner
  • Machine Learning
  • ML Maths
  • Data Visualisation
  • Pandas
  • NumPy
  • NLP
  • Deep Learning
  • Web Technologies
  • HTML
  • CSS
  • JavaScript
  • TypeScript
  • ReactJS
  • NextJS
  • Bootstrap
  • Web Design
  • Python Tutorial
  • Python Programming Examples
  • Python Projects
  • Python Tkinter
  • Python Web Scraping
  • OpenCV Tutorial
  • Python Interview Question
  • Django
  • Computer Science
  • Operating Systems
  • Computer Network
  • Database Management System
  • Software Engineering
  • Digital Logic Design
  • Engineering Maths
  • Software Development
  • Software Testing
  • DevOps
  • Git
  • Linux
  • AWS
  • Docker
  • Kubernetes
  • Azure
  • GCP
  • DevOps Roadmap
  • System Design
  • High Level Design
  • Low Level Design
  • UML Diagrams
  • Interview Guide
  • Design Patterns
  • OOAD
  • System Design Bootcamp
  • Interview Questions
  • Inteview Preparation
  • Competitive Programming
  • Top DS or Algo for CP
  • Company-Wise Recruitment Process
  • Company-Wise Preparation
  • Aptitude Preparation
  • Puzzles
  • School Subjects
  • Mathematics
  • Physics
  • Chemistry
  • Biology
  • Social Science
  • English Grammar
  • Commerce
  • World GK
  • GeeksforGeeks Videos
  • DSA
  • Python
  • Java
  • C++
  • Web Development
  • Data Science
  • CS Subjects
@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved
We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy
Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences