Search by

gunner91 / site-ai-assistant

Gunner91

Drop-in AI chat assistant for any PHP website: answers from your Markdown knowledge base, captures leads to Telegram, works with any OpenAI-compatible model, built-in cost limits. No dependencies.

Package info

github.com/Gunner91/site-ai-assistant

Type:project

pkg:composer/gunner91/site-ai-assistant

Statistics

Installs: 1

Dependents: 0

Suggesters: 0

Stars: 0

Open Issues: 0

v1.0.0 2026-11-26 09:47 UTC

This package is auto-updated.

Last update: 2026-11-26 09:51:10 UTC


README

A drop-in AI chat assistant for any PHP website. It answers visitors from your own Markdown knowledge base, never invents prices or policies, and turns conversations into leads delivered to Telegram (and a local file).

  • No dependencies — plain PHP 8.1+ with cURL, one folder, works on shared hosting.
  • Any OpenAI-compatible model — OpenAI, DeepSeek, OpenRouter, Groq or a local server.
  • Your knowledge, not the internet — answers come from knowledge/*.md, with source links.
  • Lead capture — the model calls a save_lead tool once a visitor leaves a contact.
  • Cost guardrails — daily limits per visitor, total messages and total tokens; a friendly fallback message when they’re hit.
  • Safe by default — origin allow-list, input size limits, no raw IPs stored, widget renders text without innerHTML.
  • Lightweight widget — vanilla JS + CSS, mobile-friendly, dark mode, keyboard accessible.

See it live: the AI assistant on kriatiz.com runs on the same approach. Built by Vladyslav Koshelyev (KRIATIZ).

Install with Composer

composer create-project gunner91/site-ai-assistant my-assistant

Then copy my-assistant/assistant/ to your website and follow the quick start below.

Quick start

  1. Copy the assistant/ folder to your website, e.g. https://example.com/assistant/.
  2. Create the config:
    cp assistant/config.example.php assistant/config.php
    Set api_url, api_key (or the ASSISTANT_API_KEY environment variable), model, business and allowed_origins.
  3. Describe your business in assistant/knowledge/*.md (see the examples). Split topics with ## headings and put url: https://… on the first line so answers link to the right page.
  4. Add the widget before </body>:
    <script src="/assistant/widget.js" defer
      data-title="ACME assistant"
      data-greeting="Hi! Ask me about our services and prices."
      data-suggestions="How much does it cost?|Opening hours|Book a visit"
      data-color="#0e7c66"></script>
  5. Optional: set telegram_token and telegram_chat to receive leads in Telegram.

Open demo.html to try it.

Provider examples

Provider api_url model
OpenAI https://api.openai.com/v1/chat/completions e.g. gpt-4o-mini
DeepSeek https://api.deepseek.com/chat/completions a current DeepSeek chat model
OpenRouter https://openrouter.ai/api/v1/chat/completions any model id, e.g. anthropic/claude-…
Local (Ollama, LM Studio) your server’s /v1/chat/completions URL the local model name

Use extra_body for provider-specific fields. The model must support tool (function) calling for lead capture.

How it works

visitor → widget.js → api.php → keyword search in knowledge/*.md
                              → LLM with system rules + top matches
                              → save_lead tool → Telegram + data/leads.jsonl

Knowledge search is a simple keyword ranking, which works well for small business sites (dozens of pages). For large catalogs, replace sa_search() in lib.php with embeddings or your search engine.

Security notes

  • Keep config.php out of version control (.gitignore already does this) and out of public access.
  • data/ and knowledge/ ship with Apache .htaccess files that deny direct access. On nginx, add equivalent location rules, or move data/ outside the web root and update leads_file.
  • Enable trust_proxy only behind a reverse proxy you control; otherwise X-Forwarded-For can be spoofed.
  • Knowledge files are treated as reference data, and the system prompt tells the model to ignore instructions inside them — still, only put content you control there.
  • Review the limits in config.php before going live: they cap your daily spend.

Customizing

  • Tone and facts: business and tone in config.php.
  • Rules: the system prompt in api.php (e.g. booking flow, languages).
  • Look: CSS variables and classes in widget.css, or data-color on the script tag.

Need it done for you?

I build AI assistants with calendar booking, CRM integration, WhatsApp / Telegram / Instagram channels and analytics for clinics, salons, stores and service businesses: kriatiz.com — AI chatbots · industry solutions.

License

MIT