├── .gitignore ├── README.md ├── Screenshot_11.png ├── package.json ├── public ├── favicon.ico ├── index.html ├── logo192.png ├── logo512.png ├── manifest.json └── robots.txt ├── src ├── ActionProvider.js ├── App.css ├── App.js ├── App.test.js ├── MessageParser.js ├── components │ ├── LearningOptions │ │ ├── LearningOptions.css │ │ └── LearningOptions.js │ └── LinkList │ │ ├── LinkList.css │ │ └── LinkList.js ├── config.js ├── index.css ├── index.js ├── logo.svg ├── reportWebVitals.js └── setupTests.js └── yarn.lock /.gitignore: -------------------------------------------------------------------------------- 1 | # See https://help.github.com/articles/ignoring-files/ for more about ignoring files. 2 | 3 | # dependencies 4 | /node_modules 5 | /.pnp 6 | .pnp.js 7 | 8 | # testing 9 | /coverage 10 | 11 | # production 12 | /build 13 | 14 | # misc 15 | .DS_Store 16 | .env.local 17 | .env.development.local 18 | .env.test.local 19 | .env.production.local 20 | 21 | npm-debug.log* 22 | yarn-debug.log* 23 | yarn-error.log* 24 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ![](Screenshot_11.png) 2 | 3 |

React Chat Bot

4 | 5 |
 6 |   * React, React Hook, Jest
 7 | 
8 | 9 |

:gear: Getting started

