=== Agentency Chatbot ===
Contributors: agentency
Tags: chatbot, ai, live chat, customer support, chat widget
Requires at least: 6.3
Tested up to: 7.1
Requires PHP: 7.4
Stable tag: 1.4.0
License: GPLv2 or later
License URI: https://www.gnu.org/licenses/gpl-2.0.html

Add your Agentency AI chatbot to your WordPress or WooCommerce site. Connect with a personal access token, pick an agent, done.

== Description ==

Agentency Chatbot puts your trained AI support agent on every page of your site.

This plugin is a connector for the Agentency service. You train an agent on your own content in your Agentency account, then this plugin embeds it on your WordPress site and keeps the connection in sync — including registering your domain so the widget is allowed to load.

**An Agentency account is required.** The plugin does nothing on its own.

= What it does =

* Connects to your Agentency account with a personal access token you create yourself
* Lists your agents and lets you pick which one appears on this site
* Registers your site's domain automatically, so the widget is not blocked
* Controls where the launcher sits, how big it is, and whether it opens on its own
* Optionally forces the chat into one language — for sites that run in a language the agent does not
* Optionally tells Agentency the display name of logged-in WordPress users, so your conversations list shows who you are talking to
* Optionally shares page context — the page title, URL, meta description, main heading and an excerpt of the main content — so the agent can answer questions about the page a visitor is on
* Hides the widget on specific pages, or everywhere, with one setting

= Works with WooCommerce =

WooCommerce runs on WordPress, so the same plugin covers your storefront. No extra setup.

= Privacy and the external service =

This plugin relies on the Agentency service, on two hosts:

* `https://api.agentency.com` — the Agentency API. Your WordPress server talks to it (configurable if you self-host), and visitors' browsers send chat messages to it.
* `https://agentency.com` — serves the chat widget script, `https://agentency.com/js/chatbot-widget.js`.

**From your server.** When you connect, the plugin sends your personal access token, your site URL and the plugin version, and receives your list of agents plus a public widget token. While connected it repeats a check-in (installation id and plugin version) on an interval Agentency sets — once a day by default, never more often than hourly or less often than weekly. Every one of these requests identifies itself with the plugin version and your site URL in its User-Agent header.

