# IntelTele WooCommerce SMS/Viber

WordPress/WooCommerce plugin for sending customer and manager notifications through IntelTele SMS and Viber API.

## Requirements

- PHP 7.4+
- WordPress 6.0+
- WooCommerce 7.1+
- WooCommerce HPOS compatible

## Installation

1. Upload the plugin zip in WordPress admin: Plugins -> Add New -> Upload Plugin.
2. Activate `IntelTele WooCommerce SMS/Viber`.
3. Open `IntelTele -> Settings`.
4. Enter the API key and save settings.
5. Click `Check connection` to fetch balance.
6. Add manager phone numbers in international format without plus sign, for example `380671111111`.

## API Senders

- SMS sender: `woocom`
- Viber sender: `woocomvib`

## Local Mock Mode

For local testing without real SMS/Viber sending, add this to `wp-config.php`:

```php
define( 'INTELTELE_API_CLIENT_MODE', 'mock' );
```

Mock mode returns a fake balance and fake `message_id` values. It does not send real messages.

## Settings

- `API key` - saved in WordPress options and masked in UI after saving.
- `Balance` - fetched from IntelTele API.
- `Alpha-name` - SMS sender, fixed as `woocom`.
- `Viber name` - Viber sender, fixed as `woocomvib`.
- `Manager phones` - up to 15 numbers, digits only.
- `Viber + SMS TTL` - Viber lifetime in seconds.
- `Bulk campaign batch size` - number of recipients processed per batch.

## Sending

Single sending supports:

- SMS
- Viber
- Viber + SMS

Bulk sending supports:

- recipients by WordPress/WooCommerce role;
- selected users from a list;
- campaign creation;
- batch processing;
- progress in reports.

## WooCommerce Automation

Open `IntelTele -> WooCommerce`:

1. In `Statuses`, select which order statuses should trigger messages for customer and/or administrator.
2. In `Messages`, create templates for recipient, order status and sending scheme.
3. Use preview order to test variable replacement.

Messages are sent after `woocommerce_order_status_changed`.

## Template Variables

- `{StoresName}`
- `{ClientName}`
- `{ClientLastName}`
- `{OrderStatus}`
- `{AddrOrderDelivery}`
- `{ClientEmail}`
- `{ClientPhone}`
- `{MethodPayment}`
- `{OrderID}`
- `{OrderSum}`
- `{OrderCurrency}`
- `{TTN_Number}`
- `{TrackingURL}`
- `{PaymentURL}`

If a value is missing, an empty value is substituted.

## Reports

Reports include:

- single sends;
- bulk campaigns;
- automatic order status sends;
- API message IDs;
- delivery status;
- error reason;
- Viber TTL/fallback data;
- CSV export.

## Viber + SMS

The plugin sends Viber first. SMS fallback is sent once if:

- Viber status becomes `undeliv`, `expired`, or `rejectd`;
- or Viber TTL expires without successful delivery status.

Successful Viber statuses:

- `delivrd`
- `seen`
- `click`

## Cron

On activation, the plugin schedules:

- `inteltele_sync_statuses`
- `inteltele_process_fallbacks`

Both run every five minutes through WP-Cron.

Manual buttons are also available in `IntelTele -> Reports`:

- `Sync delivery statuses`
- `Process Viber SMS fallbacks`

## Security

- Admin pages require `inteltele_manage`.
- Capability is added to `administrator` and `shop_manager` on activation.
- All admin forms use nonce checks.
- All UI output is escaped.
- API key is not shown fully after saving.
- UI strings use text domain `inteltele`.
