chatjs-free 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +26 -0
- package/dist/img/chatjs.svg +4 -0
- package/dist/img/user.svg +1 -0
- package/dist/index.html +50 -0
- package/dist/questions.txt +27 -0
- package/package.json +18 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Hayam
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
<div align="center">
|
|
2
|
+
<img src="chatjs.svg" width=200 />
|
|
3
|
+
</div>
|
|
4
|
+
|
|
5
|
+
# ChatJS
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
_ChatJS is a rule-based chatbot designed to remove API costs and give precise responses even in air-gapped areas and/or areas with no internet access._
|
|
9
|
+
|
|
10
|
+
By handling predictable conversations without relying on AI models for every request, ChatJS provides end users with more precise answers while improving performance and lowering operational expenses. This matters for every web and webapps out there because this chat interface gives end users a hope to find the answers related to the certain thing while ensuring all users get the right answer/s they need without any hallucination crap.
|
|
11
|
+
|
|
12
|
+
### Maintainer Info:
|
|
13
|
+
|
|
14
|
+
<table>
|
|
15
|
+
<tr>
|
|
16
|
+
<th>Name</th>
|
|
17
|
+
<th>Email</th>
|
|
18
|
+
<th>Github</th>
|
|
19
|
+
</tr>
|
|
20
|
+
<tr>
|
|
21
|
+
<td>Hayam</td>
|
|
22
|
+
<td><a href="mailto:hayam@duck.com">hayam@duck.com</a></td>
|
|
23
|
+
<td><a href="https://github.com/hayamahamed">@hayamahamed</a></td>
|
|
24
|
+
</tr>
|
|
25
|
+
</table>
|
|
26
|
+
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
<svg xmlns="http://www.w3.org/2000/svg" width="100" height="100" viewBox="0 0 24 24" fill="none" stroke="#cc0000" stroke-width="0.5" stroke-linecap="round" stroke-linejoin="round" class="ChatJS">
|
|
2
|
+
<path fill="#cc0000" d="M16 10a2 2 0 0 1-2 2H6.828a2 2 0 0 0-1.414.586l-2.202 2.202A.71.71 0 0 1 2 14.286V4a2 2 0 0 1 2-2h10a2 2 0 0 1 2 2z"/>
|
|
3
|
+
<path d="M20 9a2 2 0 0 1 2 2v10.286a.71.71 0 0 1-1.212.502l-2.202-2.202A2 2 0 0 0 17.172 19H10a2 2 0 0 1-2-2v-1"/>
|
|
4
|
+
</svg>
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
<svg xmlns="http://www.w3.org/2000/svg" width="100" height="100" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-circle-user-round-icon lucide-circle-user-round"><path d="M17.925 20.056a6 6 0 0 0-11.851.001"/><circle cx="12" cy="11" r="4"/><circle cx="12" cy="12" r="10"/></svg>
|
package/dist/index.html
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
<!doctype html>
|
|
2
|
+
<html lang="en">
|
|
3
|
+
<head>
|
|
4
|
+
<meta charset="UTF-8" />
|
|
5
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
|
6
|
+
<title>ChatJS</title>
|
|
7
|
+
<meta
|
|
8
|
+
name="description"
|
|
9
|
+
content="ChatJS is a rule-based chatbot designed to remove API costs and give precise responses. By handling predictable conversations without relying on AI models for every request, ChatJS provides end users with more precise answers while improving performance and lowering operational expenses."
|
|
10
|
+
/>
|
|
11
|
+
<link rel="icon" href="/docs/chatjs.svg" />
|
|
12
|
+
<script type="module" crossorigin>(function(){let e=document.createElement(`link`).relList;if(e&&e.supports&&e.supports(`modulepreload`))return;for(let e of document.querySelectorAll(`link[rel="modulepreload"]`))n(e);new MutationObserver(e=>{for(let t of e)if(t.type===`childList`)for(let e of t.addedNodes)e.tagName===`LINK`&&e.rel===`modulepreload`&&n(e)}).observe(document,{childList:!0,subtree:!0});function t(e){let t={};return e.integrity&&(t.integrity=e.integrity),e.referrerPolicy&&(t.referrerPolicy=e.referrerPolicy),t.credentials=e.crossOrigin===`use-credentials`?`include`:e.crossOrigin===`anonymous`?`omit`:`same-origin`,t}function n(e){if(e.ep)return;e.ep=!0;let n=t(e);fetch(e.href,n)}})();var e={dataFile:`questions.txt`,botName:`ChatJS`,botAvatar:`img/chatjs.svg`,userAvatar:`img/user.svg`,greeting:`Hi there! How can I help you today.`,typingDelayMs:500,storageKey:`chatapp:transcript`,paragraphGapUnitPx:8},t=document.getElementById(`chatWindow`),n=document.getElementById(`quickReplies`),r=document.getElementById(`headerAvatar`),i=document.getElementById(`headerName`),a=document.getElementById(`clearChatBtn`),o=[{name:`url`,pattern:/https:\/\/[^\s<>"']+/,toAnchor(e){let t=document.createElement(`a`);return t.href=e,t.target=`_blank`,t.rel=`noopener noreferrer`,t.textContent=e,t}},{name:`email`,pattern:/[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,}/,toAnchor(e){let t=document.createElement(`a`);return t.href=`mailto:${e}`,t.textContent=e,t}},{name:`phone`,pattern:/\+\d[\d\s()-]{6,}\d/,toAnchor(e){let t=document.createElement(`a`);return t.href=`tel:${e.replace(/[^\d+]/g,``)}`,t.textContent=e,t}}],s=new RegExp(o.map(e=>`(${e.pattern.source})`).join(`|`),`g`);function c(e){let t=document.createDocumentFragment(),n=0,r;for(s.lastIndex=0;(r=s.exec(e))!==null;){let i=r[0],a=r.index;a>n&&t.appendChild(document.createTextNode(e.slice(n,a)));let s=i.match(/[.,;:!?)\]}'"]+$/),c=``;s&&(c=s[0],i=i.slice(0,-c.length));let l=o[r.slice(1).findIndex(e=>e!==void 0)].toAnchor(i);l.classList.add(`msg-link`),t.appendChild(l),c&&t.appendChild(document.createTextNode(c)),n=a+r[0].length}return n<e.length&&t.appendChild(document.createTextNode(e.slice(n))),t}var l={load(){try{let t=localStorage.getItem(e.storageKey);return t?JSON.parse(t):[]}catch(e){return console.error(`Failed to read chat history from localStorage:`,e),[]}},save(t){try{localStorage.setItem(e.storageKey,JSON.stringify(t))}catch(e){console.error(`Failed to save chat history to localStorage:`,e)}},clear(){try{localStorage.removeItem(e.storageKey)}catch(e){console.error(`Failed to clear chat history from localStorage:`,e)}}},u=[];function d(e){u.push(e),l.save(u)}var f=/^\[\s*(title|icon|heading)\s*:\s*(.*?)\s*\]$/i;function p(e){let t=[],n=[],r=0;for(let i of e)i.trim()===``?(n.length&&(t.push({lines:n,gapBefore:r}),n=[],r=0),r++):n.push(i.trim());return n.length&&t.push({lines:n,gapBefore:r}),t.length?t:[{lines:[`(No answer provided.)`],gapBefore:0}]}function m(e){let t=e.split(/\r?\n/),n=[],r={},i=null;for(let e of t){let t=e.trim().match(f);if(t){r[t[1].toLowerCase()]=t[2].trim();continue}if(e.startsWith(`-`)){i&&n.push(i),i={question:e.slice(1).trim(),answerLines:[]};continue}i&&(e.startsWith(`:`)&&i.answerLines.length===0?i.answerLines.push(e.slice(1).trim()):i.answerLines.push(e))}return i&&n.push(i),{meta:r,entries:n.filter(e=>e.question.length>0).map(e=>({question:e.question,paragraphs:p(e.answerLines)}))}}function h(e){if(e.title&&(document.title=e.title),e.heading&&i&&(i.textContent=e.heading),e.icon){let t=document.querySelector(`link[rel~='icon']`);t||(t=document.createElement(`link`),t.rel=`icon`,document.head.appendChild(t)),t.href=e.icon}}function g(){t.scrollTop=t.scrollHeight}function _(e){let n=document.createElement(`div`);n.className=`msg-row system`;let r=document.createElement(`div`);return r.className=`msg-bubble`,r.textContent=e,n.appendChild(r),t.appendChild(n),g(),n}function v(e){_(e),d({side:`system`,text:e})}function y(e){return typeof e==`string`?{lines:[e],gapBefore:0}:e}function b({side:n,avatarSrc:r,paragraphs:i}){let a=document.createElement(`div`);a.className=`msg-row ${n}`;let o=document.createElement(`img`);o.className=`msg-avatar`,o.src=r,o.alt=n===`bot`?e.botName:`You`;let s=document.createElement(`div`);return s.className=`msg-bubble`,i.forEach((t,n)=>{let{lines:r,gapBefore:i}=y(t),a=document.createElement(`p`);n>0&&i>0&&(a.style.marginTop=`${i*e.paragraphGapUnitPx}px`),r.forEach((e,t)=>{a.appendChild(c(e)),t<r.length-1&&a.appendChild(document.createElement(`br`))}),s.appendChild(a)}),n===`bot`?(a.appendChild(o),a.appendChild(s)):(a.appendChild(s),a.appendChild(o)),t.appendChild(a),g(),a}function x({side:e,avatarSrc:t,paragraphs:n}){let r=b({side:e,avatarSrc:t,paragraphs:n});return d({side:e,paragraphs:n}),r}function S(){let n=document.createElement(`div`);n.className=`msg-row bot`;let r=document.createElement(`img`);r.className=`msg-avatar`,r.src=e.botAvatar,r.alt=e.botName;let i=document.createElement(`div`);return i.className=`msg-bubble`,i.innerHTML=`<span class="typing-dots"><span></span><span></span><span></span></span>`,n.appendChild(r),n.appendChild(i),t.appendChild(n),g(),n}function C(e){if(n.innerHTML=``,!e.length){let e=document.createElement(`div`);e.className=`quick-replies__empty`,e.textContent=`No questions available right now.`,n.appendChild(e);return}e.forEach(e=>{let t=document.createElement(`button`);t.type=`button`,t.className=`quick-reply-chip`,t.textContent=e.question,t.addEventListener(`click`,()=>T(e)),n.appendChild(t)})}function w(e){document.querySelectorAll(`.quick-reply-chip`).forEach(t=>{t.disabled=e})}function T(t){w(!0),x({side:`user`,avatarSrc:e.userAvatar,paragraphs:[t.question]});let n=S();window.setTimeout(()=>{n.remove(),x({side:`bot`,avatarSrc:e.botAvatar,paragraphs:t.paragraphs}),w(!1)},e.typingDelayMs)}function E(){l.clear(),u=[],t.innerHTML=``,k()}a&&a.addEventListener(`click`,E);function D(t){t.forEach(t=>{t.side===`system`?_(t.text):b({side:t.side,avatarSrc:t.side===`bot`?e.botAvatar:e.userAvatar,paragraphs:t.paragraphs})}),u=t}async function O(){try{let t=await fetch(e.dataFile,{cache:`no-store`});if(!t.ok)throw Error(`HTTP ${t.status}`);let{meta:n,entries:r}=m(await t.text());h(n),r.length||v(`${e.dataFile} was loaded but no questions were found. Check the file format.`),C(r)}catch(t){console.error(`Failed to load Q&A data:`,t),v(`Couldn't load ${e.dataFile}`),C([])}}async function k(){let t=l.load();t.length?D(t):x({side:`bot`,avatarSrc:e.botAvatar,paragraphs:[e.greeting]}),await O()}function A(){r.src=e.botAvatar,k()}A();</script>
|
|
13
|
+
<style rel="stylesheet" crossorigin>:root{--border:#e5e7eb;--radius:18px;--font:sans-serif;--text:#e9edef;--text-muted:#65676b;--link:#4db8ff;--bot-bubble:#202c33;--user-bubble:#a61e3c;--user-bubble-text:#e9edef;--chip-bg:#e9edef;--chip-border:#a61e3c;--chip-text:#a61e3c;--chip-bg-hover:#a61e3c;--chip-text-hover:#e9edef}*{box-sizing:border-box}html,body{height:100%;font-family:var(--font);margin:0}body{flex-direction:column;height:100vh;display:flex}.chat-header{border-bottom:3px solid var(--border);background:var(--bot-bubble);flex-shrink:0;align-items:center;gap:10px;padding:12px 16px;display:flex}.chat-header__avatar{background-color:var(--border);border-radius:10px;width:38px;height:38px;padding:6px}.chat-header__name{color:var(--text);font-size:15px;font-weight:600;line-height:1.2}.status{color:var(--text-muted);font-size:12px}.status:before{content:"";background:#31a24c;border-radius:50%;width:7px;height:7px;margin-right:5px;display:inline-block}.clear-chat-btn{border:1px solid var(--text-muted);color:var(--text-muted);font-size:12.5px;font-weight:500;font-family:var(--font);cursor:pointer;border-radius:999px;flex-shrink:0;margin-left:auto;padding:6px 12px;transition:background .15s,color .15s,border-color .15s}.clear-chat-btn:hover{color:#d93025;background:#fdecea;border-color:#d93025}.clear-chat-btn:active{transform:scale(.96)}.chat-window{flex-direction:column;flex:1;gap:4px;padding:16px 12px;display:flex;overflow-y:auto}.msg-row{align-items:flex-end;gap:8px;max-width:100%;margin:2px 0;display:flex}.msg-row.bot{justify-content:flex-start}.msg-row.user{justify-content:flex-end}.msg-avatar{flex-shrink:0;width:28px;height:28px}.msg-bubble{border-radius:var(--radius);white-space:pre-wrap;word-wrap:break-word;max-width:72%;padding:10px 14px;font-size:14.5px;line-height:1.4}.msg-bubble p{margin:0}.msg-bubble p+p{margin-top:8px}.msg-row.bot .msg-bubble{background:var(--bot-bubble);color:var(--text);border-bottom-left-radius:4px}.msg-row.user .msg-bubble{background:var(--user-bubble);color:var(--user-bubble-text);border-bottom-right-radius:4px}.msg-row.system .msg-bubble{color:var(--text-muted);text-align:center;background:0 0;margin:8px auto;font-size:12.5px}a{color:var(--link);text-decoration:underline}.typing-dots{align-items:center;gap:3px;padding:6px 4px;display:inline-flex}.typing-dots span{background:var(--text-muted);opacity:.4;border-radius:50%;width:6px;height:6px;animation:1.2s ease-in-out infinite blink}.typing-dots span:nth-child(2){animation-delay:.2s}.typing-dots span:nth-child(3){animation-delay:.4s}@keyframes blink{0%,80%,to{opacity:.25;transform:translateY(0)}40%{opacity:1;transform:translateY(-2px)}}.quick-replies{border-top:1px solid var(--border);flex-wrap:wrap;flex-shrink:0;gap:8px;max-height:40vh;padding:10px 12px 14px;display:flex;overflow-y:auto}.quick-reply-chip{border:1.5px solid var(--chip-border);background:var(--chip-bg);color:var(--chip-text);cursor:pointer;font-size:13.5px;font-weight:500;font-family:var(--font);border-radius:999px;padding:8px 14px;transition:background .15s,color .15s,transform .1s}.quick-reply-chip:hover{background:var(--chip-bg-hover);color:var(--chip-text-hover)}.quick-reply-chip:active{transform:scale(.96)}.quick-reply-chip:disabled{opacity:.5;cursor:not-allowed}.quick-replies__empty{color:var(--text-muted);padding:4px 6px;font-size:13px}.chat-window::-webkit-scrollbar{width:6px}.quick-replies::-webkit-scrollbar{width:6px}.chat-window::-webkit-scrollbar-thumb{background:#d0d3d8;border-radius:3px}.quick-replies::-webkit-scrollbar-thumb{background:#d0d3d8;border-radius:3px}
|
|
14
|
+
/*$vite$:1*/</style>
|
|
15
|
+
</head>
|
|
16
|
+
<body>
|
|
17
|
+
<header class="chat-header">
|
|
18
|
+
<img class="chat-header__avatar" src="" alt="" id="headerAvatar" />
|
|
19
|
+
<div class="chat-header__meta">
|
|
20
|
+
<div class="chat-header__name" id="headerName">ChatJS</div>
|
|
21
|
+
<div class="status">
|
|
22
|
+
Online
|
|
23
|
+
<a
|
|
24
|
+
href=""
|
|
25
|
+
title="This Chatbot is powered by ChatJS, an open source rule-based chatbot framework offered for free without any strings attached"
|
|
26
|
+
>
|
|
27
|
+
(Powered by ChatJS)
|
|
28
|
+
</a>
|
|
29
|
+
</div>
|
|
30
|
+
</div>
|
|
31
|
+
<button
|
|
32
|
+
type="button"
|
|
33
|
+
id="clearChatBtn"
|
|
34
|
+
class="clear-chat-btn"
|
|
35
|
+
title="Clear chat history"
|
|
36
|
+
>
|
|
37
|
+
Clear chat
|
|
38
|
+
</button>
|
|
39
|
+
</header>
|
|
40
|
+
|
|
41
|
+
<main class="chat-window" id="chatWindow" aria-live="polite"></main>
|
|
42
|
+
|
|
43
|
+
<div
|
|
44
|
+
class="quick-replies"
|
|
45
|
+
id="quickReplies"
|
|
46
|
+
aria-label="Suggested questions"
|
|
47
|
+
></div>
|
|
48
|
+
|
|
49
|
+
</body>
|
|
50
|
+
</html>
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
[title: ChatJS]
|
|
2
|
+
[icon: img/chatjs.svg]
|
|
3
|
+
[Heading: ChatJS Chat]
|
|
4
|
+
|
|
5
|
+
-What's ChatJS?
|
|
6
|
+
:ChatJS is a rule-based chatbot designed to remove API costs and give precise responses. By handling predictable conversations without relying on AI models for every request, ChatJS provides end users with more precise answers while improving performance and lowering operational expenses. This matters for every web and webapps out there because this chat interface gives end users a hope to find the answers related to the certain thing and this rule-based ensures all users get the right answer/s they need.
|
|
7
|
+
|
|
8
|
+
-May I know about your privacy policies
|
|
9
|
+
:We are pretty open about our privacy policies and data practices. We do not log user data to track and profile them, but someone who deploys ChatJS to their websites might go against the data handling practices of ChatJS.
|
|
10
|
+
|
|
11
|
+
-How can I contribute to this project?
|
|
12
|
+
:All contributions are valued. [This is draft]
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
-How can I use ChatJS for my website / webapp
|
|
16
|
+
:To deploy ChatJS to your web/webapp, You do not need to have programming fluency (but having it recommended).
|
|
17
|
+
|
|
18
|
+
[We are still writing it. Please comeback later and ask the question again]
|
|
19
|
+
|
|
20
|
+
-Can you help us setup ChatJS for our website
|
|
21
|
+
:Yes. [Draft :/]
|
|
22
|
+
|
|
23
|
+
-Explain about ChatJS feature.
|
|
24
|
+
: Since ChatJS is a rule-based chatbot, It can offer a plenty of features;
|
|
25
|
+
|
|
26
|
+
1. You just need to put your questions and answers in a text file. ChatJS will handle the rest. Also you can put your desired title, heading and icon image link in file to customise your branding.
|
|
27
|
+
2. It can also pass down clickable links without any additional setup. For example, https://hello.com, https://hello.com/docs, +94 (065) 500 500, +94 065 500 500. +94-065-500-500, info@hello.com, connect@mail.hello.com
|
package/package.json
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "chatjs-free",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "ChatJS is a rule-based chatbot designed to remove API costs and give precise responses with minimal setup.",
|
|
5
|
+
"main": "dist/index.html",
|
|
6
|
+
"files": ["dist"],
|
|
7
|
+
"keywords": ["rule-based chatbot"],
|
|
8
|
+
"license": "MIT",
|
|
9
|
+
"scripts": {
|
|
10
|
+
"build": "vite build",
|
|
11
|
+
"prepublishOnly": "npm run build"
|
|
12
|
+
},
|
|
13
|
+
"devDependencies": {
|
|
14
|
+
"vite": "^5.0.0",
|
|
15
|
+
"vite-plugin-singlefile": "^2.0.0",
|
|
16
|
+
"vite-plugin-static-copy": "^1.0.0"
|
|
17
|
+
}
|
|
18
|
+
}
|