softsmart/smsportal-laravel

Integration package for SMSPortal into Laravel.

1.1.1 2023-01-10 12:37 UTC

This package is auto-updated.

Last update: 2024-09-10 16:32:33 UTC


README

Latest Version on Packagist Total Downloads

Third party package created to consume the SMSPortal RESTful API to send SMS's to phone numbers.

Installation

You can install the package via composer:

composer require softsmart/smsportal-laravel

Set these .env variables:

SMSPORTAL_BASE_URL=https://rest.smsportal.com/v1
SMSPORTAL_CLIENT_ID=
SMSPORTAL_SECRET=
SMSPORTAL_TEST_MODE=true/false

You can find your client id & secret in your SMSPortal control panel.

Usage

// To send a message to a single phone number
SMSPortal::sendMessage('0112223333', 'Hello world!');

// To send a message to a single phone number later
// NOTES: even though replacements is not used for single SMS we still need to
// account for its place (this may change with named parameters in PHP8 in later versions)
// date time is a string in GMT+2 timezone
SMSPortal::sendMessage('0112223333', 'Hello world!', [], "2023-01-12 12:34:33");
// To send a message to a multiple phone numbers (without text replacements)

$numbers = [
    "0000000000",
    "00000000001",
];

SMSPortal::sendMessage($numbers, 'Hello world!');

// To send a message to a multiple phone numbers later
// NOTES: must account for replacements place (this may change with named parameters in PHP8 in later versions)
// date time is a string in GMT+2 timezone
SMSPortal::sendMessage($numbers, 'Hello world!', [], "2023-01-12 12:34:33");
// To send a message to a multiple phone numbers (with text replacements)
// Replacements must be an array of array arrays with a key attribute and a value attribute
// Its up to you to determine the key, in this is its ::first_name:: but it could be {first_name}, etc.

$numbers = [
    "0000000000",
    "0000000001",
];

$replacements = [
    // first replacement
    [
        [
            "key"   => "::first_name::",
            "value" => "John"
        ],
        [
            "key"   => "::weather::",
            "value" => "hot",
        ]
    ],
    // second replacement
    [
        [
            "key"   => "::first_name::",
            "value" => "Alice"
        ],
        [
            "key"   => "::weather::",
            "value" => "cold",
        ]
    ],
]

SMSPortal::sendMessage($numbers, 'Hello ::first_name::, today is ::weather::!', $replacements);

// To send a message to a multiple phone numbers later
// date time is a string in GMT+2 timezone
SMSPortal::sendMessage($numbers, 'Hello ::first_name::, today is ::weather::!', $replacements, "2023-01-12 12:34:33");

Changelog

Please see CHANGELOG for more information what has changed recently.

Contributing

Please see CONTRIBUTING for details.

Security

If you discover any security related issues, please make use of the issue tracker.

Credits

License

The MIT License (MIT). Please see License File for more information.