=== Embott ===
Contributors: websenorpub
Tags: ai chat, chatbot, woocommerce, livechat, lead generation
Requires at least: 5.8
Tested up to: 7.0
Stable tag: 1.0.3
Requires PHP: 7.4
WC requires at least: 6.0
WC tested up to: 9.5
License: GPLv2 or later
License URI: https://www.gnu.org/licenses/gpl-2.0.html

AI sales agent that talks to your visitors, qualifies leads, recovers carts, and books calls — 24/7. Deep WooCommerce integration.

== Description ==

**Embott** is an AI-powered sales agent for your WordPress site. It's not a clunky FAQ chatbot — it's trained on your products, your tone, and your offers, and it actively works to turn visitors into customers.

= What it does =

* **Greets** every visitor based on the page they're on (product page, cart, blog post, etc.)
* **Qualifies leads** using proven sales frameworks (SPIN, Challenger, Sandler) instead of scripted Q&A
* **Captures contact info** with smart validation that catches fake details
* **Recovers carts** — when a visitor adds to cart and idles, Embott checks in, answers objections, and can issue a one-time discount code
* **Books calls** — straight into your calendar
* **Live-agent handoff** — when the bot can't help, your team is notified and can take over the conversation in real time
* **Speaks 30+ languages** automatically (including Hindi/Hinglish for Indian stores)
* **Routes traffic** — sales goes to your dashboard, HR/spam is auto-replied or silently blocked to save credits

= Deep WooCommerce integration =

* Auto-syncs your **product catalog** (creates, updates, deletes, variants, stock)
* **Order attribution** — every sale is matched back to the conversation that produced it
* **Coupon generation** — the bot can issue WooCommerce discount codes through your dashboard's playbooks
* **Personalisation** — passes the logged-in customer's email, name, and cart so the bot picks up where they left off
* **Page-aware** — knows whether the visitor is on a product page, cart, checkout, or thank-you page

= Why merchants pick Embott =

* Installs in 60 seconds — paste a site key and you're live
* No theme code edits
* Backed by Anthropic's Claude — the same model thousands of enterprise teams trust
* Built-in dashboard, leads inbox, analytics, canned replies, tags, notes
* Mobile-first widget that looks beautiful on every store

== Installation ==

= 1. Get your site key =

1. Create an account at https://embott.com/signup (free trial — no card needed).
2. Complete the short onboarding (site URL, bot name, tone of voice). Embott will crawl your site automatically.
3. Open **Dashboard → Install** and copy your site key (it starts with `ck_`).

= 2. Install this plugin =

**Option A — Upload (recommended):**

1. Download `embott.zip` from your Embott dashboard.
2. In WordPress: **Plugins → Add New → Upload Plugin** → choose the zip → **Install Now**.
3. Click **Activate**.

**Option B — From WP-admin (when listed on WordPress.org):**

1. **Plugins → Add New** → search for "Embott".
2. **Install Now** → **Activate**.

= 3. Connect =

1. Open **Embott → Settings** in wp-admin.
2. Paste your site key into the **Site key** field.
3. **Save changes**.

The chat launcher appears in the bottom corner of every page on your site. Visit any page in an incognito tab to confirm.

== Frequently Asked Questions ==

= Does this work without WooCommerce? =

Yes. Embott works on any WordPress site as a general chat / lead-capture widget. WooCommerce is optional — when it's active, you also get product sync, order attribution, and coupon generation.

= Where is the chat data stored? =

In your Embott workspace at api.embott.com. Conversation history, leads, and analytics live there. We never write your customers' personal data to your WordPress database (apart from the WooCommerce order meta `_embott_tracked` to prevent double-attribution).

= Will it slow down my site? =

No. The widget script is loaded with `async` so it never blocks page rendering. It's a single small file served from `api.embott.com` over HTTP/2 with edge caching.

= Can I customise where the widget appears? =

Yes:

* **Embott → Settings → Hide on pages** — enter slugs like `checkout, my-account, thank-you`.
* Programmatic control via the `embott_should_show` filter.
* Add or override data-* attributes via the `embott_widget_data` filter.

= Can the bot create coupons automatically? =

Yes — when your playbook fires a discount, Embott's backend calls your site's `POST /wp-json/embott/v1/coupon` endpoint with the site key. The plugin creates a real WooCommerce coupon (one-time use, configurable expiry).

= How do I do a bulk product re-sync? =

Run `wp embott resync` from your terminal (requires WP-CLI). This pushes every published product to the Embott catalog.

= GDPR / privacy =

* Embott is GDPR-compliant. You can delete a visitor's data from your dashboard at any time.
* Toggle **Embott → Settings → Personalise for logged-in customers** OFF if you don't want to pass logged-in users' email / name to the bot automatically.

= Support =

* Docs: https://embott.com/docs
* Email: support@embott.com

== Screenshots ==

1. The Embott settings page in wp-admin — paste your site key and go.
2. WooCommerce panel — product sync and order attribution toggles.
3. Live chat launcher on a WooCommerce storefront.
4. Embott dashboard — leads, conversations, analytics.

== External services ==