**From your visitors' browsers.** While connected, every page view on your public site loads the widget script from `https://agentency.com` and the agent's widget settings from `https://api.agentency.com`, so those hosts see the visitor's IP address, browser user agent and your site's address (the referrer is limited to your site's origin), whether or not the visitor opens the chat. When a visitor chats, their messages are sent to Agentency to be answered. If you enable the "Logged-in visitors" option, the WordPress display name and user ID of signed-in users are included so you can identify them in your conversations list. That option is off by default.

If you enable the "Page context" option, each chat message also carries the current page's title, its address without the query string or hash, its meta description, its first heading and an excerpt of its main content (navigation, header, footer, sidebar and hidden content are skipped), so the agent can tell what "this page" means. That option is off by default.

Your personal access token is stored in your site's database, encrypted with a key derived from the secret keys in your wp-config.php, so a copy of the database alone does not reveal it. Anyone who can read both the database and wp-config.php can still recover it, and if those secret keys change the token can no longer be read and you connect again. It is never displayed again after you save it, never sent to the browser, and is deleted when you disconnect or delete the plugin.

Please review these before installing:

* Terms of service: https://agentency.com/terms
* Privacy policy: https://agentency.com/privacy

== Installation ==

1. Install and activate the plugin.
2. In your Agentency dashboard, go to Developers → Tokens and create a personal access token with only the `widget:manage` scope. (An API key from the Keys tab, starting with `agy_`, does not work here.)
3. In WordPress, go to Settings → Agentency Chatbot and paste the token.
4. Choose which agent to show, and save.

The chatbot appears on your site immediately.

== Frequently Asked Questions ==

= Do I need an Agentency account? =

Yes. This plugin connects an existing account to your site; it is not a standalone chatbot.

= Why does it ask for an access token instead of a password? =

So the credential can be narrow. A personal access token with only the `widget:manage` scope can install the widget and manage the site domains allowed to load it — nothing else. It cannot read your knowledge base, change your agents, or see your billing. If your site is ever compromised, the token is not a route into your account, and you can revoke it in Agentency at any time.

= Will it slow my site down? =

The plugin adds one deferred script tag, loaded from `https://agentency.com`, to every page of your public site. Nothing is loaded in the admin, and the chat interface itself loads only when a visitor opens it.

= Can I use my own button instead of the floating bubble? =

Yes. Turn on "Hide the floating bubble", then add `data-agentency-open` to any element on your site.

= My site is in a different language than my agent. Can the chat match my site? =

Yes. By default the chat window follows the language you set for the agent in Agentency. Choose a "Widget language" in the plugin settings to force the chat window, its built-in replies and the welcome message into that language instead. Per-language welcome and fallback messages are written in your Agentency dashboard under the agent's Messages settings.

= Can I hide the chatbot on certain pages? =

Enter the page or post IDs in "Hide on these pages". For anything more complex, use the `agentency_chatbot_should_render` filter.

= I self-host Agentency. Does that work? =

Yes. On the connect step, open "Advanced" and enter your instance's API URL before you click Connect, so the token is only ever sent to your own server. The URL must start with `https://` (plain `http://` is accepted only for `localhost`). WordPress refuses requests to private and loopback addresses by default; a local development setup needs core's `http_request_host_is_external` filter (and `http_allowed_safe_ports` for a port other than 80, 443 or 8080).

= I disconnected the site in my Agentency dashboard. What happens here? =

At its next check-in the plugin learns that the site was removed, stops showing the chatbot and shows a notice with a Reconnect button on the Dashboard, Plugins and plugin settings screens.

= Where do I get support? =

The setup guide is at https://agentency.com/integrations/wordpress and the help centre at https://agentency.com/help. If you are still stuck, contact the Agentency team at https://agentency.com/contact. When you write in, include the "Agentency Chatbot" section from Tools → Site Health → Info — it lists the plugin version, connection and last check-in, and never your access token.

== Screenshots ==

1. Connect this site to your Agentency account with a personal access token you create yourself, with a direct link to where you create it.
2. Choose which of your agents appears on this site.
3. Once connected: status, last check-in, and the display rules, including widget language and page context.

== Changelog ==

= 1.4.0 =
* The connect step now asks for a personal access token and links to Developers → Tokens in Agentency with the `widget:manage` scope preselected. Pasting an `agy_` API key says what to create instead of failing with a bare error.
* Self-hosted and staging instances: the API URL can be set on the connect step (under Advanced), so the token is never sent to Agentency's own API first.
* The API URL must start with `https://` (`http://` only for `localhost`); requests no longer follow redirects or reach private addresses, and the settings screen says when the token goes anywhere but Agentency. A previously saved URL that does not meet this rule stops all requests until it is corrected or cleared.
* The access token is now stored encrypted in the database; existing tokens are encrypted the next time the settings screen opens or the site checks in. Site Health reports how the token is stored.
* When the site is disconnected from the Agentency dashboard, the plugin stops showing the chatbot at its next check-in and offers a one-click Reconnect.
* Deactivating the plugin now stops its scheduled check-in (on every site of a network when network-deactivated); settings and the connection are kept.
* "Hide on these pages" no longer hides the widget on a category, tag or author archive that happens to share an excluded page's ID.
* The agent picker lists up to 200 agents and says when an account has more.
* The privacy section now names the widget's host and says what each page view sends.

= 1.3.0 =
* Disconnecting a live site now asks for confirmation first, and "Use a different API key" no longer looks like a delete button.
* The connect step links straight to Settings → Developer in Agentency, where the API key is created.
* Messages after saving no longer travel in the page address, so they show once and cannot be forged by a link.
* The "not connected yet" reminder appears only on the Dashboard and Plugins screens, and "Don't show this again" hides it for good.
* The settings screen says when the last check-in attempt failed, instead of leaving "Last check-in" to go stale silently.
* New "Agentency Chatbot" section in Tools → Site Health → Info for support requests (no API key included).
* Documentation and Support links on the Plugins screen.
* Deleting the plugin on a multisite network now cleans up every site.
* Translation fixes: time phrases and the connection status read naturally in every language. Arabic translation updated.
* The Plugins screen now lists the plugin as "Agentency Chatbot", the name its settings screen already used.

= 1.2.0 =
* Widget updates now reach your site on their own: the plugin always loads Agentency's stable widget address, and connections made before this version that stored a build-pinned address are switched over automatically — no reconnect needed.
* New optional "Page context" setting (off by default): each chat message can carry the current page's title, address, meta description, main heading and an excerpt of its main content, so the agent can answer questions about the page a visitor is on.
* The check-in that shows "last check-in" now follows the interval Agentency sends (between 1 hour and 7 days) instead of a fixed daily schedule.
* The "Widget language" setting offers four more languages: Turkish, Russian, Korean and Vietnamese.
* Arabic translation updated for the new settings.

= 1.1.0 =
* New "Widget language" setting: force the chat window, its built-in replies and the welcome message into one language instead of the agent's default. Per-language welcome and fallback texts come from the agent's Messages settings in Agentency.
* The embed script tag now always states the choice (`data-language="default"` when you have not picked one), matching the snippets the Agentency dashboard generates.

= 1.0.0 =
* First release.

== Upgrade Notice ==

= 1.4.0 =
Security update: the access token is encrypted at rest and only sent to an https:// API URL. If you set a custom API URL, check it after updating. The chatbot now goes away when you disconnect the site in Agentency.

= 1.3.0 =
Settings screen polish: a confirmation before Disconnect, failed check-ins shown, a Site Health section and a reminder you can turn off. Nothing changes on your public pages.

= 1.2.0 =
Widget updates now arrive without a reconnect, and an optional "Page context" setting is available. Nothing changes on your pages until you turn Page context on.

= 1.1.0 =
Adds the optional "Widget language" setting. Nothing changes until you pick a language; existing sites keep following the agent's own language.

= 1.0.0 =
First release.
