=== Vago Chat ===
Contributors: biribazu
Tags: live chat, chat widget, customer support, help desk, crm
Requires at least: 6.0
Tested up to: 7.0
Requires PHP: 7.4
Stable tag: 1.0.0
License: GPLv2 or later
License URI: https://www.gnu.org/licenses/gpl-2.0.html

A fast live chat widget with a real-time agent dashboard and FAQ bot — stored in its own SQLite database, not your WordPress database.

== Description ==

Vago Chat adds a front-end chat widget to your site and a real-time
agent dashboard, so you can talk to visitors as they browse — and turn
those conversations into sales.

**Chat & CRM**

* Front-end chat widget with a proactive greeting, quick-reply buttons, emoji picker, and file/image attachments.
* Real-time agent dashboard: conversation list, live visitor monitoring, and one-click invites to visitors currently browsing.
* CRM pipeline per conversation: lead status (new/contacted/qualified/won/lost), assignment to a specific team member, contact info, tags, private notes, and a visitor's previous session history.
* Live typing preview — see what a visitor is typing before they hit send.
* Right-click a conversation to move it to trash, delete it permanently, or block the visitor.

**Automation**

* Canned responses and a keyword-matched FAQ auto-bot that answers common questions instantly and hands off to a human for anything it doesn't recognize.
* Smart proactive triggers: automatically message a visitor after N seconds on a page, based on their traffic source, or once their WooCommerce cart reaches a value you set.

**Sales (WooCommerce)**

* Agents can search your product catalog from the reply box and send a rich product card (photo, price, "Add to cart" button) straight into the chat.
* One-click "Send checkout link" button for visitors who are ready to buy.

**Reports**

* A GA-style Reports view: a trend chart of chats/messages over time, per-agent leaderboard, lead-status and channel breakdowns, average first-response time, and missed-chat count.

**Team & access**

* Grant Vago Chat access to any user without making them a full site administrator (Settings → Members).
* Open the exact same dashboard at a friendly URL outside of wp-admin (Settings → External Access) — logging in there still uses your normal WordPress account, there is no separate login system.
* Appearance settings let you set a brand color once and have it apply to both the dashboard and the widget.

**Channels**

* Optional Telegram integration — connect a bot token and Telegram conversations appear in the same dashboard alongside your website chats. (WhatsApp, Instagram, and Messenger all require a verified Meta Business account for API access and aren't included.)

**Performance & architecture**

* Chat data is stored in a self-contained SQLite database under `wp-content/uploads/vago-chat/` — no additional MySQL tables are created.
* A companion standalone `chat-api.php` endpoint serves the widget and dashboard directly (bypassing `admin-ajax.php`) for lower latency; it authenticates every request with a random token or an origin/referrer check.
* CSS and JS are separate enqueued files (cacheable by the browser), not inline `<style>`/`<script>` blocks.
* Report queries are cached for 60 seconds and SQLite runs `PRAGMA optimize` periodically; a manual "Optimize database" action is available for on-demand `VACUUM`.

= External services =

This plugin uses **ip-api.com** solely to resolve a visitor's IP address to
an approximate city/country, so agents can see where a visitor is chatting
from. Only the visitor's IP address is sent to this service, and the
result is cached for 24 hours to minimize requests.

* Service: [ip-api.com](https://ip-api.com/)
* Data sent: the visitor's IP address
* When: once per visitor per 24 hours, on their first page view
* Terms of service: https://ip-api.com/docs/legal
* This lookup can be disabled by removing the geo lookup call in `includes/api/handlers-visitor.php` (`_ip_geo()`).

If you enable Web Push notifications for new chats, browser push messages
are delivered through your visitors' configured push service (e.g. Google
or Mozilla's push endpoints) using the standard, plugin-generated VAPID
keys — no third-party account or API key is required.

If you opt in to the **Telegram** integration (Settings → Channels) by
entering your own bot token, messages sent by visitors through that
Telegram bot, and your agents' replies, are relayed through Telegram's
Bot API (api.telegram.org) — this only happens if you've supplied a bot
token and clicked "Connect".

* Service: [Telegram Bot API](https://core.telegram.org/bots/api)
* Data sent: message text and the visitor's Telegram chat ID
* When: only when the Telegram integration is connected and in use
* Terms of service: https://telegram.org/tos

== Installation ==

1. Upload the `vago-chat` folder to `/wp-content/plugins/`, or install the zip via Plugins → Add New → Upload Plugin.
2. Activate **Vago Chat** through the 'Plugins' screen in WordPress.
3. A new **Vago Chat** menu item appears in your wp-admin sidebar — open it to set your agent name, avatar, and greeting.
4. The chat widget will automatically appear in the front end of your site.

= Nginx / LiteSpeed: protecting the chat database =

This plugin writes a `.htaccess` file into `wp-content/uploads/vago-chat/`
to block direct access to the SQLite database and every `.json` file there
(settings, generated config, VAPID keys — a `.php` extension is blocked too,
defensively, though nothing in the plugin writes one). Apache and LiteSpeed
(LiteSpeed reads `.htaccess` natively for Apache compatibility) honor this
automatically. **Nginx ignores `.htaccess` entirely** — if your site runs on
Nginx, add a rule like this to your server block so those files stay private:

`
location ^~ /wp-content/uploads/vago-chat/ {
    location ~* \.(db|db-wal|db-shm|json|php)$ { deny all; return 404; }
}
`

The plugin also shows an admin notice automatically when it detects Nginx.

== Frequently Asked Questions ==

= Does this create new database tables? =

No. Conversations, visitors, and messages are stored in a SQLite database
file inside `wp-content/uploads/vago-chat/`, not in your WordPress
(MySQL) database.

= Who can access the chat dashboard? =

Administrators always have access. You can grant access to other users
without making them administrators from Settings → Members — they get a
narrow "Vago Chat Agent" capability, nothing more.

= Can agents use the dashboard without going into wp-admin? =

Yes. Settings → External Access lets you open the same dashboard at a
short URL like `example.com/live-chat-agent/`. Logging in there uses
`wp_signon()` — WordPress's own login function — so it's the same
authentication as wp-admin, just without the wp-admin chrome around it.

= What happens to my data if I uninstall the plugin? =

Deleting the plugin from the Plugins screen removes its settings and the
SQLite chat database/uploaded files. Deactivating the plugin does not
delete anything.

== Screenshots ==

1. Agent dashboard — conversation list and chat panel.
2. Live visitor monitoring with one-click invite.
3. Reports view with trend chart and per-agent breakdown.
4. Front-end chat widget.

== Changelog ==

= 1.0.0 =
* Initial release: real-time chat widget and agent dashboard, live visitor monitoring, smart proactive triggers, a keyword-matched FAQ auto-bot, a CRM pipeline with agent routing, WooCommerce sales quick-actions, a real-time Reports control center, Members/Blocklist management, an external agent portal, and an optional Telegram channel.
