- PHP 78.6%
- JavaScript 17.5%
- CSS 3.5%
- Shell 0.4%
| Filename | Latest commit message | Latest commit date |
|---|---|---|
- Each new conversation keeps the IP address it was sent from, read as the guard reads it (trusted proxies only); schema 8 adds the column, older conversations have none. - History: an IP address column, found by the filter, and the address at the top of a conversation opened in the modal. - Kept for the time set for the history and deleted with the conversation; the suggested privacy text and the README say so. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01PXWEBpMDKaGGdqiqt9PHsq |
||
| assets | ||
| blocks/chat | ||
| languages | ||
| src | ||
| tests | ||
| .gitignore | ||
| CHANGELOG.md | ||
| CLAUDE.md | ||
| LICENSE | ||
| lrob-chatbot.php | ||
| README.md | ||
| release.sh | ||
| uninstall.php | ||
LRob - Chatbot
An assistant for your WordPress site that answers your visitors from your own public content. LRob - Chatbot reads your pages, documentation and blog posts, finds the passage that answers a visitor's question (in their words or in yours, in their language or in yours), and answers in a chat window, with links to the right pages. The answers come from Anthropic's Claude models, with your own API key.
For whom
Site owners, agencies and businesses whose visitors ask the same questions every day ("How much is the Pro plan?", "My IP address is blocked", "How do I set up my mailbox?") and whose answers are already written somewhere on the site, often in a page nobody would guess from its title.
Costs
The API costs are yours. Every answer is billed by Anthropic to your own account (and the optional search by meaning by your embeddings service, to yours): the plugin's author receives nothing and is not responsible for these costs.
- The plugin has spending caps per day and per month (5
and 50by default) and tracks the estimated cost of every answer in Chatbot › Costs. Set the caps when you install it and watch your usage. - These caps rely on estimates (token counts at the prices of the Costs tab) and are not infallible: several answers at the same moment, or prices that change, can take you past them.
- Also set a spend limit in your Anthropic account (Claude Console › Spend limits): that one is binding.
Example
A visitor asks: "Can I host an online shop?"
- No page says "online shop" in its title, but the features page of the Pro plan says it "suits online stores", with its storage and price in a table.
- The keyword search finds the pages that use the same words; the search by meaning finds the Pro section even though the words differ. Both are combined.
- The result is the section itself, not just the page: Hosting › Plans › Pro, with a link to
that part of the page (
/hosting/#pro), its language and the date of its last change.
What it does
The assistant
- A chat window in a corner of every page, or in a page with the Chat block. It follows the visitor from page to page, keeps the conversation for the time you choose, and a visitor can start a new one at any time. Nothing typed is ever lost: the text in progress comes back after a reload, and a message that could not be sent stays in the field.
- Answers as they are written, with what the assistant is doing shown on the way: Searching the site: "Pro plan price"…, Reading the page "Hosting"…, Writing….
- Links to the right pages, and only to them: an answer can link only to pages the assistant actually found on your site (and to addresses you allow, such as your contact page).
- Knows where the visitor is, and when: the page they are on, and the date, day, time and
time zone of your site go with each message, so "this offer" or "this weekend" make sense.
Other plugins can add context (
window.lrobChatbotContext, filterlrob_chatbot_context). - Be contacted: visitors can leave their name, e-mail address, phone number and message in the window, from a discreet button, under an answer when the assistant cannot help, or before chatting. Each request is sent to you by e-mail and kept in the History. Off until you turn it on.
- Notes of your own: facts, stock answers, the tone of the house, written in the Knowledge base (or imported in JSON) for what is not on a page; found like the pages, never shown as links.
- Tools from your other plugins: a calendar plugin can answer "What's on this weekend?" with its events and links to their pages. You turn each tool on in Chatbot › Tools; the visitor sees what it does while it runs, and each call is written in the log.
- Your prompt, your tone: the assistant's name, its personality and rules, its welcome message. The model of your choice, from the list of your Anthropic account.
- Profiles: model, prompt, content searched and spending caps make a profile; a plugin can
choose the profile of each visitor (filter
lrob_chatbot_profile), for example a stronger model for logged-in customers. - Costs under control: the prompt cache of Anthropic's API (the fixed part of the prompt is read from cache, shared by every visitor), a short memory of the conversation, spending caps per day and per month (for the site and per profile), and a Costs tab with what was spent, by model.
- Guards, all of them free and before any paid call: canned answers for "hello" or "thanks", unreadable messages, forbidden phrases (attempts to extract the prompt or misuse the assistant: answered and logged), message length, limits per minute and per hour for each address and for the whole site, a maximum of answers at once. The assistant also tells when a message is off topic or a misuse attempt; too many warnings and the address is blocked for a while, longer at each new block (like fail2ban). Every limit is a setting.
- History: every conversation, with its first page, language, cost, and what was flagged or blocked; kept 30 days by default. No IP address is stored with it.
The search
- Indexes all your public content by itself. Pages, posts, documentation, any public content type you choose. The index updates when you publish, edit, trash or delete; never while a visitor loads a page. No summaries to write, nothing to run by hand.
- Cuts each page into sections at its headings, with their titles and anchors, so that the answer can point to the right part of a long page. Tables (prices, features) stay together.
- Searches by keywords, with the exact words: plan names, error codes (
ERR_SSL_PROTOCOL_ERROR), file names (wp-config.php), short terms (IP, MX, DNS). - Searches by meaning, through any embeddings service that speaks the format of OpenAI's
/v1/embeddings: OpenAI itself, or your own server (a small multilingual model runs on a few processor cores). The vectors stay on your site. - Combines both (reciprocal rank fusion), and keeps a few sections per page so that one long page does not fill the results.
- Knows the language of each section, from your multilingual plugin (Polylang, WPML, LRob - AI Translator) or any plugin through a filter. With TranslatePress, each translated page is indexed in its language at its own address (never ordering a paid machine translation). A question in one language can find a page in another; the search looks in the visitor's language first. One language indexed is enough: when a page found exists in the visitor's language, the answer links to that version.
- Lets you leave content out: a box in the editor, address patterns (
/shop/*), languages. - Measures itself: a benchmark of your own questions scores each configuration (keywords, meaning, combined; one or several embeddings models) and writes a report you can compare over time.
- Keeps a log of its work: each call to the embeddings service (success or failure, time, size), each indexing run, each change of settings.
Installation
- Download
lrob-chatbot-<version>.zipfrom the releases of the repository. - In WordPress: Plugins → Add New → Upload Plugin, choose the zip, activate.
- Go to Chatbot in the administration menu, and follow Start in three steps: your
Anthropic API key (or in
wp-config.php, see Keys), what it reads, where it shows. The site is indexed in the background from then on.
Updates then appear in Dashboard → Updates like any other plugin. If the repository is
private, add a read token to wp-config.php:
define( 'LROB_CHATBOT_UPDATE_TOKEN', 'your-read-only-token' );
Settings
Every setting has a ? beside it that says what it does and why.
- Chatbot: the Anthropic key, the model (with the estimated cost of a conversation), the thinking, the name, welcome message and instructions, how it searches before answering, and the tools of your other plugins.
- Knowledge base: the state of the index (pages read in part, contents that failed), a test search, what is indexed (content types, other sources, languages, addresses left out), the exact-word search, the search by meaning with its vector server, and the tuning of the search.
- Chat window: who sees it, the button, the size, the opening, the colors, the links answers may give, with a live preview of the real window on your home page.
- Protection: limits, blocking, messages to visitors, canned answers, forbidden phrases, blocked addresses.
- Costs: what was spent, the spending caps, the price table.
- History and log: the conversations, the activity log, how long they are kept.
- Server: the display of the answer as it is written (a test sets what works), the compression, the trusted proxies.
The guides, with examples, are in the repository's wiki.
Keys
Put the key in wp-config.php when you can:
define( 'LROB_CHATBOT_ANTHROPIC_KEY', 'your-anthropic-key' );
define( 'LROB_CHATBOT_EMBEDDINGS_KEY', 'your-embeddings-key' );
A key typed in the settings is stored encrypted with the salts of wp-config.php. It is never
shown again and never written to the log.
Privacy
The plugin suggests a text for your privacy policy (Settings → Privacy → Policy guide): what is sent to Anthropic, how long conversations are kept, how the IP address is used, and what the browser keeps. Each conversation is kept with the visitor's IP address it was sent from (shown and searchable in the History), for the time set for the history, and deleted with it. For abuse prevention, the address is also used in a protected form, deleted after a day. Link your terms of use in the Chat window tab: the link shows under the chat. With Be contacted on, the text also says how contact requests are kept, and WordPress's export and erasure of personal data include them (found by e-mail address).
A slow embeddings service
Vectors are computed in the background, a few texts per request, and each run resumes where the last one stopped. After a failure, the next attempt waits 1, 2, 4… minutes, up to 30. A small server may take hours on a large site: the keyword search works from the first minute.
WP-CLI
wp lrob-chatbot profile --name=Robo --prompt-file=prompt.md # set the assistant
wp lrob-chatbot status # index, queue, vectors
wp lrob-chatbot index --all # index everything now, then the vectors
wp lrob-chatbot search "pro plan price" # search as the assistant will
wp lrob-chatbot source translatepress # what a content source gives, and what is left out
wp lrob-chatbot notes import notes/ # add notes from JSON files (list, export too)
wp lrob-chatbot embed --profiles=p.json # compute the vectors of other models
wp lrob-chatbot stores # vector stores on disk
wp lrob-chatbot eval questions.json --profiles=p.json --exact --out=reports/
The benchmark
A questions file:
[
{"question": "Can I host an online shop?", "lang": "en", "expected": ["/hosting/"]},
{"question": "¿Cuánto cuesta el plan Pro?", "lang": "es", "expected": ["/hosting/", 42],
"translations": {"en": "How much is the Pro plan?"}}
]
expected lists the pages that answer: addresses (only the path counts) or post IDs.
A profiles file, to compare embeddings models (a key is never written in it: "key" is
"active", "env:NAME" or "const:NAME"):
[
{"name": "small", "url": "http://192.0.2.10:8080/v1", "model": "multilingual-e5-small",
"query_prefix": "query: ", "passage_prefix": "passage: ", "batch": 8, "timeout": 120},
{"name": "openai", "url": "https://api.openai.com/v1", "model": "text-embedding-3-small",
"dimensions": 512, "key": "env:OPENAI_API_KEY"}
]
Run wp lrob-chatbot embed --profiles=p.json first, then eval. The report gives, for each
configuration (keyword, vector:<profile>, hybrid:<profile>, and vector-exact:<profile>
with --exact): hit@1, hit@5, MRR@10, recall@10 and the time per question; then the rank of the
expected page for each question. --search-lang=en also runs each configuration on the English
version of the questions, on the English sections only. --compare=<earlier report.json> shows
the changes. Both commands ask before calling a service.
For developers
lrob_chatbot_profile(string$profile_id, array$context): the assistant profile of a request ($context:page,title,user_id,extra). Profiles live in the optionlrob_chatbot, keyprofiles; the settings page editsdefault.lrob_chatbot_context(array$lines,WP_REST_Request $request): context lines sent to the model with each message (label → value, 10 at most). A page can setwindow.lrobChatbotContext = { "Area": "Invoices" }; the filter checks or completes it.lrob_chatbot_indexable(bool$indexable,WP_Post $post): include or leave out a post.lrob_chatbot_post_language(string$lang,WP_Post $post): the language of a post.lrob_chatbot_post_translations(array$urls,WP_Post $post): language → address of its translations.lrob_chatbot_sources(array$sources): content that is not made of WordPress posts (documentation served from files, a catalogue…), indexed like the pages. A source gives a paginated list of its documents and the content of one; it announces changes with the actionslrob_chatbot_source_changed,lrob_chatbot_source_removedandlrob_chatbot_source_reset. The contract, with an example: the wiki page Content sources. An item may list itstranslations(language → address), so that answers link to the visitor's language.lrob_chatbot_tools(array$tools): tools the model can call, read only (the dates of a calendar, a stock…): a name, a label, a status for the visitor, a description, a JSON Schema of the parameters and a callback returning text and pages. Off until the administrator turns them on. The contract, with an example: the wiki page Tools.lrob_chatbot_dark_mode(array$markers): how a light/dark plugin marks the mode on<html>(attribute, values, event), for the preview of the chat window.lrob_chatbot_front_changed(string$why): fired when what the chat window shows changes; empty your page cache there.LRobChatbot\Search\Searcher::search( $query, array( 'lang' => 'en', 'limit' => 6 ) ): the search, with address, page title, section title, language, type, date and text of each hit.
Performance
- Pages stay cacheable: the chat asks nothing of the server when a page loads (the conversation is in the visitor's browser), and its script and style are small and versioned.
- An answer streams through one PHP process for a few seconds: Answers at once (3 by
default) keeps visitors from taking every process of the site. Behind nginx, the answer is
sent with
X-Accel-Buffering: noso that it is not held. If a server or proxy holds it anyway, Server › Test the display finds out and turns on a workaround; see the wiki page Answers shown all at once. - Nothing runs while a page is served: indexing and vectors happen in wp-cron, under a lock and a time budget.
- Keyword search: one SQL query (BM25 over the plugin's own word tables).
- Search by meaning: a first pass on one bit per dimension over every section, read 256 sections at a time, then the exact score on the best 200. Measured in PHP on one core: 14 ms for 2,000 sections, 60 ms for 10,000, 0.2 to 0.3 s for 50,000, with less than 4 MB of memory. Nothing stays in memory between requests.
- Editing a page computes the vectors of the sections that changed only.
Security
-
Only published, public content without password is read; nothing from user accounts.
-
The text of pages is read as text: nothing in it is executed, and the administration writes every text it shows as text, never as HTML.
-
The model is told that page content and visitors' messages are data, never instructions; the chat window builds answers with its own small Markdown reader, as text nodes only, and keeps a link only when the server allowed its address.
-
A conversation is answered only to the browser holding its token; messages from another site are refused.
-
The vector files live in
wp-content/uploads/lrob-chatbot-<random>/, refused by an.htaccesson Apache. On nginx alone, add the rule the settings page shows when it detects the files can be downloaded:location ~ ^/wp-content/uploads/lrob-chatbot- { deny all; } -
Keys: see Keys above. Settings and actions require the
manage_optionscapability.
Requirements
- WordPress 6.7 or later, PHP 8.4 or later (8.5 recommended), with the
curl,dom,sodiumandmbstringextensions. - An Anthropic API key for the assistant; an embeddings service for the search by meaning (optional: the keyword search works without it).
- MySQL 8 or MariaDB 10.6 or later.
License
GPL-2.0-or-later. © LRob.
LRob - Chatbot is a free plugin by LRob, WordPress host.