=== Krivoshein Autopost for MAX ===
Contributors: alekseyweb
Tags: max, messenger, social, notifications, cron
Requires at least: 6.0
Tested up to: 7.1
Requires PHP: 8.0
Stable tag: 1.12.0
License: GPLv2 or later
License URI: https://www.gnu.org/licenses/gpl-2.0.html

Publish WordPress posts to MAX chats and channels in one message: image, text, and a button.

== Description ==

Krivoshein Autopost for MAX sends a published WordPress post to a chat or channel in the MAX messenger.

One post becomes one MAX message:

* an image, when the post has a featured image and images are enabled
* the text you choose: the content, the excerpt, the title, or a plain announcement
* an inline button, such as Read or Subscribe

This plugin is independent. It is not made by MAX, and it is not an official MAX product. You use your own bot token.

= What it does =

* More than one chat ID. One post can go to several channels or groups. A failure in one chat does not stop the others.
* A queue on WP-Cron, with a batch size, a pause between sends, retries, and a log.
* HTTP 429 stops the batch and does not use up a retry.
* Send one post now, from the editor or with WP-CLI.
* The bot token can stay in the plugin settings, or in wp-config.php as KRV_MAX_TOKEN. The settings field stores the token in the database. wp-config.php is the safer place.

New posts are queued when they are published. Posts that already existed when you installed the plugin are not sent until you queue them.

Development of this plugin happens in public at [https://github.com/A-Krivoshen/max-autopost](https://github.com/A-Krivoshen/max-autopost).

== Installation ==

1. Upload the plugin and activate Krivoshein Autopost for MAX. You can also install it from the Plugins screen once it is in the directory.
2. Open Krivoshein Autopost for MAX, then Settings. Save the bot token and the chat ID.
3. Send a test message.
4. Publish a post, or run the queue from the Queue tab.

If this site already runs the GitHub release (the folder is named max-autopost), deactivate that copy and remove its folder before you activate this one. Do not use Plugins, then Delete, if you want to keep the saved token: Delete runs uninstall and clears the plugin settings. Remove the old folder with FTP or the hosting file manager, then activate this build. The settings remain, because both builds use the same option names.

Do not keep both copies active. They are the same plugin with two different folders.

== Frequently Asked Questions ==

= Is this an official MAX plugin? =

No. MAX is a separate messenger. This plugin calls the public MAX Bot API with a token you create for your own bot.

= Where is the token stored? =

In your WordPress database (the options table), unless you define KRV_MAX_TOKEN in wp-config.php. The plugin author never receives the token.

= What is sent to MAX? =

Only when you send a test, or when the queue sends a post: the bot token, the chat ID, the title, the text, the link, the button label and URL, and the featured image when images are enabled.

= Why is a certificate file included? =

The MAX API certificate is issued by the Russian Trusted CA. Many shared hosts do not trust that CA. The plugin appends this public certificate to the normal trust store, and only for requests to MAX and its media hosts. Other HTTPS requests on the site are unchanged.

= Why does image upload use cURL? =

MAX upload is two steps. The second step is a multipart file upload to a one-time HTTPS address. The WordPress HTTP API does not send that file in the shape the API expects. cURL is limited to HTTPS, and the host must be MAX or a known MAX media host.

= Will activation publish my old posts? =

No. Existing posts stay where they are until you queue them. Queue actions run in batches.

== External services ==

This plugin connects to one external service: the MAX Bot API.

* Service: MAX messenger Bot API
* Host: https://platform-api2.max.ru
* API reference: https://dev.max.ru/docs-api
* Terms of use: https://legal.max.ru/ps
* Developer rules: https://dev.max.ru/docs/legal/rules

The plugin contacts that host only after you save a bot token and a chat ID, and then send a test or let the queue send a post.

Data sent:

* the bot token, in the Authorization header
* the chat ID
* the post title, text, and permalink
* the button label and URL, when a button is enabled
* the featured image, when images are enabled

The image is uploaded to a media host returned by the API. Those hosts are max.ru and the related media hosts oneme.ru, okcdn.ru, mycdn.me, vkuserphoto.ru, and userapi.com.

The token and the chat ID stay on your site. Nothing is sent to the plugin author.

== Changelog ==

= 1.12.0 =
* An update no longer disables the worker and no longer resets the queue stamp.
* Send a single post by ID from the admin screen or with WP-CLI.
* A run can send a batch, with a pause between posts. HTTP 429 stops the batch.
* Requeue shows a preview and asks for a separate confirmation.

= 1.11.9 =
* The image payload is the upload token or URL. This avoids HTTP 400 proto.payload.
* Bold titles use the b tag, which MAX accepts.

= 1.11.7 =
* A channel that rejects a silent message is retried once with the default notification.

= 1.11.0 =
* The API host is platform-api2.max.ru.

== Upgrade Notice ==

= 1.12.0 =
Queue settings are kept. Only queued items older than 14 days are marked as an error.
