gunner91 / site-ai-assistant
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
Requires
- php: >=8.1
- ext-curl: *
- ext-json: *
Requires (Dev)
None
Suggests
None
Provides
None
Conflicts
None
Replaces
None
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_leadtool 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
- Copy the
assistant/folder to your website, e.g.https://example.com/assistant/. - Create the config:
cp assistant/config.example.php assistant/config.php
Setapi_url,api_key(or theASSISTANT_API_KEYenvironment variable),model,businessandallowed_origins. - Describe your business in
assistant/knowledge/*.md(see the examples). Split topics with##headings and puturl: https://…on the first line so answers link to the right page. - 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>
- Optional: set
telegram_tokenandtelegram_chatto 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.phpout of version control (.gitignorealready does this) and out of public access. data/andknowledge/ship with Apache.htaccessfiles that deny direct access. On nginx, add equivalentlocationrules, or movedata/outside the web root and updateleads_file.- Enable
trust_proxyonly behind a reverse proxy you control; otherwiseX-Forwarded-Forcan 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.phpbefore going live: they cap your daily spend.
Customizing
- Tone and facts:
businessandtoneinconfig.php. - Rules: the system prompt in
api.php(e.g. booking flow, languages). - Look: CSS variables and classes in
widget.css, ordata-coloron 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.