=== LeadSender for MAX ===
Contributors: prohortech
Tags: max, messenger, leads, contact form 7, fluent forms
Requires at least: 6.2
Tested up to: 7.1
Requires PHP: 7.4
Stable tag: 1.0.1
License: GPLv2 or later
License URI: https://www.gnu.org/licenses/gpl-2.0.html

Instantly sends leads from Fluent Forms, Contact Form 7 and any form that sends email via wp_mail to chats in the MAX messenger.

== Description ==

In Russian the plugin is called «Отправка форм в MAX» ("Sending forms to MAX").

LeadSender for MAX delivers every new form submission from your WordPress site to one or several chats or groups in the MAX messenger, so your team sees new leads within seconds.

This plugin is not affiliated with or endorsed by the MAX messenger or its owners. "MAX" is used only to describe the service the plugin works with.

Plugin website: [wp-addon.ru/leadsender-for-max](https://wp-addon.ru/leadsender-for-max/)

= Features =

* **Fluent Forms** — the lead is taken right after the entry is saved, even if email notifications are turned off.
* **Contact Form 7** — the lead reaches MAX even if the site failed to send the email.
* **Any other form** (Elementor, WPForms, custom theme forms) — through wp_mail interception with filters by recipient address and subject. System emails of WordPress and WooCommerce are skipped.
* **Any number of chats** — every lead is sent to all enabled chats.
* **Instant delivery** — each lead is sent as a separate message right after the form is submitted. The visitor never waits: sending happens after the page response.
* **Message content** — form name, site, all filled-in form fields and submission time.
* **Reliable** — queue with automatic retries and an email to the administrator if delivery fails.
* **Setup wizard** — bot token check, automatic search of the chat ID, test message.
* **Russian trusted root certificates** — if the hosting does not trust the MAX API certificate, upload the certificate files in the settings and the plugin will use them for requests to MAX.
* Each message ends with a short signature with a link to the plugin website.

The plugin interface is in Russian.

= Pro add-on =

A separate paid add-on is available at [wp-addon.ru/leadsender-for-max](https://wp-addon.ru/leadsender-for-max/). It is installed as a separate plugin and adds:

* Lead source: ads, UTM tags, yclid, referrer, landing page, Yandex Metrica ClientID.
* Page of the form, device, IP address, link to the entry in the admin area.
* Buttons under the message: copy phone, copy email, open the entry.
* WooCommerce orders.
* Spam filter.
* Routing of leads to different chats by form.
* Message settings: title, blocks, hiding fields, silent notifications, message without the signature.
* Delivery log with manual resend.

== Installation ==

1. Upload the plugin and activate it.
2. Open "Settings → Отправка в MAX" (the plugin interface is in Russian).
3. Paste your MAX bot token (business.max.ru → Chat bots → ⋮ → Settings) and click "Check connection".
4. Add the bot to a MAX group, send any message to the group, click "Find my chat" and add the chat.
5. Save the settings and click "Send test message".

The token can also be defined in wp-config.php: `define( 'LSFM_BOT_TOKEN', '...' );`

== External services ==

This plugin connects to one third-party service. Without it the plugin cannot deliver leads.

**MAX Bot API** (platform-api2.max.ru) — the API of the MAX messenger, provided by the MAX service (legal.max.ru).

* Purpose: sending leads to MAX chats, checking the bot token, finding the chat ID.
* Data sent: the bot token; values of the submitted form fields (for example name, phone, email, message); site name and form name; submission time.
* When: on every new form submission, and when the administrator clicks "Check connection", "Find my chat" or "Send test message".
* Terms of use: https://legal.max.ru/ps
* Privacy policy: https://legal.max.ru/pp
* API documentation: https://dev.max.ru/docs-api

The plugin does not download anything by itself. Russian trusted root certificates, if your hosting needs them, are uploaded by the administrator manually (they are published at https://www.gosuslugi.ru/crt).

Forwarding leads to MAX means transferring visitors' personal data to the messenger operator. Mention this in your site's privacy policy.

== Frequently Asked Questions ==

= Where do I get a bot? =

A MAX bot can be created only by a verified organization, sole proprietor or self-employed person (Russian residents) on business.max.ru. The token is issued there after the bot passes moderation.

= The hosting does not trust the MAX server certificate =

Download the root and sub CA certificates from gosuslugi.ru/crt. Then open "Connection → Advanced", select the files (or paste their PEM text) and click "Save certificates". You can also put the files into the plugin's assets/certs folder.

= Leads arrive with a delay =

On hosting without PHP-FPM, sending runs through WP-Cron, which is triggered by site visits. If WP-Cron is disabled, set up a system cron job for wp-cron.php every minute.

= I get duplicates =

If a form is handled by its own adapter (Fluent Forms, Contact Form 7), its wp_mail emails are not forwarded again. For other forms, limit interception by recipient address or email subject.

== Developers ==

Filters: lsfm/sources, lsfm/lead (return false to skip), lsfm/lead_context, lsfm/recipients, lsfm/send_at, lsfm/format_group, lsfm/message_attachments, lsfm/send_args, lsfm/wpmail/should_capture, lsfm/http_args, lsfm/settings_defaults, lsfm/save_settings.
Actions: lsfm/queued, lsfm/sent, lsfm/failed.

Add your own form:

    add_action( 'my_form_submitted', function ( $data ) {
        LSFM_Collector::add( array(
            'source'     => 'my-form',
            'form_title' => 'Calculator',
            'fields'     => array(
                array( 'label' => 'Phone', 'value' => $data['phone'] ),
            ),
        ) );
    } );

== Screenshots ==

1. Connection: bot token check, chat search and the list of chats that receive leads.
2. Lead sources: Fluent Forms, Contact Form 7 and interception of other forms via wp_mail.

== Changelog ==

= 1.0.1 =
* The Russian plugin name «Отправка форм в MAX» is now used throughout the interface.
* Plugin headers are translated through translate.wordpress.org instead of a bundled file.

= 1.0.0 =
* First release.