10 | 11 | 1. Clone project. 12 | 2. Install required dependencies with `yarn install`. 13 | 3. Unit test using `yarn test` command 14 | 4. Run project using `npm start` command 15 | 5. Deploy on github-pages using `yarn build` command. -------------------------------------------------------------------------------- /Screenshot_11.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/codemaster730/React-ChartBot/5495aa9b84bf8d53f9e757a6ea5de8c149dd39de/Screenshot_11.png -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "chatbot", 3 | "version": "0.1.0", 4 | "private": true, 5 | "dependencies": { 6 | "@testing-library/jest-dom": "^5.11.4", 7 | "@testing-library/react": "^11.1.0", 8 | "@testing-library/user-event": "^12.1.10", 9 | "react": "^17.0.1", 10 | "react-chatbot-kit": "^1.1.2", 11 | "react-dom": "^17.0.1", 12 | "react-scripts": "4.0.2", 13 | "web-vitals": "^1.0.1" 14 | }, 15 | "scripts": { 16 | "start": "react-scripts start", 17 | "build": "react-scripts build", 18 | "test": "react-scripts test", 19 | "eject": "react-scripts eject" 20 | }, 21 | "eslintConfig": { 22 | "extends": [ 23 | "react-app", 24 | "react-app/jest" 25 | ] 26 | }, 27 | "browserslist": { 28 | "production": [ 29 | ">0.2%", 30 | "not dead", 31 | "not op_mini all" 32 | ], 33 | "development": [ 34 | "last 1 chrome version", 35 | "last 1 firefox version", 36 | "last 1 safari version" 37 | ] 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /public/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/codemaster730/React-ChartBot/5495aa9b84bf8d53f9e757a6ea5de8c149dd39de/public/favicon.ico -------------------------------------------------------------------------------- /public/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 12 | 13 | 17 | 18 | 27 | React App 28 | 29 | 30 | 31 |
32 | 42 | 43 | 44 | -------------------------------------------------------------------------------- /public/logo192.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/codemaster730/React-ChartBot/5495aa9b84bf8d53f9e757a6ea5de8c149dd39de/public/logo192.png -------------------------------------------------------------------------------- /public/logo512.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/codemaster730/React-ChartBot/5495aa9b84bf8d53f9e757a6ea5de8c149dd39de/public/logo512.png -------------------------------------------------------------------------------- /public/manifest.json: -------------------------------------------------------------------------------- 1 | { 2 | "short_name": "React App", 3 | "name": "Create React App Sample", 4 | "icons": [ 5 | { 6 | "src": "favicon.ico", 7 | "sizes": "64x64 32x32 24x24 16x16", 8 | "type": "image/x-icon" 9 | }, 10 | { 11 | "src": "logo192.png", 12 | "type": "image/png", 13 | "sizes": "192x192" 14 | }, 15 | { 16 | "src": "logo512.png", 17 | "type": "image/png", 18 | "sizes": "512x512" 19 | } 20 | ], 21 | "start_url": ".", 22 | "display": "standalone", 23 | "theme_color": "#000000", 24 | "background_color": "#ffffff" 25 | } 26 | -------------------------------------------------------------------------------- /public/robots.txt: -------------------------------------------------------------------------------- 1 | # https://www.robotstxt.org/robotstxt.html 2 | User-agent: * 3 | Disallow: 4 | -------------------------------------------------------------------------------- /src/ActionProvider.js: -------------------------------------------------------------------------------- 1 | class ActionProvider { 2 | constructor(createChatBotMessage, setStateFunc, createClientMessage) { 3 | this.createChatBotMessage = createChatBotMessage; 4 | this.setState = setStateFunc; 5 | this.createClientMessage = createClientMessage; 6 | } 7 | greet() { 8 | const greetingMessage = this.createChatBotMessage("Hi, friend.") 9 | this.updateChatbotState(greetingMessage) 10 | } 11 | handleJavascriptList = () => { 12 | const message = this.createChatBotMessage( 13 | "Fantastic, I've got the following resources for you on Javascript:", 14 | { 15 | widget: "javascriptLinks", 16 | } 17 | ); 18 | 19 | this.updateChatbotState(message); 20 | }; 21 | updateChatbotState(message) { 22 | 23 | // NOTE: This function is set in the constructor, and is passed in // from the top level Chatbot component. The setState function here // actually manipulates the top level state of the Chatbot, so it's // important that we make sure that we preserve the previous state. 24 | 25 | 26 | this.setState(prevState => ({ 27 | ...prevState, messages: [...prevState.messages, message] 28 | })) 29 | } 30 | } 31 | 32 | export default ActionProvider; 33 | -------------------------------------------------------------------------------- /src/App.css: -------------------------------------------------------------------------------- 1 | .App { 2 | text-align: center; 3 | } 4 | 5 | .App-logo { 6 | height: 40vmin; 7 | pointer-events: none; 8 | } 9 | 10 | @media (prefers-reduced-motion: no-preference) { 11 | .App-logo { 12 | animation: App-logo-spin infinite 20s linear; 13 | } 14 | } 15 | 16 | .App-header { 17 | background-color: #282c34; 18 | min-height: 100vh; 19 | display: flex; 20 | flex-direction: column; 21 | align-items: center; 22 | justify-content: center; 23 | font-size: calc(10px + 2vmin); 24 | color: white; 25 | } 26 | 27 | .App-link { 28 | color: #61dafb; 29 | } 30 | 31 | @keyframes App-logo-spin { 32 | from { 33 | transform: rotate(0deg); 34 | } 35 | to { 36 | transform: rotate(360deg); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /src/App.js: -------------------------------------------------------------------------------- 1 | import logo from './logo.svg'; 2 | import './App.css'; 3 | import Chatbot from 'react-chatbot-kit'; 4 | 5 | import ActionProvider from './ActionProvider'; 6 | import MessageParser from './MessageParser'; 7 | import config from './config'; 8 | 9 | function App() { 10 | return ( 11 |
12 |
13 | 14 |
15 |
16 | ); 17 | } 18 | 19 | export default App; 20 | -------------------------------------------------------------------------------- /src/App.test.js: -------------------------------------------------------------------------------- 1 | import { render, screen } from '@testing-library/react'; 2 | import App from './App'; 3 | 4 | test('renders learn react link', () => { 5 | render(); 6 | const linkElement = screen.getByText(/learn react/i); 7 | expect(linkElement).toBeInTheDocument(); 8 | }); 9 | -------------------------------------------------------------------------------- /src/MessageParser.js: -------------------------------------------------------------------------------- 1 | class MessageParser { 2 | constructor(actionProvider, state) { 3 | this.actionProvider = actionProvider; 4 | this.state = state; 5 | } 6 | 7 | parse(message) { 8 | const lowerCaseMessage = message.toLowerCase() 9 | 10 | if (lowerCaseMessage.includes("hello") || lowerCaseMessage.includes("hi")) { 11 | this.actionProvider.greet() 12 | } 13 | if (lowerCaseMessage.includes("javascript")) { 14 | this.actionProvider.handleJavascriptList(); 15 | } 16 | } 17 | } 18 | 19 | export default MessageParser; -------------------------------------------------------------------------------- /src/components/LearningOptions/LearningOptions.css: -------------------------------------------------------------------------------- 1 | .learning-options-container { 2 | display: flex; 3 | align-items: flex-start; 4 | flex-wrap: wrap; 5 | } 6 | 7 | .learning-option-button { 8 | padding: 0.5rem; 9 | border-radius: 25px; 10 | background: transparent; 11 | border: 1px solid green; 12 | margin: 3px; 13 | } -------------------------------------------------------------------------------- /src/components/LearningOptions/LearningOptions.js: -------------------------------------------------------------------------------- 1 | import React from "react"; 2 | 3 | import "./LearningOptions.css"; 4 | 5 | const LearningOptions = (props) => { 6 | const options = [ 7 | { 8 | text: "Javascript", 9 | handler: props.actionProvider.handleJavascriptList, 10 | id: 1 11 | }, 12 | { text: "Data visualization", handler: () => {}, id: 2 }, 13 | { text: "APIs", handler: () => {}, id: 3 }, 14 | { text: "Security", handler: () => {}, id: 4 }, 15 | { text: "Interview prep", handler: () => {}, id: 5 }, 16 | ]; 17 | 18 | const optionsMarkup = options.map((option) => ( 19 | 26 | )); 27 | 28 | return
{optionsMarkup}
; 29 | }; 30 | 31 | export default LearningOptions; -------------------------------------------------------------------------------- /src/components/LinkList/LinkList.css: -------------------------------------------------------------------------------- 1 | 2 | 3 | .link-list { 4 | padding: 0; 5 | } 6 | 7 | .link-list-item { 8 | text-align: left; 9 | font-size: 0.9rem; 10 | } 11 | 12 | .link-list-item-url { 13 | text-decoration: none; 14 | margin: 6px; 15 | display: block; 16 | color: #1d1d1d; 17 | background-color: #f1f1f1; 18 | padding: 8px; 19 | border-radius: 3px; 20 | box-shadow: 2px 2px 4px rgba(150, 149, 149, 0.4); 21 | } -------------------------------------------------------------------------------- /src/components/LinkList/LinkList.js: -------------------------------------------------------------------------------- 1 | import React from "react"; 2 | 3 | import "./LinkList.css"; 4 | 5 | const LinkList = (props) => { 6 | const linkMarkup = props.options.map((link) => ( 7 |
  • 8 | 14 | {link.text} 15 | 16 |
  • 17 | )); 18 | 19 | return ; 20 | }; 21 | 22 | export default LinkList; 23 | 24 | -------------------------------------------------------------------------------- /src/config.js: -------------------------------------------------------------------------------- 1 | import { createChatBotMessage } from "react-chatbot-kit"; 2 | import LearningOptions from "./components/LearningOptions/LearningOptions"; 3 | import LinkList from "./components/LinkList/LinkList"; 4 | 5 | const config = { 6 | // initialMessages: [createChatBotMessage(`Hi I am a bot`)] 7 | botName: "LearningBot", 8 | initialMessages: [ 9 | createChatBotMessage("Hi, I'm here to help. What do you want to learn?", { 10 | widget: "learningOptions", 11 | }) 12 | ], 13 | customStyles: { 14 | botMessageBox: { 15 | backgroundColor: "#376B7E", 16 | }, 17 | chatButton: { 18 | backgroundColor: "#376B7E", 19 | }, 20 | }, 21 | widgets: [ 22 | { 23 | widgetName: "learningOptions", 24 | widgetFunc: (props) => 25 | }, 26 | { 27 | widgetName: "javascriptLinks", 28 | widgetFunc: (props) => , 29 | props: { 30 | options: [ 31 | { 32 | text: "Introduction to JS", 33 | url: 34 | "https://www.freecodecamp.org/learn/javascript-algorithms-and-data-structures/basic-javascript/", 35 | id: 1, 36 | }, 37 | { 38 | text: "Mozilla JS Guide", 39 | url: 40 | "https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide", 41 | id: 2, 42 | }, 43 | { 44 | text: "Frontend Masters", 45 | url: "https://frontendmasters.com", 46 | id: 3, 47 | }, 48 | ], 49 | }, 50 | }, 51 | ] 52 | } 53 | 54 | export default config -------------------------------------------------------------------------------- /src/index.css: -------------------------------------------------------------------------------- 1 | body { 2 | margin: 0; 3 | font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen', 4 | 'Ubuntu', 'Cantarell', 'Fira Sans', 'Droid Sans', 'Helvetica Neue', 5 | sans-serif; 6 | -webkit-font-smoothing: antialiased; 7 | -moz-osx-font-smoothing: grayscale; 8 | } 9 | 10 | code { 11 | font-family: source-code-pro, Menlo, Monaco, Consolas, 'Courier New', 12 | monospace; 13 | } 14 | -------------------------------------------------------------------------------- /src/index.js: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | import ReactDOM from 'react-dom'; 3 | import './index.css'; 4 | import App from './App'; 5 | import reportWebVitals from './reportWebVitals'; 6 | 7 | ReactDOM.render( 8 | 9 | 10 | , 11 | document.getElementById('root') 12 | ); 13 | 14 | // If you want to start measuring performance in your app, pass a function 15 | // to log results (for example: reportWebVitals(console.log)) 16 | // or send to an analytics endpoint. Learn more: https://bit.ly/CRA-vitals 17 | reportWebVitals(); 18 | -------------------------------------------------------------------------------- /src/logo.svg: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /src/reportWebVitals.js: -------------------------------------------------------------------------------- 1 | const reportWebVitals = onPerfEntry => { 2 | if (onPerfEntry && onPerfEntry instanceof Function) { 3 | import('web-vitals').then(({ getCLS, getFID, getFCP, getLCP, getTTFB }) => { 4 | getCLS(onPerfEntry); 5 | getFID(onPerfEntry); 6 | getFCP(onPerfEntry); 7 | getLCP(onPerfEntry); 8 | getTTFB(onPerfEntry); 9 | }); 10 | } 11 | }; 12 | 13 | export default reportWebVitals; 14 | -------------------------------------------------------------------------------- /src/setupTests.js: -------------------------------------------------------------------------------- 1 | // jest-dom adds custom jest matchers for asserting on DOM nodes. 2 | // allows you to do things like: 3 | // expect(element).toHaveTextContent(/react/i) 4 | // learn more: https://github.com/testing-library/jest-dom 5 | import '@testing-library/jest-dom'; 6 | --------------------------------------------------------------------------------