This plugin relies on the Embott AI Sales Agent service, operated by WebSenor Private Limited. To use Embott, you create a free Embott account at https://embott.com and paste the resulting site key into the plugin's settings page. **The plugin sends no data to any third party until you paste a site key and click Save changes.**

Once activated, the plugin communicates with the Embott API at `https://api.embott.com` for the following purposes:

**Loading the chat widget script:** Each storefront page loads `https://api.embott.com/widget.js` (as a regular `<script async>` tag) so visitors can chat with the AI agent. This call is made by your storefront visitor's browser, not by your WordPress server.
- Data sent: site key, current page URL, page type, locale, optional WooCommerce cart state, optional logged-in customer ID / email / name (only if "Personalise for logged-in customers" is enabled).
- Provider's terms of service: https://embott.com/privacy
- Provider's privacy policy: https://embott.com/privacy

**Product sync (WooCommerce only):** When a product is created, updated, or deleted, the plugin sends the product details to `https://api.embott.com/widget/sync-product` so the bot's knowledge base stays in sync.
- Data sent: site key, product ID, title, description, price, image URL, inventory, category, tags, variants.
- This is opt-in — disabled by unchecking "Sync products" in Embott settings.

**Order attribution (WooCommerce only):** When an order is placed or completes, the plugin sends the order summary to `https://api.embott.com/widget/track-order` so the merchant can see which conversations produced sales.
- Data sent: site key, order ID, total, currency, billing email / phone / name, discount codes used, line items.
- This is opt-in — disabled by unchecking "Track orders" in Embott settings.

**Coupon creation:** The Embott backend calls back into your site at `https://yoursite.com/wp-json/embott/v1/coupon` (authenticated with your site key + HMAC) when the bot's playbook needs to generate a single-use WooCommerce coupon for a visitor.
- Data sent: code, discount type, amount, expiry. No personal data flows in this direction.

All communication is over HTTPS. The Embott service stores conversations and leads in encrypted Postgres in DigitalOcean's EU and US regions. Full terms and privacy policy are at https://embott.com/privacy.

== Privacy ==

* The plugin does not phone home or send any data until a site key is saved.
* The plugin does not place cookies on the merchant's site directly. The widget script sets one first-party cookie, `chatry_visitor`, to remember a visitor across page loads within a chat session.
* No tracking pixels, no third-party advertising network.
* Merchants can disable all WooCommerce data flow with one click ("Sync products" / "Track orders" / "Personalise for logged-in customers" toggles).
* On uninstall, every plugin option is removed from the database (see `uninstall.php`).

== Changelog ==

= 1.0.3 =
* Critical fix: WC product detail pages could 500 when the global `$product` was a string (post slug) instead of a `WC_Product` object — calling `->get_id()` on it fataled. Now validates with `is_object` + `method_exists` before use, and wraps every field extraction in try/catch with error_log.
* `register_widget()`, `context_attrs()`, the cart block, and the product-category block are now all wrapped end-to-end so no unexpected fault on a future WP/WC release can take a storefront page down.
* `wp_register_script()` strategy-array now gated behind a WP 6.3+ feature check (falls back to legacy in_footer boolean on older WP).

= 1.0.2 =
* Hardened boot path: every class constructor, the plugins_loaded init, the activation hook, the HPOS compat call, and uninstall.php now run inside try/catch with error_log so an isolated fault can never bring down the host site.
* Explicit PHP < 7.4 guard: bail with admin notice instead of fataling.
* Explicit WooCommerce version guard (>= 6.0) before booting the WC bridge.
* Defensive WP-CLI registration — survives partial WP-CLI shims.
* Class file requires now wrapped + missing-file fallback.

= 1.0.1 =
* Critical fix: default backend URL pointed at non-existent api.embott.com, causing 15 s blocking calls on every product save and checkout. Now points to embott.com and auto-heals existing installs on first load.
* All WooCommerce sync calls switched to non-blocking (`wp_remote_request` with `blocking: false`) so checkout pages can never be held up by a slow backend.
* Sync timeout reduced from 15 s → 3 s as a belt-and-suspenders safety net.

= 1.0.0 =
* First public release.
* Universal widget injection with rich WooCommerce data-* context (page-type, product, collection, cart, customer).
* Product sync on create / update / delete / variation / stock change.
* Order attribution on `woocommerce_thankyou` and status transitions.
* Coupon creation REST endpoint (site-key + HMAC verified).
* Polished admin UI matching the embott.com dashboard.
* WP-CLI command: `wp embott resync` for bulk product re-sync.
* HPOS (custom order tables) compatibility declared.

== Upgrade Notice ==

= 1.0.3 =
Critical reliability fix — eliminates a 500 error on WooCommerce product detail pages caused by a string-vs-object check in the widget context builder. Strongly recommended for all installs.

= 1.0.2 =
Critical reliability update. Strongly recommended for all installs — eliminates the silent-activation-failure pattern and makes the plugin incapable of taking down a host site under any boot-path fault.

= 1.0.1 =
Critical fix — eliminates 15 s checkout hangs caused by a misconfigured default backend URL. Upgrade ASAP.

= 1.0.0 =
First public release.
