diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 0000000..21d4d20 --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,20 @@ +# Changelog + +All notable changes to this project will be documented in this file. + +The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). + +## [Unreleased] + +### Bug Fixes + +- **Message priority always serialized** — a message's `priority` is now always included in the JSON body (defaulting to `0` when unset), matching the wire format of the other official SDKs. + +## [2.6.0] - 2026-08-19 + +### New Features + +#### Inbox refresh and batch webhooks + +- **`RefreshInbox` with `InboxRefreshRequest`** — refresh the inbox and choose how webhook events are delivered with `WebhookDelivery` (`Disabled`, `Individual`, or `Batch`). `RequestInboxExport` is deprecated in favor of it. +- **Batch webhook events** — `sms:batch:received`, `sms:batch:data-received`, `mms:batch:received`, and `mms:batch:downloaded` events with typed payload classes (`SmsBatchReceivedPayload`, `SmsBatchDataReceivedPayload`, `MmsBatchReceivedPayload`, `MmsBatchDownloadedPayload`). \ No newline at end of file diff --git a/README.md b/README.md index 7eb1b62..ea7aa7d 100644 --- a/README.md +++ b/README.md @@ -11,7 +11,7 @@ A modern PHP client for the [SMSGate](https://sms-gate.app) API: send SMS messag ## 📖 About -`capcom6/android-sms-gateway` is a type-safe PHP library for the SMSGate 3rd-party API. It covers messages (send, state, listing, cancellation), inbox refresh with attachment download, devices, webhooks, settings, logs, health checks, and the JWT token lifecycle, with a fluent `MessageBuilder` for message construction and an optional `Encryptor` for end-to-end encryption. Works with any PSR-18 HTTP client (Guzzle, curl, or others) and PHP 7.4+. +`capcom6/android-sms-gateway` is a type-safe PHP library for the SMSGate 3rd-party API. It covers messages (send, state, listing, cancellation), inbox refresh with individual or batch webhook delivery and attachment download, devices, webhooks, settings, logs, health checks, and the JWT token lifecycle, with a fluent `MessageBuilder` for message construction and an optional `Encryptor` for end-to-end encryption. Works with any PSR-18 HTTP client (Guzzle, curl, or others) and PHP 7.4+. ## 📚 Table of Contents @@ -25,6 +25,7 @@ A modern PHP client for the [SMSGate](https://sms-gate.app) API: send SMS messag - [JWT Authentication](#jwt-authentication) - [🚀 Quickstart](#-quickstart) - [💻 Usage](#-usage) + - [⚙️ Configuration](#️-configuration) - [📖 API Reference](#-api-reference) - [🤝 Contributing](#-contributing) - [📄 License](#-license) @@ -32,10 +33,11 @@ A modern PHP client for the [SMSGate](https://sms-gate.app) API: send SMS messag ## ⭐ Features - Fluent `MessageBuilder` for messages and `SettingsBuilder` for settings +- Messages: send, state, listing, and cancellation - PSR-18 HTTP client and PSR-17 factories, auto-discovered - Basic and JWT authentication with token generation and revocation -- Webhooks, devices, settings, logs, and health checks -- Inbox refresh with webhook delivery and MMS attachment download +- Inbox refresh with individual or batch webhook delivery and MMS attachment download +- Webhooks (single and batch events), devices, settings, logs, and health checks - Optional end-to-end encryption via `Encryptor` - Structured `HttpException` error handling @@ -96,6 +98,20 @@ echo 'Message ID: ' . $state->ID() . PHP_EOL; Beyond sending, the client covers message listing and cancellation, inbox listing and refresh, device management, health checks, logs, settings (get, patch, replace), webhooks, and token lifecycle. See [src/Client.php](https://github.com/android-sms-gateway/client-php/blob/master/src/Client.php) for the complete method list with signatures and [src/Domain](https://github.com/android-sms-gateway/client-php/tree/master/src/Domain) for the domain models. +## ⚙️ Configuration + +The `Client` constructor accepts the following parameters: + +| Parameter | Required | Description | +| ------------ | -------- | ------------------------------------------------------------------------- | +| `$login` | No | Account login for Basic authentication | +| `$password` | Yes | Account password (Basic) or a JWT token (Bearer) | +| `$serverUrl` | No | API base URL; defaults to `https://api.sms-gate.app/3rdparty/v1` | +| `$client` | No | PSR-18 HTTP client; auto-discovered via `php-http/discovery` when omitted | +| `$encryptor` | No | Optional `Encryptor` for end-to-end encryption | + +When `$login` is set, Basic authentication is used. When only `$password` is provided, it is sent as a Bearer JWT token. + ## 📖 API Reference - [Official API Reference](https://docs.sms-gate.app/integration/api/) - endpoints, payloads, and error codes diff --git a/src/Domain/Message.php b/src/Domain/Message.php index 12dbec5..576e676 100644 --- a/src/Domain/Message.php +++ b/src/Domain/Message.php @@ -105,6 +105,10 @@ public function ToObject(): object { $obj->priority = $this->priority; } + // Go wire parity: Message.Priority has no omitempty and always + // serializes (zero value 0). + $obj->priority = $this->priority ?? 0; + if ($this->ttl !== null) { $obj->ttl = $this->ttl; } diff --git a/tests/Domain/MessageTest.php b/tests/Domain/MessageTest.php index 1eb0db2..52b28ec 100644 --- a/tests/Domain/MessageTest.php +++ b/tests/Domain/MessageTest.php @@ -31,6 +31,7 @@ public function testCanSerializeToObject(): void { $expected = (object) [ 'id' => $id, 'message' => $messageText, + 'priority' => 0, 'ttl' => $ttl, 'simNumber' => $simNumber, 'withDeliveryReport' => $withDeliveryReport, @@ -52,5 +53,17 @@ public function testDefaultsWithNullParameters(): void { $this->assertNull($serialized->simNumber); $this->assertTrue($serialized->withDeliveryReport); $this->assertFalse($serialized->isEncrypted); + $this->assertSame(0, $serialized->priority); } -} \ No newline at end of file + + public function testLegacyTextMessageStillSerializesMessageKey(): void { + $message = new Message('Hello', ['+1234567890']); + + $json = json_encode($message->ToObject(), JSON_THROW_ON_ERROR | JSON_UNESCAPED_SLASHES); + + $this->assertSame( + '{"id":null,"message":"Hello","simNumber":null,"withDeliveryReport":true,"isEncrypted":false,"phoneNumbers":["+1234567890"],"priority":0}', + $json + ); + } +}