=== Raya AI – Persian Support Chatbot ===
Contributors: rayachat
Tags: chatbot, ai chatbot, live chat, customer support, woocommerce
Requires at least: 5.3
Tested up to: 7.1
Requires PHP: 7.2
Stable tag: 1.8.1
License: GPLv2 or later
License URI: https://www.gnu.org/licenses/gpl-2.0.html

Puts your Rayachat AI chatbot on your site — it answers visitors from your knowledge and products — and its inbox in wp-admin.

== Description ==

[Rayachat](https://rayachat.net) is an AI customer-support chatbot for Persian-speaking businesses. You build the chatbot in the Rayachat dashboard — its knowledge, products, tone and look — and this plugin puts its chat widget on your WordPress site without touching theme code.

* Connect with one click: approve the site in your Rayachat account and come back connected — no codes or keys to copy. Pasting the install code by hand still works.
* Switch the widget off and on without losing its settings.
* Show it on every page, on every page except a few, or only on a few. Persian (non-Latin) addresses work as typed or as copied from the browser.
* The settings page shows the widget itself, so you see at once whether the code is right.
* Read and answer the chatbot's conversations without leaving WordPress, and see on the Dashboard who is waiting for a person and how the chatbot is doing.

The widget's corner, colours, texts, greeting and everything the chatbot says are managed in the Rayachat dashboard, so a change there reaches your site without updating the plugin.

= The inbox in WordPress =

Tick "Inbox and figures in WordPress" when you connect, and Rayachat → Inbox shows every conversation of the chatbot, from the site and from Telegram or Bale: the customers waiting for a person first, the whole thread with photos and the product cards the bot sent, the contact details from the lead form, and the page the visitor wrote from. Answer from there — the reply goes out on the customer's own channel, and the bot stops in that conversation until you press "Resume automatic replies" — or mark a conversation resolved. Saved replies from Rayachat are a "/" away. The menu shows how many customers are waiting.

The Dashboard gets Rayachat cards: customers waiting for you, conversations and leads with a 14-day chart, the plan's messages and whether the bot is still answering, questions the bot couldn't answer, the latest leads, the products it showed, and the latest conversations. Add or remove them under Screen Options and drag them where you like; each links to the page in the Rayachat dashboard that has all of it. On a store, shop managers see the inbox and the cards too; elsewhere, administrators.

= WooCommerce =

Tick "Sync WooCommerce products" when you connect, and the plugin sends your products to your chatbot — name, description, categories, attributes, every variation with its price and stock, and the main picture — and keeps them up to date. A change waits 10 minutes before it is sent (you can choose 5, 10 or 30), and each new edit to the same product starts the wait again, up to twice the wait in all, so a wrong price or a product trashed by mistake that you put right in time never reaches your customers. Once a day the plugin checks every product again; only the products that changed are sent. Prices are converted to toman from rial, toman, thousand rial or thousand toman.

Developers can hide the widget on any page with the `rayachat_show_widget` filter:

`add_filter( 'rayachat_show_widget', function ( $show ) { return $show && ! ( function_exists( 'is_checkout' ) && is_checkout() ); } );`

== External services ==

This plugin connects your site to Rayachat (https://rayachat.net), the service that runs your chatbot. The plugin needs a Rayachat account and chatbot; until you connect it loads nothing and sends nothing.

* **Connecting (when you click "Connect to Rayachat"):** your browser opens `https://rayachat.net/connect/wordpress` with your site's address and name, whether WooCommerce is active, and two random one-time values. After you approve, your site sends `https://rayachat.net/api/integrations/wordpress/exchange` the one-time code it got back, and receives the chatbot's install code, a sync key if you chose product sync, and a key for the inbox if you allowed it. Disconnecting tells Rayachat to stop accepting those keys.

* **The chat widget:** on every page where the widget is shown, and on the plugin's own settings page as a preview, the visitor's browser loads `https://rayachat.net/widget.js`, which opens the chat window in an iframe served from `https://rayachat.net/embed/`. Loading those files sends the chatbot's install code and, as with any web request, the visitor's IP address and browser details. When a visitor chats, their messages, any photo or file they attach and any details they enter in the chatbot's contact form are sent to Rayachat, to be answered and shown to your team. The chat window keeps a random visitor token in the browser's storage for rayachat.net, so a conversation carries on across pages.
* **WooCommerce product sync (only when you turned it on):** your site sends `https://rayachat.net/api/integrations/woocommerce/` your store's address and currency, and for each published product its name, SKU, link, descriptions, categories, visible attributes, variations with their prices and stock, and its main picture. It does so when you connect, after a product changes (after the wait you chose), and once a day — then a short fingerprint of each product, and in full only the products that changed.
* **Sales after a chat (with WooCommerce product sync on):** when a visitor writes to the chatbot, the widget keeps a random reference in a cookie on your site, `rayachat_ref`, for 7 days. An order placed with it keeps the reference, and when the order is paid, cancelled, refunded or fails your site sends `https://rayachat.net/api/integrations/woocommerce/sales` its order ID, total, currency, status, date and that reference — never the buyer's name, phone, email, address or the products bought. Once a night it also sends the number and total of the paid orders of the last two days, as two figures per day. Rayachat uses them to show the chatbot's owner the sales that came after a chat.
* **The inbox and the Dashboard cards (only when you allowed them):** while an admin has the inbox or the Dashboard open, your site asks `https://rayachat.net/api/integrations/wordpress/inbox/` for the chatbot's conversations, its figures and the customers waiting for a person, and passes them on to that admin's browser — every few seconds for an open conversation, and at most once a minute for the menu's count and the Dashboard's figures. A reply, a pause or a status change made there is sent with the display name of the WordPress user who made it. Product pictures in conversations load from `https://rayachat.net/api/product-images/`. The plugin's own admin pages load Rayachat's typeface from `https://rayachat.net/api/integrations/wordpress/font`, which serves it to connected sites only; the request carries the site's address, as any font request does. Disconnecting or deleting the plugin tells Rayachat to stop accepting the key, and the chatbot's owner can withdraw it from the Rayachat dashboard at any time.
* **What is never sent:** anything about your customers, anything about your orders beyond the figures above, and anything about your site's posts, pages or users — except, from the inbox, the display name of the user who answered or changed a conversation.

Rayachat terms of use: https://rayachat.net/terms
Rayachat privacy policy: https://rayachat.net/terms#privacy

== Installation ==

1. Install and activate the plugin from Plugins → Add New, or upload the plugin zip there.
2. Open Rayachat in the admin menu and click "Connect to Rayachat".
3. Sign in to Rayachat (or create an account), choose the chatbot for this site and approve. Keep "Inbox and figures in WordPress" ticked to answer customers from WordPress, and on a WooCommerce store, "Sync WooCommerce products".
4. You come back to WordPress connected: the widget is in the corner of the page, the conversations are in Rayachat → Inbox, and the first product sync runs in the background.

If the one-click connection can't be used on your site, open "Connect by hand" on the same page and paste the install code (and, for a store, a sync key) from your chatbot's Publish page in the Rayachat dashboard.

== Frequently Asked Questions ==

= Do I need a Rayachat account? =

Yes. You can create one while connecting: "Connect to Rayachat" takes you to sign in or sign up, and then back.

= Where do I change the widget's colours and texts? =

In the Rayachat dashboard, on your chatbot's Widget tab. The plugin only decides where the widget appears.

= The widget doesn't show up on my site. =

Open Rayachat in the admin menu: the widget is always shown there. If it appears there but not on your pages, check the Pages setting and clear your caching plugin's cache. If it doesn't appear there either, copy the install code again from the Rayachat dashboard.

= I edited a synced product in Rayachat and my change was lost. =

The store is the source of a synced product: its next change in WooCommerce writes over the product in Rayachat. Edit the product in WooCommerce. Which chatbots show it and whether the bot uses it are settings of Rayachat's own and are kept.

= Who can see the conversations in WordPress? =

Administrators, and on a WooCommerce store shop managers too. A site can change that with the `rayachat_inbox_capability` filter. The chatbot's owner can take the inbox away from the site in the Rayachat dashboard: your chatbot → Publish → WordPress plugin.

= I updated the plugin; where is the inbox? =

A site connected with an earlier version connects once more to turn it on: Rayachat → Settings → "Change chatbot or reconnect", keeping "Inbox and figures in WordPress" ticked.

= I installed the plugin from rayachat.net before. Should I switch? =

There is no need: both are the same plugin, and the copy from rayachat.net keeps updating from rayachat.net. To switch, update the old copy to 1.8.1 or later first, then install this one, deactivate the old copy, activate this one and delete the old copy. They share their settings, so the site stays connected throughout; an old copy before 1.8.1 erases them when it is deleted. Only one of the two runs at a time.

= Does it work on right-to-left sites? =

Yes. The plugin and the widget are built for Persian sites first.

== Screenshots ==

1. The settings page, with the widget previewed in its corner.
2. The chat widget open on a site.

== Changelog ==

= 1.8.1 =
* The plugin is in Persian on a Persian site however it was installed: the copy from the WordPress.org directory showed in English, because it came without the translation.
* The Persian translation was reviewed: one spelling throughout, the dashboard's own names for the places it points to, and clearer wording in a few places, such as the inbox's "Save and teach" button.
* Rayachat downloaded from rayachat.net and Raya AI from WordPress.org can no longer both run: with both active, one steps aside and a notice asks you to deactivate one, where activating the second used to stop with a fatal error. Both use the same settings, so the one you keep stays connected.
* Deleting one of the two copies while the other is active leaves the settings, the store's connection and the inbox in place.

= 1.8.0 =
* Sales after a chat: on a store with product sync on, an order placed by a visitor who wrote to the chatbot in the week before is reported to Rayachat — its ID, total, currency, status and date only — and the Rayachat overview shows those orders, their total and how many conversations led to one. Nothing about the buyer or the products bought is sent. The checkout waits on nothing: the report goes from a background job.

= 1.7.7 =
* When the Rayachat account has no AI — the free plan's 100 AI replies are used up, the plan has run out, or the wallet is empty — the bar above the reply box says so instead of offering "Pause the bot" or "Turn the bot back on", with a link to where it is fixed in Rayachat. Messages keep arriving as live chat and you answer them here as before.

= 1.7.6 =
* Saved replies in the inbox open on a dot as well as a slash — ". " at the start of the reply or after a space, then part of a title — as in Rayachat's inbox. Punctuation stays text: "..." or a full stop at the end of a sentence opens nothing.
* A saved reply's {نام}, {موبایل}, {ایمیل}, {صفحه} and {ربات} (or {name}, {phone}, {email}, {page}, {bot}) are filled in as it is dropped into the reply box, from what the conversation already shows: the lead's name, mobile and email, the page the visitor wrote from and the chatbot's name. One the conversation doesn't know stays as written, so you see what is missing before sending.

= 1.7.5 =
* Product sync sends a variation's options by name, for example Color: Black. A global attribute with a Persian name used to go out as its encoded slug, which the chatbot couldn't read, so it guessed which colours and sizes were in stock.

= 1.7.4 =
* Product sync sends a product's description up to 20,000 characters instead of 6,000, so the chatbot can answer from the care instructions, size guide and FAQ further down a long description.

= 1.7.3 =
* The bar above the reply box is always there: "Bot active" with "Pause the bot" while the bot answers, "Bot paused" with "Turn the bot back on" once someone has taken over. A handover offers "Pause the bot" beside "Done, mark handled".

= 1.7.2 =
* Answering a customer stops the bot in that conversation, as before, and it now says so above the reply box: "Bot paused", who has the conversation, and "Turn the bot back on". A handover shows its reason in the same place, with "Done, mark handled" to close it while the bot keeps answering, so it is settled before anyone types.
* Every conversation wears one tag, as in Rayachat's inbox: In progress (the bot is answering), Needs a person (the bot handed it over), Pending (a person has it), Unanswered message (the customer wrote again after your reply) or Resolved (handed back to the bot).
* "Needs you" holds everyone waiting for a person — handovers and unanswered messages — and so do the menu's count and the Dashboard card, until someone answers them or turns the bot back on.
* The "Bot paused" list is now "Pending", with unanswered customers first, and the Leads list is gone: a lead keeps its tag on its conversation.
* A dot marks a conversation with a customer message you haven't opened yet. Each admin has their own.

= 1.7.1 =
* Send queue: a job WordPress has not run by its time says how late it is, with "Send now" to send it at once. WordPress runs every plugin's scheduled jobs one batch at a time, and only when someone opens the site or its admin, so a cache plugin's preloading can hold a change for minutes.

= 1.7.0 =
* The chatbot's inbox in WordPress: read every conversation from the site, Telegram and Bale, answer on the customer's own channel, mark conversations resolved, and use your saved replies. Customers waiting for a person come first, and the menu shows how many there are.
* Answering a customer yourself stops the bot in that conversation, here and in the Rayachat dashboard alike, so it never answers over you; "Resume automatic replies" turns it back on.
* "This answer was wrong" under the bot's replies in the inbox: write the right answer and the bot uses it the next time a customer asks something similar (administrators only).
* "Send queue" on the plugin's page: every product change, retry, picture and full-sync step still waiting to reach Rayachat, with the products, why each one waits and when it goes. It is read only when you open the page.
* Rayachat cards on the Dashboard — customers waiting for you, conversations and leads, the plan's messages, questions the bot couldn't answer, the latest leads, the products it showed and the latest conversations — to add, remove and arrange under Screen Options.
* A site connected with an earlier version connects once more to turn these on.

= 1.6.3 =
* A maintenance release. Nothing changes in how the plugin works.

= 1.6.2 =
* The product sync's settings keep only the fields the plugin knows, each checked, however they are saved. Nothing changes in how the plugin works.

= 1.6.1 =
* Lighter on your site's server. The daily check and queued product updates read your products in a few database queries instead of several for every product and variation, a sale adds fewer queries to the checkout, admin pages look up the daily check's schedule once an hour instead of on every page, and the pages your visitors open no longer load the plugin's translation. What is sent to Rayachat, and when, is unchanged.

= 1.6.0 =
* The "Straight away" choice for sending product changes is gone: it made saving a product, and a customer's checkout, wait for Rayachat to answer. A site that had it now sends changes after 5 minutes.

= 1.5.1 =
* Small fixes ahead of the WordPress.org plugin directory; nothing changes in how the plugin works.

= 1.5.0 =
* Updates arrive in WordPress like any other plugin's: an "Update now" link on the Plugins page, and the auto-update switch if you want them installed by themselves. Install this version by hand once; the versions after it come to you.
* The widget's corner is set only in the Rayachat dashboard, next to its distance from the bottom and side of the page, so the two can't disagree. A corner chosen in an earlier version of the plugin no longer applies.
* The reminder to clear your site cache after saving stands out, so it is not missed.

= 1.4.1 =
* Rayachat has its own item in the admin menu (it was under Settings), and its page is redesigned: the connection at the top, the numbers that matter first, and settings you can change at a glance.
* The daily check runs at night, between 2 and 5 in the morning in your site’s time, instead of an hour after the plugin was last turned on.
* A product that could not be sent (no connection, a server error) is sent again automatically, a few times, waiting longer each time.
* Pictures upload in their own background jobs, so prices and stock are never held up behind them.
* “Sync everything now” says how many products did not get through, instead of only “Done”.
* Products on backorder show as orderable without ready stock, never as in stock.

= 1.4.0 =
* A sale no longer starts a product’s wait again, so a product that sells often is still sent on time — once per wait, however many times it sold.
* The wait for a change never grows past twice the time you chose, however often the product is saved.
* The daily check sends a short fingerprint of each product, and only the products that changed are sent in full.
* Turning the plugin off and on again no longer stops the daily check.
* Product data is sent as plain UTF-8 — about a third of the size for Persian text — and read with fewer database queries.

= 1.3.0 =
* One-click connection: "Connect to Rayachat" sets up the widget and, on a store, the product sync — no codes or keys to copy. Disconnecting stops the sync on Rayachat's side too.
* Product changes wait before they are sent (10 minutes by default; straight away, 5, 10 or 30), and a new change restarts the wait, so mistakes corrected in time never reach your customers.
* The WooCommerce sync now sends products only. Order tracking and selling in the chat (an "Add to cart" button and a checkout link) are removed: the plugin no longer reads your orders or changes a visitor's cart.
* A main picture in a format Rayachat can't read (such as AVIF or GIF) is no longer uploaded, and none is uploaded while your plan's picture space is full.
* "Sync everything now" also reports how many products were already up to date.
* A redesigned settings page: the widget's and the product sync's state at a glance — pages and corner, products in your store and with the chatbot, your plan's product use, the last and next sync, and changes still waiting to be sent — with setup steps for a new install.

= 1.1.0 =
* WooCommerce sync: products, with prices in toman, stock, variations and the main picture, kept up to date as they change.
* Optional order tracking: the chatbot tells a customer their order's status after they give its number and their mobile.

= 1.0.0 =
* First release.
