AI · Open source · · Trevor Heshka
How I built HeshBot, the AI assistant on this site
HeshBot replaced a third-party chat widget on trevorheshka.com. It's a dependency-free JavaScript widget and a single PHP 7.4 endpoint that calls Google Gemini, grounded in this site's public pages.
Why build my own
The site used a third-party Typebot widget that loaded about 164 KB from a CDN. I wanted a chat assistant that runs on my own hosting, answers from my own content, and loads nothing until someone asks for it.
The widget
- Vanilla JavaScript and CSS with no dependencies
- A small launcher bubble; the widget script and styles load only on the first click
- Keyboard and screen-reader support: a dialog with a live log, Esc to close, focus returned to the launcher
- Full-screen on phones and styled to match the site's dark theme
- A markdown-lite renderer that escapes the model's output first, then allows a small whitelist of formatting and safe links
- The conversation is kept in sessionStorage, so it lasts for the current tab only
The backend
- One PHP 7.4 file using curl to call the Gemini REST API, because that's what the cPanel/LiteSpeed host runs
- The API key lives in a config file outside public_html (or an environment variable), never in the repo
- It tries a list of Gemini flash models in order and falls back on errors, with a friendly “email Trevor” message when the free quota runs out
- Per-IP file-based rate limiting, message length and history caps, a same-origin check and JSON errors
- An .htaccess file makes chat.php the only reachable file in the API folder
Grounding
A Python script reads the site's public pages (home, about, AI, projects, services and the landing pages) and writes a knowledge file. The system prompt tells HeshBot to answer only from that file, to say it doesn't know otherwise, and to point people to email. When the site changes, I rerun the script.
Testing
I tested it locally on Apache with PHP, checked the PHP against 7.4 compatibility rules, mocked the Gemini call when no key was present, and took desktop and mobile screenshots in headless Chrome before going live.
Source
HeshBot is MIT-licensed: github.com/YardPhantom/HeshBot. More detail is on the project page.