=== Agentsia Agents ===
Contributors: thomasservais
Tags: chatbot, ai, conversational agent, booking, lead generation
Requires at least: 5.8
Tested up to: 7.0
Requires PHP: 7.4
Stable tag: 1.5.0
License: GPLv2 or later
License URI: https://www.gnu.org/licenses/gpl-2.0.html

Easily add your Agentsia AI agents (web chatbot, appointment booking, demo funnel) to your WordPress site.

== Description ==

Agentsia Agents connects your WordPress site to your Agentsia application (app.agentsia.fr). In a few minutes you can:

* Display the Agentsia **chatbot** as a floating bubble across the whole site, as a modal, or full-page inside a post.
* Embed a public **appointment booking form** on any page.
* Add a **call-to-action button** that links to your demo funnel.
* Let your Agentsia **SEO agent** update the SEO title, meta description, noindex and canonical URL of your pages, in the fields of your SEO plugin (Yoast SEO, Rank Math, SEOPress, All in One SEO, The SEO Framework), fix the alternative text of their images, and edit one section of a page without rewriting it, including the text custom fields (ACF) of pages that keep their text there. Without any SEO plugin, Agentsia Agents prints these tags itself.

Three integration methods are available: global settings, shortcodes and Gutenberg blocks.

This plugin is a client for the external Agentsia service and requires an Agentsia account. See the "External services" section below for details about the data exchanged.

= Shortcodes =

* `[agentsia_chatbot]` — Full-page chatbot (configurable via attributes).
* `[agentsia_chatbot mode="bubble"]` — Force the floating bubble from a specific page.
* `[agentsia_chatbot scenario="sos" context_hint="AC emergency page"]` — Scenario + page context.
* `[agentsia_chatbot hide_bubble="1"]` — Hide the bubble, open via JavaScript.
* `[agentsia_booking]` — Booking form using the default calendar slug.
* `[agentsia_booking slug="sales-demo" height="780"]`
* `[agentsia_demo label="Book my demo"]` — Button linking to `/demo`.
* `[agentsia_derniers_articles nombre="3" titre="Derniers articles" categorie="" auteur=""]`: latest published posts of a category (slug or ID) or of an author (ID or login). Without category nor author, on a page: the category whose slug is the page's slug (page `/advisor/jane-doe/` and category `jane-doe`); nothing is shown when there is none.

= Gutenberg blocks =

* **Agentsia Chatbot**
* **Agentsia Booking**
* **Agentsia Demo button**
* **Derniers articles** (latest posts, same settings as the shortcode)

== External services ==

