=== Maktomine AI Agent ===
Contributors: maktomine
Tags: ai, chatbot, openai, claude, gemini
Requires at least: 6.5
Tested up to: 7.1
Requires PHP: 8.1
Stable tag: 1.3.0
License: GPLv2 or later
License URI: https://www.gnu.org/licenses/gpl-2.0.html

AI chat assistant that answers visitors from your own business knowledge, captures leads with consent, and hands off to WhatsApp.

== Description ==

Maktomine AI Agent adds an AI chat assistant to your WordPress site. It answers visitor questions using the business information you provide — pages, posts, FAQs and notes — rather than guessing.

* **Multiple assistants** — each with its own name, personality, language, instructions, model and branding.
* **Knowledge base** — add text and FAQs, or import pages and posts (kept in sync automatically). Each assistant only uses its own knowledge.
* **Chat widget** — floating chat button or inline chat box via shortcode `[maktomine_ai_agent id="1"]` or the "Maktomine AI Agent" block. Mobile friendly, no external scripts.
* **Lead capture** — "Leave your details" form with explicit consent, email notifications and CSV export.
* **WhatsApp handoff** — let visitors continue the conversation with your team.
* **Dashboard & analytics** — conversations, leads, token usage, estimated cost and most-asked questions.
* **Privacy controls** — configurable data retention, privacy notice, and full data removal on uninstall.

Bring your own AI: use the AI providers you connected in WordPress 7.0+ (Settings → Connectors), or connect OpenAI, Anthropic Claude, Google Gemini, or any OpenAI-compatible API (OpenRouter, Groq, DeepSeek, Mistral, a local Ollama…). Each assistant can use a different provider and model, and AI usage is billed by the provider directly to your account.

== External services ==

To generate answers, this plugin sends requests to the AI provider(s) that the site administrator chooses and configures with their own API key. Nothing is sent to any provider until an administrator saves a key (or, for the OpenAI-compatible option, a base URL). Only the provider selected for an assistant receives that assistant's traffic.

What is sent and when:

* When a visitor sends a chat message: the message, recent messages from the same conversation, the assistant's instructions, and the business knowledge sections relevant to the question.
* When an administrator clicks "Save & test" or "Load models": a short test prompt, or a request for the list of available models.
* The visitor's IP address, name, email and phone number are **not** sent to any AI provider. Lead form details stay in your WordPress database.

Supported providers:

