=== Mersal Assistant ===
Contributors: mersal
Tags: ai, chatbot, assistant, woocommerce, search, support, knowledge base
Requires at least: 6.0
Tested up to: 6.6
Requires PHP: 7.4
Stable tag: 1.0.0
License: GPLv2 or later
License URI: https://www.gnu.org/licenses/gpl-2.0.html

A live AI assistant and smart product search for WordPress & WooCommerce: knowledge base, RAG answering, in-chat actions, and 10 integrations.

== Description ==

Mersal Assistant turns your site content and WooCommerce catalog into a knowledgeable AI assistant. It answers visitor questions from your own content (Retrieval-Augmented Generation), powers a semantic product search, performs real actions during chats (order lookup, lead capture, coupons, and more), and connects to your favourite tools.

**Highlights**

* Pixel-faithful admin dashboard (Overview, Conversations, Knowledge Base, Actions, Integrations, Team & Roles, Settings).
* Configurable OpenAI-compatible LLM provider (OpenAI, Azure OpenAI, OpenRouter, Groq, local servers).
* Self-contained vector knowledge base stored in your own database (MySQL + PHP cosine similarity) — no external vector DB required.
* Front-end chat widget + `[mersal_search]` smart-search shortcode.
* Nine assistant actions exposed to the model as tools.
* Ten integrations: WooCommerce, WhatsApp, Messenger, Slack, Zapier, Google Calendar, HubSpot, Mailchimp, Stripe, Intercom.
* Privacy-first: PII masking, GDPR consent, configurable retention, allowed-domains, profanity filter.

== Installation ==

1. Upload the `mersal-assistant` folder to `/wp-content/plugins/`, or install the ZIP via Plugins → Add New → Upload.
2. Activate **Mersal Assistant** through the Plugins menu.
3. Open **Mersal** in the admin sidebar.
4. Go to **Settings → AI & Model** and enter your OpenAI-compatible API base URL and API key.
5. Go to **Knowledge Base → Add source** and index your site content (WordPress content, sitemap, crawl, files, or WooCommerce products).
6. (Optional) Connect integrations under **Integrations**, and place `[mersal_search]` on any page.

= Loading as an unpacked plugin =

No build step is required. The admin UI and front-end widget are hand-written vanilla JavaScript (CSP-safe), so the plugin runs as-is once copied into `/wp-content/plugins/`.

== Configuration prerequisites for integrations ==

Some providers require you to create an app and supply credentials in the Connect dialog:

* **WhatsApp / Messenger:** a Meta app with the Cloud API / Pages webhook. Use the webhook URLs shown in the Connect dialog and your chosen verify token.
* **Google Calendar:** an OAuth client (Client ID/Secret). Add the shown redirect URI to your Google Cloud console.
* **Slack / HubSpot / Intercom / Mailchimp / Stripe:** a bot token / private-app token / API key.
* **Zapier:** a "Catch Hook" URL.
* **WooCommerce:** no credentials — connects natively when WooCommerce is active.

== Frequently Asked Questions ==

= Does it work without WooCommerce? =
Yes. WooCommerce is optional; product/order/stock actions activate automatically when WooCommerce is present.

= Where is my data stored? =
All conversations, leads, and knowledge embeddings are stored in your own WordPress database. Credentials are encrypted at rest. Only the messages you send to your configured LLM provider leave your server.

= Is it accessible / CSP-safe? =
The UI uses no inline scripts and no `eval`. All dynamic content is rendered via DOM text nodes, preventing XSS.

== Manual test checklist ==

Activation & teardown
* Activate the plugin: tables `wp_mersal_*` are created; no PHP notices with `WP_DEBUG` on.
* Deactivate: scheduled events are cleared; data is preserved.
* Uninstall (delete): tables, options, transients and capabilities are removed.

Admin dashboard
* Each sidebar item renders its screen; the active item is highlighted.
* Toggle any switch / segmented control — a "Saved" toast appears and the value persists after reload.
* Overview shows real counts (zeros on a fresh install) with correct empty states.
* Add a knowledge source; it appears in the table and indexing is queued.
* Re-sync and delete a source work.
* Open the Action config drawer; coupon shows extra rules; Save closes it.
* Open the Connect dialog for an integration; submitting credentials connects or shows a clear error.
* Settings → AI & Model: saving the API key shows "(saved)" on reload and never returns the key.

Front-end
* The launcher appears in the configured position; opening it shows the welcome message.
* With GDPR enabled, the consent gate appears before chatting.
* Sending a message returns an answer (or the fallback if the provider is unconfigured); sources and follow-ups render.
* `[mersal_search]` renders the styled field; typing returns product cards (with WooCommerce active).

Security
* Calling `/wp-json/mersal/v1/chat` without a valid nonce returns 403.
* Rapid repeated requests return 429 (rate limited).
* Restricting allowed domains blocks requests from other origins.

== Changelog ==

= 1.0.0 =
* Initial release: admin dashboard, knowledge base + vector search, RAG chat engine, front-end widget, smart-search shortcode, 9 actions, 10 integrations, notifications, retention.

== Upgrade Notice ==

= 1.0.0 =
First public release.