This plugin is a connector for the **Agentsia** service (operated by Agentsia, https://agentsia.fr). It only works with an Agentsia account and communicates with the services described below. By installing and configuring this plugin, you — and your site visitors — exchange data with these services.

= 1. Agentsia application — https://app.agentsia.fr =

* **From your WordPress server (admin)**: when you save the settings and to populate the dropdowns, the plugin calls `https://app.agentsia.fr/api/public/wp/me`, `/api/public/wp/chatbots` and `/api/public/wp/booking-calendars`. Data sent: your Agentsia API key (Authorization header) and your site URL (User-Agent header). Data received: your account name, the list of your chatbots and your calendars.
* **From your visitors' browser**: the chat widget script is loaded from `https://app.agentsia.fr/chatbot/embed.js`; the appointment booking form is displayed in an iframe `https://app.agentsia.fr/book/<slug>`; the "demo" button is a plain link to `https://app.agentsia.fr/demo`.

= 2. Agentsia agent backend — https://agent-backend-production-311267441656.europe-west1.run.app =

* **From your visitors' browser**: once the chat widget is loaded, the messages typed by your visitors (and the optional page context) are sent to this service to generate the AI agent's replies. No data is sent until a visitor opens and uses the chat.

= 3. One-click connection (« Connect to Agentsia » button) =

* **From the administrator's browser**: the button opens `https://app.agentsia.fr/connect/wordpress` with your site address, its REST address and a random one-time value; you log in to Agentsia there and choose a workspace, then come back to your site with a one-time code.
* **From your WordPress server**: the plugin creates a dedicated user « Agentsia » with a limited role (posts, pages, media) and an Application Password for it, then sends to `https://app.agentsia.fr/api/public/wp/connect` the one-time code, your site and REST addresses, a random site identifier, the dedicated user's login and Application Password, and your administrator user ID (default author of articles). Agentsia calls your site back once (`/wp-json/agentsia/v1/environment`) to check the site holds that password, stores it encrypted, and returns the workspace API key.
* **Afterwards**, the Agentsia SEO agent uses that dedicated user to read and update your content through the WordPress REST API and the plugin's routes. « Disconnect » revokes the Application Password and tells `https://app.agentsia.fr/api/public/wp/disconnect`.

No data is transmitted until the plugin has been configured with a valid API key or connected with the button (server side), or the chatbot has been loaded and used (visitor side).

* Terms of use: https://www.agentsia.fr/conditions-dutilisation/
* Privacy policy: https://www.agentsia.fr/privacy-policy/

**Important (GDPR)**: the chatbot sends your visitors' messages to a third-party service. Mention this in your site's privacy policy and, where applicable, obtain the required consent (cookie / consent banner).

== Installation ==

1. Upload the `agentsia-agents` folder to `/wp-content/plugins/`.
2. Activate the plugin from the WordPress "Plugins" page.
3. Generate an API key in your Agentsia account: **My account › API keys › New key**. Copy the key (`agsk_…`) — it is shown only once.
4. Open **Settings › Agentsia Agents** and paste the key into the "API key" field. Save.
5. Select the default chatbot and calendar from the dropdowns (populated automatically from your account).
6. Enable (or not) the global bubble loading, then save again.
7. Use the shortcodes or Gutenberg blocks in your pages.

== Frequently Asked Questions ==

= Where do I get my API key? =

Sign in to app.agentsia.fr, then open **My account › API keys** and click "New key". Give it a descriptive name (e.g. "WordPress site agentsia.fr"). The full key is shown only once — copy it into WordPress immediately.

= What if my key is lost or compromised? =

From **My account › API keys** on app.agentsia.fr, revoke the existing key and create a new one. Paste the new key into the WordPress plugin. Integrations using the old key will stop working immediately.

= Does it work with Divi / Elementor / Avada? =

Yes. The shortcodes work in any text module. The Gutenberg blocks work in the native WordPress editor.

= Can I disable the chatbot on specific pages? =

Yes. On the settings page, enter the paths to exclude (one per line).

= The chatbot / calendar list is empty, why? =

Make sure your API key is valid (a "Connected" badge appears at the top of the settings page). If it is valid but no chatbot is listed, create one from your Agentsia dashboard. The plugin caches the lists for 5 minutes.

== Changelog ==

= 1.5.0 =
* New: **Custom fields (ACF) in targeted edits** — when ACF is active, the `agentsia/v1/content` route also lists a page's text fields (text, textarea, WYSIWYG) as editable items (`f:<name>`, at the end of the list), and the `set_field` operation changes their text in the same request as the other edits. A page with no content of its own, whose text lives in its fields (one page per advisor in a network, for example), can be edited the same way, whether it is built with the block editor, the classic editor or Elementor.
* Contact details and identity are never listed: a field whose name or label refers to a phone, email, address, website, link, social network, photo, logo, name, first name, SIRET, SIREN, RSAC or professional card stays out of Agentsia's reach. Two filters adjust the list on a site: `agentsia_content_excluded_field_patterns` (excluded words) and `agentsia_content_field_units` (offered fields).
* Rollback: `restore_fields` puts back the previous value of a field, only for a value Agentsia itself replaced (the last 20 per field).
* New: **Latest posts** — `[agentsia_derniers_articles]` shortcode and « Derniers articles » block: the latest published posts of a category (`categorie`, slug or ID) or an author (`auteur`, ID or login), 3 by default and 10 at most (`nombre`), with an adjustable heading (`titre`). With neither category nor author, it uses the category that has the same slug as the page (page `/conseiller/jean-dupont/` and category `jean-dupont`); nothing is shown when there is none.
* Fix: targeted edits refused every blog post as a « shared template » on themes that have both a PHP `single.php` and a block `index.html` template. The plugin now picks the same template as WordPress: a theme's PHP template wins over a less specific block template.

= 1.4.0 =
* New: **One-click connection** — « Connect to Agentsia » sends the administrator to log in to Agentsia and pick a workspace; the site is linked without copying any API key or password. A dedicated « Agentsia » user is created with a limited role (posts, pages and media only: never users, plugins, themes or settings); « Disconnect » revokes its access.
* New: **SEO title, meta description, noindex and canonical URL** — REST route `agentsia/v1/seo-meta` (Application Password, `edit_post` capability) so the Agentsia SEO agent reads and writes them in the active SEO plugin (Yoast SEO, Rank Math, SEOPress, All in One SEO, The SEO Framework), or prints them itself when no SEO plugin is active.
* New: **Targeted page edits** — REST route `agentsia/v1/content` lists the sections of a page (blocks, classic content split at its headings, Elementor Heading and Text editor widgets) and changes, adds or removes one without rewriting the page or touching its layout. Refuses Divi/WPBakery pages. Every write checks the page did not change since it was read.
* New: targeted edits reach the blocks nested in groups, columns and covers (theme patterns): change the words of a paragraph or heading while keeping its style, insert inside a section, duplicate an FAQ question with new texts. Layout blocks and their settings are never modified.
* New: block themes: the home page, the archive of a post type or a page built in the Site Editor can be edited too (its template, like the Site Editor does; templates shared by several pages are refused). `replace_text` puts a link on words already in a text (internal linking) without rewriting it.
* New: **Structured data (JSON-LD)** — the SEO agent sends an article's JSON-LD through `agentsia/v1/seo-meta` (`schema_jsonld`); the plugin validates it, stores it with the post and prints it in `<head>`. It no longer goes into the post content, where WordPress stripped the `<script>` tag for the dedicated Agentsia user and showed the JSON as text.
* New: **Image alternative text** — REST route `agentsia/v1/images` lists the images of a page and fixes their alt text, both in the media library and in the page content (where the editor copies it). Requires WordPress 6.2+.

= 1.3.0 =
* Integration IndexNow et resize des calendriers

= 1.2.0 =
* New: **Auto-resize du formulaire de rendez-vous** — l'iframe `[agentsia_booking]` (shortcode et bloc) ajuste automatiquement sa hauteur au contenu via postMessage (formulaire rempli, questions supplémentaires, calendrier, confirmation). L'attribut `height` ne sert plus que de hauteur initiale — plus de zone vide ni de scroll interne.

= 1.1.0 =
* New: **Custom open/close trigger** — bind any page element (CSS selector) to toggle the chatbot, with automatic grey-out or hide while the assistant is unavailable.
* New: **Default scenario** at the global level — applies a named scenario (defined in the chatbot config on the Agentsia side) on all public pages.
* New: **Hide bubble** at the global level — hides the floating bubble and only opens the chatbot via `window.agentsia.open()`.
* New: **Extended shortcode** — `scenario`, `context_hint`, `hide_bubble` available on `[agentsia_chatbot]`.
* New: Documentation of the JavaScript methods `setWelcomeMessage`, `setQuickReplies`, `setTeaserMessage`, `setAutoOpenDelay`, `setScenario`, `setContext`, `setAppearance`, `apply()`.

= 1.0.0 =
* First public release.
* Personal API key authentication (generated from app.agentsia.fr).
* Chatbot and calendar selection via dropdowns (automatic sync from the Agentsia account).
* Global chatbot (bubble, modal, full-page).
* Shortcodes and Gutenberg blocks for chatbot, booking and demo button.
* Complete settings page (API, appearance, exclusions).
