=== Holy Grail Chatbot ===
Contributors: holygrailapp
Tags: chatbot, ai assistant, conversational ai, woocommerce, product recommendations
Requires at least: 5.9
Tested up to: 7.1
Requires PHP: 8.0
Stable tag: 1.2.2
License: GPLv2 or later
License URI: https://www.gnu.org/licenses/gpl-2.0.html

Smart AI chat assistant for WordPress: adds the Holy Grail chatbot and keeps its knowledge in sync as you edit content - set up in minutes.

== Description ==

**Holy Grail Chatbot** adds a smart, conversational AI assistant to your WordPress site and keeps its knowledge in sync as your content changes — without touching your theme.

Connect your site to the [Holy Grail](https://my.holygrail.app) platform by entering your Agent-ID, and the chatbot is injected on the front end automatically. Whenever you create, update, or delete a monitored post, page, or product, the plugin sends a webhook to Holy Grail so the matching page is re-crawled and your assistant answers with your latest content.

= What you get =

* **Setup in minutes.** Paste your Agent-ID, save, done — the chatbot appears on your site.
* **Talks like a human.** Powered by leading LLMs, trained on *your* content in the Holy Grail platform.
* **Real-time knowledge sync.** Every create/update/delete on a monitored post type fires a webhook so Holy Grail re-crawls just that page. No more stale replies.
* **You choose what syncs.** Select exactly which public post types (posts, pages, products, custom types) trigger a webhook.
* **Production and Staging.** Switch the whole integration between your live and test Holy Grail environments with one setting.
* **Visibility control.** Show the chatbot to all visitors, or restrict it to logged-in users only.
* **Multilingual ready.** Assign a different Holy Grail agent per language on WPML, Polylang, or TranslatePress sites.
* **Secure by design.** Requests are authenticated with an `X-Team-Api-Key` header; API keys are masked in the debug log.
* **Built-in debug log.** Capture webhook requests/responses in a filterable, paginated log, then clear it in one click.

= Product recommendations =

If your site exposes product data, the assistant can recommend the right items as a visual product slider inside the conversation — with image, title, and price — helping reduce cart abandonment and lift conversions. Select the product post type to keep it in sync.

= Use cases =

* **E-commerce stores:** AI shopping assistant that recommends products from your synced catalog and guides shoppers to checkout.
* **Service businesses:** Answers FAQs and qualifies leads while you focus on the work.
* **Membership sites:** Guides members to the right content, courses, or resources based on what they ask.

= External service =

This plugin relies on [Holy Grail](https://www.holygrail.app), a third-party AI service, and will not function without a Holy Grail account. Two kinds of communication take place:

* **Chatbot widget.** When an Agent-ID is configured, the chatbot script is loaded on your front end from `static.holygrail.app` and the conversation runs against the Holy Grail service. Visitor messages typed into the chatbot are sent to Holy Grail to generate a reply. No chatbot script is loaded and no data is sent when no Agent-ID is set.
* **Content sync.** When a Webhook Endpoint is configured, the plugin sends the public URL of a post, page, or product to Holy Grail whenever you create, update, or delete one of the post types you selected, so that Holy Grail can re-crawl that page. The request body contains the page URL and the action (`created_or_updated` or `delete`) -- no post content and no user data. When you configure an Authorization Token, it is sent with the request as an `X-Team-Api-Key` header so Holy Grail can identify your account. No webhook is sent when no endpoint is configured.

Requests are sent to the environment you select in the settings: `my.holygrail.app` (Production) or `staging.my.holygrail.app` (Staging).

By using this plugin you are subject to Holy Grail's [Terms of Service](https://www.holygrail.app/tos/) and [Privacy Policy](https://www.holygrail.app/privacy-policy/).

= Requirements =

You'll need a Holy Grail account. [Create one for free](https://my.holygrail.app) — setup takes about 5 minutes. The plugin is also available from your Holy Grail dashboard.

== Installation ==

1. Install and activate the plugin — from the WordPress plugin directory (Plugins > Add New, search "Holy Grail Chatbot") or by uploading the ZIP from your [Holy Grail dashboard](https://my.holygrail.app).
2. Go to Settings > Holy Grail Chatbot.
3. Under **Environment**, choose **Production**; use **Staging** for testing.
4. Under **Chatbot Installation**, paste your **Agent-ID** and set **Visibility** (all visitors, or logged-in users only). Optionally add **Custom url parameters** and **Allowed Link Sources**. On multilingual sites, use **Agent ID Mappings** to assign a different agent per language.
5. Under **Webhook Request**, enter your **Webhook Endpoint** and **Authorization Token** to enable content sync.
6. Under **Supported Post Types**, tick the **Post Types to Monitor** (posts, pages, products, custom types).
7. Click **Save Changes**, then open your site — the chatbot appears in the bottom-right corner.

Enable **Debug Logging** to inspect webhook traffic during setup, then turn it off when you're done.

== Frequently Asked Questions ==

= Do I need a Holy Grail account? =

Yes. The chatbot and webhook sync both require a Holy Grail AI account. You can sign up at [my.holygrail.app](https://my.holygrail.app).

= Which post types trigger webhooks? =

Any public post type — posts, pages, WooCommerce products, or custom post types. You pick which ones in the settings. Revisions and autosaves are always ignored.

= Does this slow down my site? =

No. The chatbot script loads asynchronously from a CDN. Webhooks fire server-side on the `shutdown` hook, after WordPress has already sent the page to the visitor.

= I use WPML / Polylang / TranslatePress. Does this work? =

Yes. The plugin auto-detects your multilingual setup and lets you assign per-language Agent IDs. Webhook URLs resolve in each post's language, not the admin panel's language.

= Can I restrict the chatbot to logged-in users? =

Yes. There's a visibility setting in the admin panel. You can also use the `holy_grail_chatbot_user_authenticated` filter for custom logic.

= How do I check if webhooks are working? =

Enable Debug Logging in the settings. Every webhook request and response gets logged with status codes and payloads. Use the filters to narrow down specific operations, then clear the log when you're done.

= What happens when I bulk-trash posts? =

The plugin batches the URLs and sends them in a single request (up to 100 URLs per chunk) instead of firing one webhook per post.

== Screenshots ==

1. AI-powered shopping assistant — the chatbot answering product questions inside a WooCommerce store.
2. Plugin settings — Agent ID, Webhook Endpoint, Authorization Token, post type selection, and debug logging.
3. Product discovery — the chatbot showing product recommendations with images and prices.

== Changelog ==

= 1.2.2 =
* Settings page styles and scripts are now loaded as separate files instead of being printed into the page, following WordPress.org plugin directory requirements.
* Removed a duplicate "Settings saved." message on the settings screen.
* No functional changes.

= 1.2.1 =
* Raised the minimum PHP version to 8.0. The plugin has only ever been tested against PHP 8.0 and above; the previous 7.4 declaration was never verified. Sites on PHP 7.4 or older will no longer be offered the update.
* Raised the minimum WordPress version to 5.9, in line with the PHP 8.0 requirement. WordPress 5.6-5.8 are long past end of life and are not tested against.
* Tested against WordPress 7.1.
* Prepared for listing on the WordPress.org plugin directory.
* No functional changes.

= 1.2.0 =
* The chatbot embed placed by this plugin now carries a `data-channel="wordpress"` attribute. Previously the markup was identical to the snippet copied by hand from the Holy Grail backend, so the platform could not tell where a widget request came from and switching the WordPress channel off had no effect. No configuration change is needed.

= 1.1.0 =
* Added an optional "Custom url parameters" field (Settings -> Holy Grail Chatbot -> Chatbot Installation). Enter a query string like `button_type=square&width=80&height=40&radius=10` and it is appended to the chatbot script URL. A single free-text field means new widget options need no plugin update. The value is validated on save and malformed input is rejected, keeping the previous value.

= 1.0.0 =
* First stable release, rolled out to client sites.
* No code changes from 0.4.2.

= 0.4.2 =
* Added `holy_grail_chatbot_is_visible` filter so themes and plugins can check whether the chatbot will render.
* Fixed webhook URLs resolving in the wrong language on multilingual sites (WPML).
* Fixed duplicate webhooks from cascading saves (WPML translation sync, page builders).

= 0.4.1 =
* Consolidated magazine issue REST API into a single `GET /holy-grail/v1/issues` endpoint with optional `week`/`year` parameters.

= 0.4.0 =
* Per-language Agent ID mappings for multilingual sites (WPML, Polylang, TranslatePress).
* Auto-detection of active multilingual plugin with language dropdown in settings.
* Fallback chain: language mapping, then single Agent ID, then suppress chatbot.

= 0.3.14 =
* Added "Allowed Domains" setting for chatbot link references.

= 0.3.13 =
* Bulk webhook support — admin bulk actions send one batched request instead of one per post.

= 0.3.12 =
* Rebranded to "Holy Grail Chatbot" across all labels and documentation.
* Renamed settings fields: Agent-ID, Webhook Endpoint, Authorization Token.

= 0.3.11 =
* Updated staging chatbot script URL.

= 0.3.10 =
* Renamed authentication header to X-Team-Api-Key.

= 0.3.8 =
* Added chatbot visibility setting (all visitors or logged-in only).
* Added `holy_grail_chatbot_user_authenticated` filter.

= 0.3.7 =
* Added Production/Staging environment toggle.
* API keys masked in debug log entries.
* Database index on debug log operation column.
* Per-request settings caching.

= 0.3.6 =
* Removed Basic settings mode and custom headers.
* Refactored permalink handling and post eligibility into dedicated classes.

= 0.3.5 =
* Added chatbot embed via Agent ID — loads automatically on the front end.
* Reorganized settings into sections.

= 0.3.4 =
* Rebranded user-facing labels to "Holy Grail Chatbot".
* Added Plugins list Settings shortcut and German translation.

= 0.3.3 =
* Database-backed debug log with filtering, pagination, and clear button.
* Delete webhooks reuse the same permalink as create/update events.

= 0.3.2 =
* Fixed vendor directory issue.

= 0.3.1 =
* Bundled Composer dependencies for immediate use after download.

= 0.3.0 =
* Grouped settings sections and payload handling improvements.

= 0.2.0 =
* Block delete webhooks for posts not in a public status.

= 0.1.0 =
* Initial release with webhook dispatching, settings page, and debug logging.
