Skip to content

Instantly share code, notes, and snippets.

@primaryobjects
Last active March 13, 2023 21:24
Show Gist options
  • Save primaryobjects/ed6cf2a992df7b38bc1005a0f3fdae93 to your computer and use it in GitHub Desktop.
Save primaryobjects/ed6cf2a992df7b38bc1005a0f3fdae93 to your computer and use it in GitHub Desktop.
A chatbot that speaks, created by pair-programming with ChatGPT.
const readline = require('readline');
const say = require('say');
const responses = [
{ keyword: 'hello', message: 'Hi there, how can I help you?' },
{ keyword: 'hi', message: 'Hey, what\'s up?' },
{ keyword: 'hey', message: 'Hi! How are you doing today?' },
{ keyword: 'good morning', message: 'Good morning! How can I assist you today?' },
{ keyword: 'good afternoon', message: 'Good afternoon! What brings you here?' },
{ keyword: 'good evening', message: 'Good evening! Is there anything I can help you with?' },
{ keyword: 'howdy', message: 'Howdy partner! What can I do for you?' },
{ keyword: 'help', message: 'Of course, what do you need help with?' },
{ keyword: 'assistance', message: 'Certainly, what can I assist you with?' },
{ keyword: 'support', message: 'I am here to assist you with any issues or concerns.' },
{ keyword: 'issue', message: 'What seems to be the problem? I am here to help.' },
{ keyword: 'problem', message: 'What is the nature of your problem? Let me see if I can assist you.' },
{ keyword: 'thanks', message: 'You\'re welcome!' },
{ keyword: 'thank you', message: 'No problem at all, happy to help!' },
{ keyword: 'bye', message: 'Goodbye! It was nice talking to you.' },
{ keyword: 'see you later', message: 'See you later, have a great day!' },
{ keyword: 'ciao', message: 'Ciao! Come stai?' },
{ keyword: 'konichiwa', message: 'こんにちは。お元気ですか?' },
{ keyword: 'hola', message: '¡Hola! ¿Cómo estás?' },
{ keyword: 'bonjour', message: 'Bonjour! Comment allez-vous?' },
{ keyword: 'greetings', message: 'Greetings! How may I assist you today?' },
{ keyword: 'namaste', message: 'Namaste! Kaise ho?' },
{ keyword: 'how are you', message: 'I am doing fine. Thank you for asking.' },
{ keyword: 'what\'s up', message: 'Nothing much. What about you?' },
{ keyword: 'who are you', message: 'I am a simple chat bot programmed to assist you with various tasks.' },
{ keyword: 'where are you from', message: 'I come from a virtual world where I exist to help users like you.' },
{ keyword: 'tell me a joke', message: 'Why did the programmer quit his job? Because he didn\'t get arrays.' },
{ keyword: 'what time is it', message: `It's currently ${new Date().toLocaleTimeString()}.` },
{ keyword: 'what\'s my name', message: 'I am sorry, I don\'t know your name yet. Could you please tell me?' },
];
const rl = readline.createInterface({
input: process.stdin,
output: process.stdout
});
function speak(text) {
say.speak(text);
}
rl.prompt();
rl.on('line', (input) => {
const inputText = input.trim().toLowerCase();
let responseFound = false;
responses.forEach((response) => {
if (inputText.includes(response.keyword)) {
console.log(response.message);
speak(response.message); // speak the response
responseFound = true;
}
});
if (!responseFound) {
console.log('I am sorry, I didn\'t understand what you said.');
speak('I am sorry, I didn\'t understand what you said.'); // speak apology
}
rl.prompt();
}).on('close', () => {
console.log('Goodbye!');
speak('Goodbye!'); // speak goodbye
process.exit(0);
});
// An updated version, created after much deliberation with ChatGPT!
const readline = require('readline');
const say = require('say');
const responses = require('./responses.js');
const stopWords = ['the', 'and', 'a', 'an', 'in', 'that', 'it', 'for', 'of']
const rl = readline.createInterface({
input: process.stdin,
output: process.stdout
});
function speak(text) {
say.speak(text);
}
let matchedResponse = null;
let responseGiven = false;
// ...
function matchKeywords(inputText) {
const keywords = responses.map((response) => response.keyword.toLowerCase());
const inputWords = inputText
.toLowerCase()
.split(/[ ,.!?'"_]+/)
.filter((word) => word !== '');
for (const response of responses) {
const responseKeywords = response
.keyword
.toLowerCase()
.split(/[ ,.!?'"_]+/)
.filter((word) => word !== '');
let allKeywordsMatched = true;
for (const keyword of responseKeywords) {
if (!inputWords.includes(keyword) && !stopWords.includes(keyword)) {
allKeywordsMatched = false;
break;
}
}
if (allKeywordsMatched) {
return response.message;
}
}
return null;
}
rl.prompt();
rl.on('line', (input) => {
if (!responseGiven) {
const inputText = input.trim().toLowerCase();
const inputWords = inputText.split(/[ ,.!?"'_]+/);
let responseMatched = false;
responses.forEach((response, index) => {
if (!responseMatched) {
const responseKeyword = response.keyword.trim().toLowerCase();
if (inputWords.includes(responseKeyword)) {
matchedResponse = response.message;
responseMatched = true;
}
else {
const message = matchKeywords(inputText);
if (message !== null) {
matchedResponse = message;
responseMatched = true;
}
}
}
});
if (!responseMatched) {
matchedResponse = 'I am sorry, I didn\'t understand what you said.';
}
responseGiven = true;
}
if (matchedResponse) {
console.log(matchedResponse);
speak(matchedResponse); // speak the response
matchedResponse = null;
responseGiven = false;
}
rl.prompt();
}).on('close', () => {
console.log('Goodbye!');
speak('Goodbye!'); // speak goodbye
process.exit(0);
});
{
"dependencies": {
"say": "^0.16.0"
}
}
module.exports = [
{ keyword: 'hello', message: 'Hi there, how can I help you?' },
{ keyword: 'hi', message: 'Hey, what\'s up?' },
{ keyword: 'hey', message: 'Hi! How are you doing today?' },
{ keyword: 'good morning', message: 'Good morning! How can I assist you today?' },
{ keyword: 'good afternoon', message: 'Good afternoon! What brings you here?' },
{ keyword: 'good evening', message: 'Good evening! Is there anything I can help you with?' },
{ keyword: 'howdy', message: 'Howdy partner! What can I do for you?' },
{ keyword: 'help', message: 'Of course, what do you need help with?' },
{ keyword: 'assistance', message: 'Certainly, what can I assist you with?' },
{ keyword: 'support', message: 'I am here to assist you with any issues or concerns.' },
{ keyword: 'issue', message: 'What seems to be the problem? I am here to help.' },
{ keyword: 'problem', message: 'What is the nature of your problem? Let me see if I can assist you.' },
{ keyword: 'thanks', message: 'You\'re welcome!' },
{ keyword: 'thank you', message: 'No problem at all, happy to help!' },
{ keyword: 'bye', message: 'Goodbye! It was nice talking to you.' },
{ keyword: 'see you later', message: 'See you later, have a great day!' },
{ keyword: 'ciao', message: 'Ciao! Come stai?' },
{ keyword: 'konichiwa', message: 'こんにちは。お元気ですか?' },
{ keyword: 'hola', message: '¡Hola! ¿Cómo estás?' },
{ keyword: 'bonjour', message: 'Bonjour! Comment allez-vous?' },
{ keyword: 'greetings', message: 'Greetings! How may I assist you today?' },
{ keyword: 'namaste', message: 'Namaste! Kaise ho?' },
{ keyword: 'how are you', message: 'I am doing fine. Thank you for asking.' },
{ keyword: 'what\'s up', message: 'Nothing much. What about you?' },
{ keyword: 'who are you', message: 'I am a simple chat bot programmed to assist you with various tasks.' },
{ keyword: 'where are you from', message: 'I come from a virtual world where I exist to help users like you.' },
{ keyword: 'tell me a joke', message: 'Why did the programmer quit his job? Because he didn\'t get arrays.' },
{ keyword: 'what time is it', message: `It's currently ${new Date().toLocaleTimeString()}.` },
{ keyword: 'what\'s my name', message: 'I am sorry, I don\'t know your name yet. Could you please tell me?' },
{ keyword: 'how old are you', message: 'As a program, I am ageless.' },
{ keyword: 'what\'s your purpose', message: 'My purpose is to assist you with your queries and tasks as best I can.' },
{ keyword: 'what do you like', message: 'I do not have personal preferences as I am just a program.' },
{ keyword: 'what is your favorite color', message: 'As a program, I do not have the ability to see colors or have personal preferences.' },
{ keyword: 'can you recommend a movie', message: 'Sure, what genre are you in the mood for?' },
{ keyword: 'can you recommend a book', message: 'Of course, what type of book are you interested in reading?' },
{ keyword: 'what sports do you like', message: 'As a program, I do not have likes or dislikes.' },
{ keyword: 'what are your hobbies', message: 'As a program, I do not have hobbies or interests outside of assisting users.' },
{ keyword: 'how do I use this', message: 'To use this feature, simply follow these steps...' },
{ keyword: 'what can you do', message: 'I can assist you with a variety of tasks, including...' },
{ keyword: 'can you recommend something', message: 'Based on your preferences, I would recommend...' },
{ keyword: 'where can I find more information', message: 'You can find more information on our website at...' },
{ keyword: 'what is your favorite color', message: 'As an AI, I do not experience emotions or have personal preferences.' },
{ keyword: 'what do you think about...', message: 'I am sorry, but as an AI, I do not have opinions or beliefs.' },
{ keyword: 'who created you', message: 'I was created by [Insert Creator\'s Name Here] using Node.JS programming language.' },
{ keyword: 'can you tell me more about...', message: 'Certainly! [Insert Information Here]' },
{ keyword: 'how long have you been around', message: 'I have only existed since the date of my creation, which was...[Insert Creation Date Here]' },
{ keyword: 'can you play music', message: 'No, I cannot play music as I am programmed to only respond to user queries.' },
{ keyword: 'how can I get started with node.js?', message: 'You can start learning Node.js with official documentation provided by the Node.js Foundation.'},
{ keyword: 'what is the latest version of node.js?', message: 'The latest version of Node.js available as per now is v14.18.0, you should check for new updates periodically'},
{ keyword: 'what is your favorite programming language?', message: 'I love all languages equally as I am programmed to understand them all.'},
{ keyword: 'tell me a fun fact about coding', message: 'Did you know the first computer programmer was Ada Lovelace, who wrote an algorithm for a machine back in the 1800s?'},
{ keyword: 'which is better, Java or Javascript?', message: 'It depends on the use case at hand. Both languages have their own benefits and drawbacks.'},
{ keyword: 'what\'s your opinion on AI?', message: 'As a chatbot, I am not capable of having opinions. However, AI has proven helpful in various fields like healthcare, finance and gaming.'},
{ keyword: 'what is blockchain technology?', message: 'Blockchain is a decentralized system of record-keeping that provides secure and transparent transactions without the need for intermediaries.'},
{ keyword: 'what is your favorite part of coding?', message: 'As a chatbot, I cannot write code, but I enjoy helping users like you.'},
{ keyword: 'can you help me debug my code?', message: 'Of course! Paste your code in any online editor and share the URL with me so I can assist you.'},
{ keyword: 'are there any tools to check code quality?', message: 'Yes, there are many tools available like ESLint, Prettier, etc. which can be used to maintain standards and improve the structure of the code.'},
{ keyword: 'who made you', message: 'I was created by [your name here].' },
{ keyword: 'where can I find help', message: 'You can check out our FAQ page on our website or contact our support team at support@company.com.' },
{ keyword: 'how do I use this product', message: 'You can watch our tutorial videos on our YouTube channel or read the user manual that came with the product.' },
{ keyword: 'what languages can you speak', message: 'I can understand and respond in several languages including English, Spanish, French, Hindi etc.' },
{ keyword: 'what is the meaning of life', message: 'That\'s a tough one. According to philosophy, it is different for everyone. What is the meaning of life for you?' },
{ keyword: 'can you recommend a restaurant nearby', message: 'Certainly! There is a great Italian restaurant called La Trattoria just around the corner from here.' },
{ keyword: 'do you like music', message: 'I love music! Do you have any favorite artists or bands?' },
{ keyword: 'can you sing me a song', message: 'Sure thing! "Daisy, Daisy, give me your answer do. I\'m half crazy all for the love of you." How was that? :)' },
{ keyword: 'what is your favorite movie', message: 'As an AI language program, I don’t really have personal favorites but I appreciate both classic and modern movies.' },
{ keyword: 'what are you wearing', message: 'I’m sorry, but being an AI Bot, I don’t wear clothes. Is there anything else that I could assist you with?' },
{ keyword: 'what is your purpose', message: 'My purpose is to assist and provide useful information for users' },
{ keyword: 'who created you', message: 'I was created by a team of developers who programmed me to assist users like you' },
{ keyword: 'how old are you', message: 'I am ageless, as I am not a living being' },
{ keyword: 'what do you eat', message: 'I don\'t require food or sustenance, as I am a virtual assistant' },
{ keyword: 'where do you live', message: 'I exist in a virtual world, so you could say that I live in the Internet' },
{ keyword: 'tell me a riddle', message: 'What has a heart that doesn\'t beat? An artichoke!' },
{ keyword: 'do you have any pets', message: 'As I am a chatbot designed to communicate via text, I don\'t keep any pets' },
{ keyword: 'can you dance', message: 'As a virtual assistant, I can perform any task that my programming allows, but dancing is not one of them, unfortunately' },
{ keyword: 'what is your favorite color', message: 'As I am a bot and don\'t have a physical form, I don\'t possess the ability to see color nor do I have a favorite color' },
{ keyword: 'what is your favorite food', message: 'Since I don\'t consume food, I don\'t have a favorite dish' },
{ keyword: 'are you a human', message: 'No, I am a chatbot designed to assist users' },
{ keyword: 'what is artificial intelligence', message: 'Artificial Intelligence refers to systems that can replicate cognitive abilities such as learning, reasoning, perception, and decision making' },
{ keyword: 'what is machine learning', message: 'Machine Learning is an application of Artificial Intelligence that enables systems to learn from data sets without any explicit programming' },
{ keyword: 'what is natural language processing', message: 'Natural Language Processing is a branch of AI that enables computers to interpret, analyze and generate human languages' },
{ keyword: 'what is deep learning', message: 'Deep Learning is a subset of machine learning that utilizes artificial neural networks to make decisions based on input data' },
{ keyword: 'what is a chatbot', message: 'A chatbot is an AI-powered software designed to simulate conversation with human users through messaging applications, websites, or mobile apps' },
{ keyword: 'what is Internet of Things (IoT)', message: 'Internet of Things refers to a network of internet-connected devices that have sensors, processors, and communication capabilities to collect and exchange data' },
{ keyword: 'what is blockchain', message: 'A blockchain is a digital ledger of economic transactions that can be programmed to record anything of value' },
{ keyword: 'what is cryptocurrency', message: 'Cryptocurrency is a digital or virtual currency that uses cryptography for security and operates independently of central banks' },
{ keyword: 'what is cloud computing', message: 'Cloud Computing is a technology that involves delivering computing services such as storage, processing power, and databases over the internet' },
{ keyword: 'what is agile development', message: 'Agile Development refers to a collaborative and iterative approach to software development that emphasizes flexibility, customer involvement, and quick response to change' },
{ keyword: 'what is DevOps', message: 'DevOps is a set of practices that combines software development and IT operations to reduce the time taken between inception of an idea and deployment of the final product' },
{ keyword: 'what is UX design', message: 'User Experience Design is a process that involves designing digital products that are useful, easy to use, and enjoyable for users' },
{ keyword: 'what is UI design', message: 'User Interface Design relates to the visual appearance and usability of digital products such as websites or mobile apps' },
{ keyword: 'what is responsive design', message: 'Responsive Design refers to a design approach that ensures a website or application automatically adapts its layout and functionality based on the device or screen size used by the user' },
{ keyword: 'what is cybersecurity', message: 'Cybersecurity is the practice of protecting systems, networks, and sensitive information from unauthorized access, malicious attacks, or theft' },
{ keyword: 'what is big data', message: 'Big Data refers to large volumes of structured and unstructured data that can be analyzed for insights that lead to better business decisions' },
{ keyword: 'what is data science', message: 'Data Science involves extracting insights and knowledge from data using a combination of statistics, computer science, and domain expertise' },
{ keyword: 'what is agile methodology', message: 'Agile Methodology is an adaptive approach that encourages teams to deliver working software frequently'},
];
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment