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
  • NextJS
  • Material UI
  • React Bootstrap
  • React Suite
  • Ant Design
  • Reactstrap
  • BlueprintJS
  • React Desktop
  • React Native
  • React Rebass
  • React Spring
  • React Evergreen
  • ReactJS
  • ReactJS
  • JS Formatter
  • Web Technology
Open In App
Next Article:
Create an E-commerce App using React-Native
Next article icon

Create a Chatbot App using React-Native

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

Creating a chatbot app using React Native will be an exciting project. In this article, we are going to implement a Chatbot App using React Native. Chatbot App is a mobile application that answers the user's questions on the basis of their previous learning or content provided by developers.

It helps to reduce the cost of the workforce in companies because companies design the chatbot to solve the problems of users.

Preview of final output: Let us have a look at how the final output will look like.

chat
preview of the app

Prerequisite:

  • React Native
  • React Native State
  • React Native Props

Approach:

  • This app answers the questions asked by users.
  • We used the react-native-gifted-chat package in the app because it is a popular open-source library for implementing a chat interface in React Native applications.
  • It simplifies the process of building chat features by providing pre-built components and functionality.

Steps to Create React Native Application:

Step 1: Create a react native application by using this command in the command prompt

React-native init ChatbotApp

Step 2: After initiating the project, install the react-native-gifted-chat package to view the Chatbot format.

npm i react-native-gifted-chat

Project Structure:

structure

The updated dependencies in package.json file will look like:

"dependencies": {
"@expo/vector-icons": "^13.0.0",
"react-native-elements": "0.18.5",
"react-native-gifted-chat": "*"
}

Example: Write the below source code into the App.js file.

JavaScript
//App.js  import React from 'react'; import { SafeAreaView, Text } from 'react-native'; import ChatbotApp from './ChatbotApp';  const App = () => { 	return ( 		<SafeAreaView style={{ flex: 1 }}>  			<Text 				style={{ 					marginLeft: 23, 					fontSize: 20, 					marginTop: 20, 					fontWeight: 'bold', 					color: 'green', 					backgroundColor: 'yellow', 					marginRight: 30 				}}> 				GeekforGeeks ChatBot App</Text>  			<ChatbotApp /> 		</SafeAreaView> 	); };  export default App; 
JavaScript
//ChatbotApp.js  import React, { useState } from "react"; import { GiftedChat } from "react-native-gifted-chat";  const ChatbotApp = () => { 	const [messages, setMessages] = useState([ 		{ 			_id: 1, 			text: "Hello! I am your GFG chatbot. How can I help you?", 			createdAt: new Date(), 			user: { _id: 2, name: "Chatbot" }, 		}, 	]);  	const handleSend = (newMessages = []) => { 		setMessages((previousMessages) => 			GiftedChat.append(previousMessages, newMessages) 		);  		const userMessage = newMessages[0].text; 		const botResponse = generateChatbotResponse(userMessage);  		setMessages((previousMessages) => 			GiftedChat.append(previousMessages, [ 				{ 					_id: Math.round(Math.random() * 1000000), 					text: botResponse, 					createdAt: new Date(), 					user: { _id: 2, name: "Chatbot" }, 				}, 			]) 		); 	};  	const generateChatbotResponse = (userMessage) => { 		switch (userMessage.toLowerCase()) { 			case "hello": 				return "Hi there! How can I assist you today?"; 			case "how are you": 				return "I am just a chatbot, but thanks for asking!"; 			case "bye": 				return "Goodbye! If you have more questions, feel free to ask."; 			case "javascript": 				return "JavaScript is a programming language commonly used to create interactive effects within web browsers."; 			case "python": 				return "Python is a versatile and easy-to-read programming language often used for web development, data analysis, and artificial intelligence."; 			case "html": 				return "HTML (Hypertext Markup Language) is the standard markup language for documents designed to be displayed in a web browser."; 			case "css": 				return "CSS (Cascading Style Sheets) is a style sheet language used for describing the look and formatting of a document written in HTML."; 			case "git": 				return "Git is a distributed version control system used to track changes in source code during software development."; 			case "api": 				return "An API (Application Programming Interface) is a set of rules that allows one software application to interact with another."; 			case "algorithm": 				return "An algorithm is a step-by-step procedure or formula for solving a problem or accomplishing a task in computer science."; 			case "database": 				return "A database is an organized collection of data, typically stored and accessed electronically from a computer system.";  			default: 				return "I'm sorry, I didn't understand that. Can you please rephrase?"; 		} 	};  	return ( 		<GiftedChat 			messages={messages} 			onSend={(newMessages) => handleSend(newMessages)} 			user={{ _id: 1, name: "User" }} 		/> 	); };  export default ChatbotApp; 

