=== AI CRM Nepal - Chat Capture ===
Contributors: krishnamishra8848
Tags: crm, whatsapp, lead capture, contact, sales
Requires at least: 6.8
Tested up to: 7.1
Requires PHP: 8.3
Stable tag: 0.2.0
License: GPLv2 or later
License URI: https://www.gnu.org/licenses/gpl-2.0.html

Capture a visitor phone in AI CRM Nepal before opening your business WhatsApp chat. Lightweight popup, +977 default and daily connection health.

== Description ==

Connect your WordPress website to an AI CRM Nepal workspace. A visitor opens a popup, shares a phone number and continues to your configured WhatsApp number only after CRM acknowledges the enquiry.

* Phone only, with editable +977 visitor country code by default.
* Business destination, message, button text, position and privacy link settings.
* Floating button, [aicrm_whatsapp] shortcode and opt-in aicrm-whatsapp-trigger CSS class.
* Existing CRM contact details remain unchanged; enquiries are attached privately.
* Local vanilla JavaScript/CSS. No remote frontend SDK, tracking pixels or background polling.
* Capture-only key encrypted in the WordPress database using your auth salt. Never put this key into page builders.
* Daily signed read-only connection health in CRM. Health does not submit test leads or send messages.

An AI CRM Nepal account and an active workspace connection are required. The external CRM service may have usage limits or paid plans. Plugin code is fully available under GPLv2 or later. The plugin does not send WhatsApp messages automatically and does not use the WhatsApp Business API. WhatsApp is a third-party trademark; this plugin is not affiliated with or endorsed by WhatsApp or Meta.

== External services and data handling ==

This plugin connects to AI CRM Nepal at https://www.aicrmnepal.com, operated by AI Automation Nepal. Configuration is explicit: a site administrator supplies a capture-only key, enables the integration and tests the connection.

Endpoints:
* https://www.aicrmnepal.com/api/wordpress-whatsapp/validate — read-only setup/daily readiness check using the server-side key. Returns connection ID/revision/site/health route; no contact records.
* https://www.aicrmnepal.com/api/wordpress-whatsapp/capture — after the visitor chooses Continue, sends phone, random retry receipt, page path without query/fragment and optional page title. Creates or attaches a private CRM enquiry in the connected workspace. Transport request metadata may be processed by hosting/rate-limit providers; With optional source measurement disabled, this plugin does not add IP, user-agent or referrer to the saved enquiry.
* https://wa.me/ — opens the saved business number and optional prefilled message after CRM acknowledgement. The visitor then chooses whether to send a message in WhatsApp.

The capture key never enters frontend HTML or browser requests. WordPress stores an encrypted copy; CRM stores its hash. Visitor phone stays in the popup memory during the interaction and is not put into localStorage. CRM data remains until managed by the workspace; removing this plugin does not delete CRM records. WordPress transients temporarily enforce local limits and signed-probe replay friction. Daily health uses a short-lived signed ticket and reports plugin version, enabled status, destination format and CRM readiness; it does not transmit visitor phones.

Service requirements and data handling: https://www.aicrmnepal.com/wordpress-whatsapp/
Business operators should configure their own privacy-policy link and provide appropriate visitor notices. This plugin does not promise legal compliance. For enquiry access/removal contact the business receiving the enquiry; for service questions contact the support details on the service page. WhatsApp privacy policy: https://www.whatsapp.com/legal/privacy-policy

== Installation ==

1. Upload the ZIP in Plugins > Add New > Upload Plugin and activate.
2. Open Settings > AI CRM WhatsApp. Copy your site address and exact health path.
3. In AI CRM Nepal > Lead Source > WordPress WhatsApp, create the matching connection.
4. Paste the one-time capture key into WordPress. Choose a valid business destination with country code, such as your own +977 number. No destination is preselected.
5. Enable capture, save and click Test CRM connection. The widget appears after a successful test.
6. Optionally add [aicrm_whatsapp] or CSS class aicrm-whatsapp-trigger to your own button. Existing WhatsApp links are not replaced automatically.

Keep existing widgets disabled only after you have chosen and verified your site's final button flow. This plugin never disables other plugins.

== Frequently Asked Questions ==

= Does it require a WhatsApp API subscription? =
No. It uses a regular click-to-chat link after CRM save. Your CRM account is required separately.

= What if CRM is temporarily unavailable? =
The popup shows an error and does not redirect. Retry uses the same receipt for the same enquiry to avoid duplicate writes.

= Does a repeated phone create another contact? =
A matching normalized phone in the same workspace keeps its current contact details and receives another private enquiry. An identical retry receipt is accepted once.

= Why does Health show Unknown or Overdue? =
Unknown can mean a new/revoked/changed connection or incomplete monitoring run. Checks run once daily; results older than 26 hours show Overdue. Health is a bounded readiness check, not a continuous uptime or WhatsApp account guarantee.

= What if my WordPress salts change? =
Stored credentials cannot be decrypted. Reconnect with a new capture-only connection key and revoke the previous connection in CRM.

= Where is the source? =
All plugin source is included in this package. There is no frontend build step or external executable-code loader. Packaging instructions are in README.md.

== Changelog ==

= 0.2.0 =
* Add optional bounded enquiry-source capture with explicit decision provenance and trusted visitor request context.
* Add immediate Please wait feedback and one bounded submit deadline.
* No advertising API, pixel, feedback transfer or WhatsApp delivery confirmation.

= 0.1.3 =
* Increase phone-popup width and input/button spacing while retaining mobile fit.

= 0.1.2 =
* Use an accessible green circular WhatsApp icon for the floating launcher.

= 0.1.1 =
* Fix verified connection state persistence through the WordPress Settings API.
* Preserve browser permission boundaries while saving server-verified readiness.

= 0.1.0 =
* Initial phone capture, server relay, configurable click-to-chat widget and signed daily health integration.

== Upgrade Notice ==

= 0.1.0 =
Initial release. Configure and test your site-bound connection before enabling the widget.

== Optional source measurement ==
The CRM connection controls whether measurement is offered. The default-selected checkbox can be unchecked. Default selection is recorded separately from affirmative user choice and does not grant future advertising sharing or personalization. When permitted, available Google/Meta click IDs, existing cookie evidence, UTM/page/product context, original submitted contact fields and trusted visitor IP/user agent can be saved privately with the enquiry. No Meta/Google advertising calls or remote IP lookup occur. The CRM raw-attribution retention is90days; ordinary enquiry records have their own lifecycle. The business must provide an accessible privacy notice appropriate to its website and purposes.

Behind a reverse proxy, an administrator may define AICRM_WA_TRUSTED_PROXIES as an array of verified CIDRs in private server configuration. Default is an empty list. Untrusted forwarded headers are ignored; verified proxy chains are parsed right-to-left, and malformed chains omit IP. Never set broad universal trusted ranges merely to populate IP.
