@aditya1301/greeting-module
v1.2.0
Published
A greeting chatbot with multilingual utilities, 4 built-in themes, and a plug-and-play DOM chat widget. Optionally extend with any LLM SDK.
Maintainers
Readme
@aditya1301/greeting-module
A greeting chatbot with multilingual utilities, 4 built-in themes, and a plug-and-play DOM chat widget.
Works out of the box with static responses — no API key required.
Optionally wire in any LLM (Claude, OpenAI, custom) via a single handler function.
Installation
npm install @aditya1301/greeting-moduleQuick Start
Node.js — static chatbot (no API key)
const { ChatbotClient } = require('@aditya1301/greeting-module');
const bot = new ChatbotClient();
const reply = await bot.sendMessage('Hello!');
console.log(reply); // "Hello there! Great to meet you! 😊"Browser — DOM chat widget (no API key)
const { ChatbotUI } = require('@aditya1301/greeting-module');
const chat = new ChatbotUI({ theme: 'ocean' });
chat.mount('#app'); // appends the chat widget into <div id="app">SDK Override — plug in any LLM
The handler option lets you replace the static engine with any LLM.
The handler receives (text, history, systemPrompt) and must return a Promise<string>.
Claude (Anthropic SDK)
npm install @anthropic-ai/sdkconst Anthropic = require('@anthropic-ai/sdk');
const { ChatbotClient } = require('@aditya1301/greeting-module');
const anthropic = new Anthropic({ apiKey: process.env.ANTHROPIC_API_KEY });
async function claudeHandler(text, history, systemPrompt) {
const response = await anthropic.messages.create({
model: 'claude-haiku-4-5',
max_tokens: 512,
system: [
{
type: 'text',
text: systemPrompt,
cache_control: { type: 'ephemeral' }, // prompt caching
},
],
messages: history,
});
return response.content
.filter(b => b.type === 'text')
.map(b => b.text)
.join('');
}
const bot = new ChatbotClient({ handler: claudeHandler });
const reply = await bot.sendMessage('Good morning!');
console.log(reply);OpenAI SDK
npm install openaiconst OpenAI = require('openai');
const { ChatbotClient } = require('@aditya1301/greeting-module');
const openai = new OpenAI({ apiKey: process.env.OPENAI_API_KEY });
async function openAIHandler(text, history, systemPrompt) {
const messages = [
{ role: 'system', content: systemPrompt },
...history,
];
const response = await openai.chat.completions.create({
model: 'gpt-4o-mini',
messages,
});
return response.choices[0].message.content;
}
const bot = new ChatbotClient({ handler: openAIHandler });Custom / local model
const { ChatbotClient } = require('@aditya1301/greeting-module');
async function myHandler(text, history, systemPrompt) {
const res = await fetch('http://localhost:11434/api/chat', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
model: 'llama3',
messages: [{ role: 'system', content: systemPrompt }, ...history],
}),
});
const data = await res.json();
return data.message.content;
}
const bot = new ChatbotClient({ handler: myHandler });ChatbotUI — browser widget with SDK override
Pass the same handler to ChatbotUI for a fully LLM-powered widget:
const { ChatbotUI } = require('@aditya1301/greeting-module');
const chat = new ChatbotUI({
theme: 'dark',
handler: claudeHandler, // any async handler from above
title: 'AI Assistant',
});
chat.mount('#app');Themes
Four built-in themes. Pass by name or a custom object.
| Name | Colors |
|------|--------|
| default | Red header + white background |
| dark | Purple + dark navy background |
| ocean | Blue + light cyan background |
| sunset | Orange + warm cream background |
// By name
const chat = new ChatbotUI({ theme: 'ocean' });
// Switch theme at runtime
chat.setTheme('sunset');
// Custom theme (deep-merged over default)
chat.setTheme({
colors: {
primary: '#10b981',
headerBg: '#10b981',
userBubble: '#10b981',
},
borderRadius: '4px',
});API Reference
ChatbotClient(options?)
| Option | Type | Default | Description |
|--------|------|---------|-------------|
| handler | async (text, history, systemPrompt) => string | null | LLM handler. If omitted, uses static responses. |
| systemPrompt | string | Built-in greeting prompt | System prompt passed to the handler. |
| starterMessages | Array | [{ role: 'assistant', content: '...' }] | Initial messages shown in history. |
Methods
| Method | Returns | Description |
|--------|---------|-------------|
| sendMessage(text) | Promise<string> | Send a message, get a reply. |
| getHistory() | Array | Returns a copy of the current conversation history. |
| clearHistory(keepStarter?) | void | Resets history. Pass false to clear everything. |
ChatbotUI(options?)
| Option | Type | Default | Description |
|--------|------|---------|-------------|
| theme | string \| Object | 'default' | Theme name or custom theme object. |
| handler | Function | null | Same as ChatbotClient.handler. |
| systemPrompt | string | Built-in | Override system prompt. |
| starterMessages | Array | Built-in | Override starter messages. |
| title | string | 'Greeting Assistant' | Header title text. |
| placeholder | string | 'Type a message…' | Input placeholder text. |
Methods
| Method | Description |
|--------|-------------|
| mount(el) | Append widget to a DOM element or CSS selector string. |
| setTheme(nameOrObj) | Swap theme at runtime and rebuild the widget in place. |
Sync utilities
const { greet, greetByTime, farewell } = require('@aditya1301/greeting-module');
greet('Alice'); // "Hello, Alice!"
greet('Carlos', 'es'); // "¡Hola, Carlos!"
greetByTime('Bob'); // "Good morning, Bob!" (based on system clock)
farewell('Alice'); // "Goodbye, Alice! Have a great day."Supported language codes: en, es, fr, hi, de
Running locally (development)
# Install dev deps
npm install
# Build the browser bundle
npm run build
# Start demo server at http://localhost:3000/demo.html
npm run demo