Step to run the Project:

Step 1: Depdending on your opearting system, type the following command in terminal.

For android:

React-native run-android

For IOS:

React-native run-ios

Output:


Next Article
Create an E-commerce App using React-Native

S

sumitprajapat001
Improve
Article Tags :
  • Project
  • Web Technologies
  • ReactJS
  • Geeks Premier League
  • React-Native
  • Geeks Premier League 2023

Similar Reads

  • Create a Blog App using React-Native
    This article shows how to create a basic blog app using react native. This app contains functionalities such as adding a blog and a delete button to remove the blogs using react native. The user can enter content with a title and then click on 'Add New Post' to create a new blog post Preview of fina
    4 min read
  • Create a Camera App using React-Native
    A camera app using react native is a mobile application that is designed to capture photos or videos using the built-in camera functionality of a mobile device. In this article, you will learn how you can create a camera app with simple steps. Output Preview: Let us have a look at how the final appl
    3 min read
  • Create a Calling App using React-Native
    Building a Calling App using React-Native allows you to create a cross-platform application that supports voice calling. This tutorial will guide you through the process of integrating voice calling functionality into a React-Native app, enabling users to make and receive calls seamlessly. Preview o
    5 min read
  • Create ClassRoom App using React-Native
    ClassRoom App using React Native is a simple application designed to facilitate online learning and classroom management. These apps are commonly used in educational institutions, schools, colleges, and universities to enhance the teaching and learning experience. Preview of final output: Let us hav
    7 min read
  • Create an E-commerce App using React-Native
    An E-commerce app using react native is an application designed to facilitate online buying and selling of goods and services. These apps aim to provide a digital platform for businesses to showcase their products or services and for consumers to browse, compare, and purchase items without the need
    5 min read
  • Create Job Board App using React-Native
    In this article, we are going to Create a Job Board App using React Native. The Job Board App is a simple application that is a collection of job openings in any field. It helps the students and the people who are searching for jobs in the market. It helps to find jobs and provides in-depth informat
    6 min read
  • Create a Tip Calculator using React-Native
    A Tip Calculator proves to be a convenient tool for effortlessly calculating tips and dividing bills among friends at restaurants. The app enables users to input the bill amount, select their desired tip perce­ntage, specify the numbe­r of people sharing the bill, and promptly obtain calculate­d val
    5 min read
  • Create an Alarm Clock using React-Native
    React Native is a popular JavaScript framework for building cross-platform mobile applications which binds with a lot of features that help you to create versatile and industry-level applications. In this article, we will see the step-by-step process to create an Alarm Clock using React-Native. Prev
    3 min read
  • Create a Bill Splitter App using React-Native
    We are going to implement the Bill Splitter App using React Native. Bill Splitter App is a mobile application that helps us divide expenses and bills among a group of people. For example, when we are dining at a restaurant with friends, going on a trip, or sharing household expenses with roommates.
    4 min read
  • Create a Portfolio App using React-Native
    In this article, we are going to Create a portfolio app using React Native. The portfolio app is a simple application that is a collection of a person's qualifications, achievements, work samples, and other relevant materials. It is used to demonstrate one's abilities and suitability for a particula
    5 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