<!DOCTYPE html> <html> <head> <title>Chatbot</title> </head> <body> <div class="js-container"></div> <script src="https://unpkg.com/supersimpledev/react.js"></script> <script src="https://unpkg.com/supersimpledev/react-dom.js"></script> <script src="https://unpkg.com/supersimpledev/chatbot.js"></script> <script src="https://unpkg.com/supersimpledev/babel.js"></script> <script type="text/babel"> function ChatInput({chatMessages, setChatMessages}){ const [inputText, setInputText] = React.useState(''); function saveInputText(event) { // console.log(event.target.value); setInputText(event.target.value); } function sendMessage() { // console.log(inputText); const newChatMessages = [ ...chatMessages, { message : inputText, sender : 'user', id : crypto.randomUUID() } ]; setChatMessages(newChatMessages); const response = Chatbot.getResponse(inputText); // console.log(response); setChatMessages([ ...newChatMessages, { message : response, sender : 'robot', id : crypto.randomUUID() } ]); setInputText(''); } return ( <> {/* using fragment to remove extra div elements */} <input placeholder="Send a message to chatbot" size="30" onChange={saveInputText} value={inputText} /> <button onClick = {sendMessage} >Send</button> </> ); } function ChatMessage({message, sender}){ return ( <div> {/* use div element to put the ChatMessage on a new line */} {sender === 'robot' && <img src="robot.jpeg" width= "50"/>} {message} {sender === 'user' && <img src="human.jpeg" width= "50"/>} </div> ) } function ChatMessages({chatMessages}) { /* in react we should not modify the data directly. We should create a copy of the data and modify the copy. */ return ( <> {chatMessages.map((chatMessage) => { return ( <ChatMessage message={chatMessage.message} sender={chatMessage.sender} key={chatMessage.id} /> ); } )} </> ); } function App (){ const array = React.useState([{ message: 'hello chatbot', sender: 'user', id : 'id1' }, { message: 'Hello! How can I help you?', sender: 'robot', id : 'id2' }, { message: 'Can you get me todays date?', sender: 'user', id : 'id3' }, { message: 'Today is September 26', sender: 'robot', id : 'id4' } ] ); const chatMessages = array[0]; const setChatMessages = array[1]; return (<> <ChatInput chatMessages={chatMessages} setChatMessages={setChatMessages} /> <ChatMessages chatMessages={chatMessages} /> </>); } //const app = ( App ); const container = document.querySelector('.js-container'); ReactDOM.createRoot(container).render(<App />); </script> </body> </html>
Navigation Bar
- Oracle Developer
- Date Functions
- Queries
- PL/SQL
- Oracle XML DB
- Oracle XML DB: An Example
- To Store and Select XML Data
- XMLDB : Examples of using getClobVal, getStringVal and getNumberVal
- XMLDB: Convert xml file into equivalent relational dataset
- XMLDB: XML to HTML with XSL stylesheet
- XMLDB : DBUriType
- XMLDB : XML Functions continued ...
- XMLElement, XMLAttributes, XMLAgg, XMLForest - Examples
- JSON in Oracle
- Working with JSONs in Oracle
- PL/SQL Object Types and Methods for JSON
- Oracle JSON : Select Level 1 and Level 2 data
- A JSON generator using SQL and PLSQL
- XML to JSON and JSON to XML
- Parsing a JSON object with Oracle PLSQL
- Parsing and updating a JSON object using PLSQL
- A generic JSON parser with update using Oracle PL/SQL
- A generic multi level JSON object parse and update script using PLSQL
- A generic JSON parser and JSON generator using a config table
- A generic JSON generator using a config table
- Common Oracle Errors
- Exception Handling
- Archiving
- Reclaim tablespace size after a large table delete
- Data Archiving in Oracle
- Archiving a generic solution - Part 1
- Archiving a generic solution - Part 2
- Archiving a generic solution - Part 3
- Archiving a generic solution - Part 4
- Archiving a generic solution - Part 5
- Archiving a generic solution - Part 6 - Deploy and Test
- Archiving - Case Study for optimizing disk space utilization with archiving
- Archiving : Changes for data replication
- Archiving : A case study for data replication
- Data Replication : Using Change Notification and DBMS_SCHEDULER as a LISTENER
- Oracle DBA
- Knowledge Base
- Linux
- Oracle Dewdrops
- Newsletters
- Java
Thursday, October 1, 2026
React - Chatbot - Display response from the bot
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment