gsmservice-pl/messaging-sdk-php

v2.1.5 2024-10-26 22:06 UTC

This package is auto-updated.

Last update: 2024-10-26 22:17:32 UTC


README

Packagist Version GitHub License Static Badge

GSMService.pl Messaging REST API SDK for PHP

This package includes Messaging SDK for PHP (>8.2) to send SMS & MMS messages directly from your app via https://bramka.gsmservice.pl messaging platform.

Additional documentation:

A documentation of all methods and types is available below in section Available Resources and Operations .

Also you can refer to the REST API documentation for additional details about the basics of this SDK.

Table of Contents

SDK Installation

The SDK relies on Composer to manage its dependencies.

To install the SDK and add it as a dependency to an existing composer.json file:

composer require "gsmservice-pl/messaging-sdk-php"

Requeirements:

  • Minimal PHP version: 8.2

SDK Example Usage

Sending single SMS Message

This example demonstrates simple sending SMS message to a single recipient:

declare(strict_types=1);

require 'vendor/autoload.php';

use Gsmservice\Gateway;
use Gsmservice\Gateway\Models\Components;

$security = '<YOUR API ACCESS TOKEN>';

$sdk = Gateway\Client::builder()->setSecurity($security)->build();

$request = [
    new Components\SmsMessage(
        recipients: [
            '+48999999999',
        ],
        message: 'To jest treść wiadomości',
        sender: 'Bramka SMS',
        type: Components\SmsType::SmsPro,
        unicode: true,
        flash: false,
        date: null,
    ),
];

$response = $sdk->outgoing->sms->send(
    request: $request
);

if ($response->messages !== null) {
    // handle response
}

Sending single MMS Message

This example demonstrates simple sending MMS message to a single recipient:

declare(strict_types=1);

require 'vendor/autoload.php';

use Gsmservice\Gateway;
use Gsmservice\Gateway\Models\Components;

$security = '<YOUR API ACCESS TOKEN>';

$sdk = Gateway\Client::builder()->setSecurity($security)->build();

$request = [
    new Components\MmsMessage(
        recipients: [
            '+48999999999',
        ],
        message: 'To jest treść wiadomości',
        attachments: [
            '<file_body in base64 format>',
        ],
        subject: 'To jest temat wiadomości',
        date: null,
    ),
];

$response = $sdk->outgoing->mms->send(
    request: $request
);

if ($response->messages !== null) {
    // handle response
}

Available Resources and Operations

Available methods

accounts

common

  • ping - Checks API availability and version

incoming

  • list - List the received SMS messages
  • getByIds - Get the incoming messages by IDs

outgoing

  • getByIds - Get the messages details and status by IDs
  • cancelScheduled - Cancel a scheduled messages
  • list - Lists the history of sent messages

outgoing->mms

  • getPrice - Check the price of MMS Messages
  • send - Send MMS Messages

outgoing->sms

  • getPrice - Check the price of SMS Messages
  • send - Send SMS Messages

senders

  • list - List allowed senders names
  • add - Add a new sender name
  • delete - Delete a sender name
  • setDefault - Set default sender name

Error Handling

Handling errors in this SDK should largely match your expectations. All operations return a response object or throw an exception.

By default an API error will raise a Errors\SDKException exception, which has the following properties:

When custom error responses are specified for an operation, the SDK may also throw their associated exception. You can refer to respective Errors tables in SDK docs for more details on possible exception types for each operation. For example, the get method throws the following exceptions:

Example

declare(strict_types=1);

require 'vendor/autoload.php';

use Gsmservice\Gateway;

$security = '<YOUR API ACCESS TOKEN>';

$sdk = Gateway\Client::builder()->setSecurity($security)->build();

try {
    $response = $sdk->accounts->get(

    );

    if ($response->accountResponse !== null) {
        // handle response
    }
} catch (Errors\ErrorResponseThrowable $e) {
    // handle $e->$container data
    throw $e;
} catch (Errors\SDKException $e) {
    // handle default exception
    throw $e;
}

Server Selection

Server Selection

Select Server by Name

You can override the default server globally by passing a server name to the server: str optional parameter when initializing the SDK client instance. The selected server will then be used as the default on the operations that use it. This table lists the names associated with the available servers:

Override Server URL Per-Client

The default server can also be overridden globally by passing a URL to the server_url: str optional parameter when initializing the SDK client instance. For example:

Development

Maturity

This SDK is in continuous development and there may be breaking changes between a major version update. Therefore, we recommend pinning usage to a specific package version. This way, you can install the same version each time without breaking changes unless you are intentionally looking for the latest version.

Contributions

While we value open-source contributions to this SDK, this library is generated programmatically. Any manual changes added to internal files will be overwritten on the next generation. We look forward to hearing your feedback. Feel free to open a PR or an issue with a proof of concept and we'll do our best to include it in a future release.