chimcham-chatter
v1.0.0
Published
A customizable chatbot library for web applications
Maintainers
Readme
ChimCham Chatter
A lightweight, customizable chatbot library for web applications that allows you to create pattern-matching chatbots with ease.
Installation
npm install chimcham-chatterOr include directly in your HTML:
<script src="path/to/chimcham-chatter.js"></script>Usage
Basic Setup
// Create a new chatbot instance
const chatbot = new ChimChamChatter({
defaultResponse: "I'm not sure how to respond to that."
});
// Add pattern-response pairs
chatbot.addPattern("hello", "Hi there! How can I help you?");
chatbot.addPattern("how are you", "I'm doing great, thanks for asking!");
// Process user input
const response = chatbot.processInput("hello");
console.log(response); // Outputs: "Hi there! How can I help you?"Using %LIKE% Pattern Matching
The %LIKE% keyword allows for flexible pattern matching. It will match any word in that position:
// This pattern will match "I like pizza", "I love pizza", "I enjoy pizza", etc.
chatbot.addPattern("I %LIKE% pizza", "Pizza is delicious!");
// This will match "What is your name", "What's your name", etc.
chatbot.addPattern("what %LIKE% your name", "I'm ChimCham, nice to meet you!");Using Function Responses
You can use functions as responses for dynamic content:
chatbot.addPattern("what time is it", (input) => {
return `The current time is ${new Date().toLocaleTimeString()}`;
});Conversation History
// Get the conversation history
const history = chatbot.getConversationHistory();
// Clear the conversation history
chatbot.clearHistory();Features
- Simple pattern matching with %LIKE% keyword support
- Dynamic responses using functions
- Conversation history tracking
- Customizable default responses
- Works in both Node.js and browser environments
License
MIT