* **WordPress AI (Settings → Connectors)** — on WordPress 7.0 and later, the plugin can use the WordPress AI Client (`wp_ai_client_prompt()`). Requests then go to whichever provider the site owner connected under Settings → Connectors, under that provider's terms and privacy policy. This plugin stores no API key in that case.
* **OpenAI** — `https://api.openai.com/` (Responses API; requests are sent with `store: false`). [Terms of use](https://openai.com/policies/row-terms-of-use/), [Privacy policy](https://openai.com/policies/privacy-policy/).
* **Anthropic (Claude)** — `https://api.anthropic.com/`. [Commercial terms](https://www.anthropic.com/legal/commercial-terms), [Privacy policy](https://www.anthropic.com/legal/privacy).
* **Google Gemini** — `https://generativelanguage.googleapis.com/`. [Gemini API terms](https://ai.google.dev/gemini-api/terms), [Google Privacy Policy](https://policies.google.com/privacy).
* **OpenAI-compatible endpoint** — any URL the administrator enters (for example OpenRouter, Groq, DeepSeek, Mistral, xAI, Together, Perplexity, or a self-hosted Ollama server). The data listed above is sent to that URL under that service's own terms and privacy policy. When the URL is OpenRouter (`openrouter.ai`), the site's name and home URL are also sent, as OpenRouter's optional app-attribution headers. [OpenRouter Terms](https://openrouter.ai/terms), [OpenRouter Privacy](https://openrouter.ai/privacy).

The WhatsApp button (optional) is a plain link to `https://wa.me/` that opens WhatsApp only when the visitor clicks it. No data is sent to WhatsApp by the plugin. [WhatsApp Terms](https://www.whatsapp.com/legal/terms-of-service), [WhatsApp Privacy Policy](https://www.whatsapp.com/legal/privacy-policy).

== Privacy ==

API keys are stored encrypted with your site's secret keys. The plugin stores, in your own database: conversations and messages, leads submitted with consent, token usage, and anonymous analytics events. Visitors are identified only by a salted hash of their IP address (for rate limiting) and a random session token stored in their browser's localStorage. Conversations are deleted automatically after the retention period you choose (default 90 days). Please mention the use of an AI service in your site's privacy policy.

== Installation ==

1. Upload the plugin and activate it.
2. Go to **Maktomine AI → API & Settings**, add an API key for the AI provider you want to use, pick a model and click "Save & test".
3. Create an assistant in **Maktomine AI → AI Assistants**.
4. Add knowledge in **Maktomine AI → Knowledge Base**.
5. Tick "Show as floating chat on every page", or embed it with the shortcode or block.

== Frequently Asked Questions ==

= Can I use the AI providers I connected in WordPress? =

Yes. On WordPress 7.0 or later, choose **WordPress AI (Settings → Connectors)** in **API & Settings**. The assistant then uses the providers you connected in WordPress itself, and no separate API key is needed in this plugin.

= How much does it cost to run? =

The plugin is free. AI replies are billed by the provider you connect, to your own account, per "token" (roughly ¾ of a word). A typical chat answer uses a few hundred to a few thousand tokens, so for most small sites the monthly cost is low — but it depends on the model and your traffic. The dashboard shows exact token counts; enter your provider's prices in **API & Settings** to see estimated costs.

= How do I keep AI costs under control? =

* Choose a smaller, cheaper model (for example a "mini", "flash", "lite" or "haiku" model).
* Lower **Knowledge per answer** and **Conversation memory** in **API & Settings** to send fewer tokens.
* Keep the **Daily AI reply limit** (default 1,000 replies per day) and the per-visitor rate limit switched on.
* Set a spending limit in your provider's billing settings as well.

= Which AI provider should I choose? =

Any of them works. Each assistant can use a different provider and model, so you can start with one and switch later without losing your knowledge base, conversations or leads.

= Is visitor data sent to the AI provider? =

Only the visitor's chat messages, the assistant's instructions and the relevant knowledge snippets — never IP addresses, or the name, email or phone from the lead form. See **External services** above.

= Is my API key visible to visitors? =

No. The browser only talks to your WordPress site; the key is used server-side only, is never output in page HTML or REST responses, and is stored encrypted in the database.

= Does it work with page builders? =

Yes. Use the shortcode in any builder's shortcode widget (including Elementor).

= Which languages are supported? =

Set the assistant language to "auto" to reply in the visitor's language, or list languages such as "English and Bangla".

== Screenshots ==

1. Floating chat widget answering a visitor from the business knowledge base, with "Leave your details" and WhatsApp buttons.
2. Assistant builder: identity, instructions, AI provider and model, leads and WhatsApp handoff.
3. Appearance options: brand colours, chat button colours and position (any corner).
4. API & Settings: choose an AI provider from a dropdown and connect it with your own API key.
5. Knowledge base: add text and FAQs, import pages and posts, and test what the assistant will find.
6. Dashboard with conversations, leads, AI usage and most-asked questions.
7. Leads list with status tracking and CSV export.

== Changelog ==

= 1.3.0 =
* New AI provider option: WordPress AI (Settings → Connectors) via the WordPress 7.0+ AI Client.
* All database queries now use prepared statements with %i identifier placeholders.

= 1.2.1 =
* OpenRouter attribution headers are now only sent to OpenRouter.
* Readme: screenshots, cost FAQ.

= 1.2.0 =
* API keys are now stored encrypted (libsodium) with a key derived from your site's wp-config.php secret keys; existing keys are encrypted automatically.
* Leads are deleted automatically after 365 days by default (configurable in API & Settings).

= 1.1.2 =
* Separate colours for the chat button (background and icon) and for visitor message bubbles, e.g. a light chat button for a dark brand.
* Fix: the chat button and send button now always use their configured colours.

= 1.1.1 =
* Chat button can be placed in any corner: bottom right, bottom left, top right or top left.
* AI provider is now chosen from a dropdown on API & Settings.

= 1.1.0 =
* Choose any AI provider: OpenAI, Anthropic Claude, Google Gemini or any OpenAI-compatible API, per assistant.
* Live model lists, per-provider reasoning effort and cost estimates.
* Plugin prefix renamed to "mkagent" (existing data is migrated automatically).
* Security hardening and a daily AI reply limit.

= 1.0.0 =
* Initial release.
