Skip to content

andookg/agentic-chat-widget

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

10 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

✦ AgenticChat Widget

A zero-API, zero-backend AI chat widget for any website.
No LLM. No API key. No server. Just drop in two files.

License: MIT Zero Dependencies Vanilla JS Made by Opcelerate


A gift from Opcelerate Neural to the world. 🎁
Free. Forever. MIT licensed. Use it, fork it, ship it β€” no strings attached.


✨ What it does

  • 🧠 Pattern-based AI β€” answers questions from your knowledge base in milliseconds
  • πŸ’¬ Chat history β€” saves & browses past conversations via localStorage (like ChatGPT)
  • πŸ“ Page-aware greetings β€” knows which page the visitor is on and tailors its opener
  • ⚑ Proactive engagement β€” bounces after a configurable delay to invite interaction
  • πŸ“‹ Lead capture β€” offers a name/email form after N messages (hooks to any webhook)
  • πŸ“± Mobile-friendly β€” full-width bottom sheet on mobile, floating panel on desktop
  • πŸ”Œ LLM upgrade path β€” swap one function to add Gemini/GPT when you're ready

πŸš€ Quick start

1. Copy the files into your project:

your-website/
β”œβ”€β”€ widget.js
β”œβ”€β”€ widget.css
└── avatar.png   ← optional, use any square image

2. Add to your HTML:

<!-- In <head> -->
<link rel="stylesheet" href="widget.css" />

<!-- Before </body> -->
<script>
  window.AgenticChatConfig = {
    name:          'Aria',          // Widget name
    role:          'AI Assistant',  // Subtitle
    avatar:        'avatar.png',    // Your avatar image
    brand:         '#6c63ff',       // Primary brand color
    brandDark:     '#4b44cc',       // Darker gradient shade
    brandLight:    '#8b85ff',       // Lighter gradient shade
    bg:            '#0f172a',       // Panel background
    proactiveSec:  8,               // Proactive bounce delay (0 = off)
    leadNudgeAfter: 5,              // Lead form after N messages (0 = off)
    footerNote:    'Aria is an AI β€” for specific help, contact our team.',
  };
</script>
<script src="widget.js" defer></script>

3. Edit the knowledge base inside widget.js:

const KB = {
  services: {
    patterns: [/what do you (do|offer)|services?/i],
    responses: ['We help businesses with...'],
    chips: ['Learn more', 'Pricing', 'Contact us']
  },
  pricing: {
    patterns: [/price|cost|fee|how much/i],
    responses: ['Our plans start at $X/month...'],
    chips: ['Get a quote', 'Talk to sales']
  },
  // ... add as many intents as you like
};

That's it. No build step. No npm. No account.


πŸ“‹ Configuration options

Key Type Default Description
name string 'Sage' Widget display name
role string 'AI Assistant' Subtitle in header
avatar string '' Path to avatar image (falls back to ✦)
brand string '#6c63ff' Primary brand color
brandDark string '#4b44cc' Darker gradient shade
brandLight string '#8b85ff' Lighter gradient shade
bg string '#0f172a' Panel background color
proactiveSec number 8 Seconds before proactive bounce; 0 = disabled
leadNudgeAfter number 5 Messages before showing lead form; 0 = disabled
footerNote string '...' Small disclaimer text at panel bottom

🧠 Knowledge base structure

const KB = {
  intentName: {
    patterns:  [/regex/i],                    // RegExp array to match user input
    responses: ['Response string'],           // Picked at random
    chips:     ['Quick reply 1', '...'],      // Optional quick-reply buttons
    navigate:  'page.html',                   // Optional "Take me there" link
    handler:   (text) => 'dynamic response',  // Optional: overrides responses
  },
  fallback: {
    // No patterns β€” always fires if nothing else matches
    responses: ['I\'m not sure, but our team can help!'],
  }
};

Tips:

  • Order intents specific β†’ general (first match wins)
  • Cover synonyms: /price|cost|fee|how much|charge/i
  • Anchor greetings: /^(hi|hello|hey)/i

πŸ“‹ Intent categories to cover

Intent Patterns to include
Greeting hi, hello, hey, good morning
Services what do you do, offerings, help with
Pricing price, cost, fee, how much
About who are you, about you, background
Contact contact, reach, email, call, support
Location office, where, city, address
Get started sign up, begin, how do I start
FAQ how does it work, explain
Farewell bye, thanks, that's all

πŸ”Œ LLM upgrade path

The regex approach handles ~95% of conversations. When you need full NLU:

// Replace classifyIntent() + getResponse() with:
async function askAI(text) {
  const res = await fetch('/api/chat', {
    method: 'POST',
    headers: { 'Content-Type': 'application/json' },
    body: JSON.stringify({ message: text, page: window.location.pathname })
  });
  const { reply } = await res.json();
  return reply;
}

Add a serverless function (Netlify, Vercel, Cloudflare Worker) β€” all the UI stays identical.

Approach Monthly Cost Intelligence
AgenticChat (regex) $0 Pattern matching
+ Gemini 2.0 Flash ~$5–20 True NLU
+ GPT-4o-mini ~$5–30 True NLU
Intercom / Drift $400–$1,000+ Rules-based SaaS

πŸ“ File structure

agentic-chat-widget/
β”œβ”€β”€ widget.js        ← Core widget (KB + engine + UI)
β”œβ”€β”€ widget.css       ← All styles
β”œβ”€β”€ index.html       ← Live demo / landing page
β”œβ”€β”€ avatar.png       ← Replace with your own
└── README.md

πŸ›  Inject into all pages automatically

python3 << 'PY'
import glob

WIDGET = '<script src="widget.js" defer></script>'

for page in glob.glob('*.html'):
    with open(page, 'r') as f: content = f.read()
    if 'widget.js' in content: print(f'SKIP {page}'); continue
    content = content.replace('</body>', f'  {WIDGET}\n</body>', 1)
    with open(page, 'w') as f: f.write(content)
    print(f'OK   {page}')
PY

πŸ“„ License

MIT β€” free for personal and commercial use. No attribution required.


🎁 A gift from Opcelerate Neural

AgenticChat is Opcelerate's open-source contribution to the developer community.

Opcelerate Neural builds Industrial AI and Agentic AI solutions β€” from predictive analytics to full agentic software platforms. This widget is our gift to every developer building on the web.

β†’ opcelerateneural.ca


⭐ Support

If this helped your project, a GitHub star means everything. 🌟
Bug reports and PRs are very welcome.

About

Embeddable zero-API AI chat widget with pattern-matching intent engine.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors