graystackit / laravel-smstools-api
Laravel package for integrating the Smstools API (www.smstools.at)
Package info
github.com/GraystackIT/laravel-smstools-api
pkg:composer/graystackit/laravel-smstools-api
Requires
- php: ^8.3
- illuminate/support: ^11.0|^12.0|^13.0
- saloonphp/saloon: ^4.0
Requires (Dev)
- laravel/pint: ^1.0
- orchestra/testbench: ^9.0|^10.0|^11.0
- pestphp/pest: ^3.0
- pestphp/pest-plugin-laravel: ^3.0
Suggests
None
Provides
None
Conflicts
None
Replaces
None
This package is auto-updated.
Last update: 2026-11-23 07:11:06 UTC
README
A Laravel package for the Smstools API, built on Saloon 4.
Send SMS messages to single or multiple recipients, schedule delivery, use test mode, and route through subaccounts — all with a clean, Laravel-native interface.
Requirements
- PHP 8.3+
- Laravel 11, 12, or 13
Installation
composer require graystackit/laravel-smstools-api
Laravel auto-discovers the service provider and registers the Smstools facade. Then publish the config file:
php artisan vendor:publish --tag=smstools-config
Configuration
Add the following to your .env file:
SMSTOOLS_CLIENT_ID=your-client-id SMSTOOLS_CLIENT_SECRET=your-client-secret # Optional — defaults shown SMSTOOLS_BASE_URL=https://api.smsgatewayapi.com/v1 SMSTOOLS_TIMEOUT=30
Obtain your credentials from the Smstools dashboard under Advanced → API authentication.
If SMSTOOLS_CLIENT_ID or SMSTOOLS_CLIENT_SECRET is not set, a RuntimeException is thrown when the client is first resolved from the container.
Usage
Inject SmstoolsClient via the constructor, resolve it from the container, or use the Smstools facade.
Send to a single recipient
use GraystackIT\SmstoolsApi\Facades\Smstools; $result = Smstools::messages()->send( to: '436501234567', message: 'Hello from Laravel!', sender: 'MyApp', ); echo $result['messageid']; // h2md1ewkyzjkuyn9ak7pryw1evtyw3x
Send to multiple recipients
$result = Smstools::messages()->send( to: ['436501234567', '436501234568'], message: 'Hello everyone!', sender: 'MyApp', ); echo count($result['messageids']); // 2
Schedule a message
$result = Smstools::messages()->send( to: '436501234567', message: 'Your appointment is tomorrow.', sender: 'MyApp', date: '2026-06-01 09:00', );
All optional parameters
$result = Smstools::messages()->send( to: '436501234567', message: 'Test message', sender: 'MyApp', date: '2026-06-01 10:00', // Scheduled send time (yyyy-MM-dd HH:mm) reference: 'order-999', // Custom reference string (max 255 chars) test: true, // Validate without sending — no credits used subid: 42, // Send from a specific subaccount partner: 'yourslug', // Integration partners only: the slug Smstools assigned ); // The API may add a `warnings` entry, e.g. for an unknown partner slug. $result['warnings'] ?? [];
Send a stored message template
Instead of a text, send one of your message templates — preferably by its public ID (tpl_...,
from Smstools::templates()->list()). Its placeholders such as [FIRSTNAME] are filled per
recipient. A template with an attachment can only go out through WhatsApp; the API refuses it here
with error 169, and an unknown template with error 150.
$result = Smstools::messages()->sendTemplate( to: ['436501234567', '436509876543'], template: 'tpl_3520a1ec234dbabe1232def67e858855', sender: 'MyApp', );
sendTemplate() takes the same optional parameters as send().
Using dependency injection
use GraystackIT\SmstoolsApi\SmstoolsClient; class SmsController extends Controller { public function __construct(private SmstoolsClient $sms) {} public function notify(): void { $this->sms->messages()->send( to: '436501234567', message: 'Your order has shipped.', sender: 'MyShop', ); } }
Error handling
All API errors throw GraystackIT\SmstoolsApi\Exceptions\SmstoolsException (extends RuntimeException).
use GraystackIT\SmstoolsApi\Exceptions\SmstoolsException; try { $result = Smstools::messages()->send( to: '436501234567', message: 'Hello', sender: 'MyApp', ); } catch (SmstoolsException $e) { echo $e->getMessage(); // Human-readable error from the API error code map echo $e->getStatusCode(); // HTTP status code (e.g. 400, 401) echo $e->getApiErrorCode(); // Smstools API error code (e.g. 104, 108) or null echo $e->getApiErrorMessage(); // The API's own errorMsg, naming the value at fault, or null }
Common API error codes
| Code | Meaning |
|---|---|
| 104 | Invalid credentials |
| 108 | Not enough credits |
| 109 | Sender name cannot be empty |
| 111 | Invalid sender name (max 11 chars or 14 digits) |
| 118 | Message exceeds 612 characters |
| 121 | Scheduled date is invalid or in the past |
| 131 | Number is on the opt-out list |
| 150 | Message template not found |
| 169 | Message template has an attachment (WhatsApp only) |
| 200 | IP address not allowed |
The exception maps every code Smstools documents (102–169, 200, 1002); an unknown code falls back
to the API's errorMsg.
Contact Management
Manage contacts via Smstools::contacts() (or inject SmstoolsClient).
use GraystackIT\SmstoolsApi\Facades\Smstools; // Add a contact $result = Smstools::contacts()->add( phone: '436501234567', groupid: 5, firstname: 'Jane', // optional lastname: 'Doe', // optional ); echo $result['ID'][0]; // new contact ID (also $result['public_ID'][0]) // Update a contact (only pass fields you want to change) — by numeric or public ID Smstools::contacts()->update( id: 42, firstname: 'Janet', phone: '436509876543', ); // Search contacts $result = Smstools::contacts()->search( query: 'Jane', groupid: 5, // optional filter limit: 100, page: 1, ); // List all contacts $result = Smstools::contacts()->list( groupid: 5, // optional filter limit: 100, page: 1, ); // Remove a contact Smstools::contacts()->remove(42);
Account Operations
// Account details $account = Smstools::account()->details(); // Credit balance $balance = Smstools::account()->balance(); echo $balance['balance']; // '42.50' echo $balance['currency']; // 'EUR' // History of sent messages $history = Smstools::account()->history( limit: 100, // 1–2000 page: 1, ); // `from`/`to` are still accepted and sent, but Smstools no longer documents them for this // endpoint, so the API may ignore them — don't rely on them to filter. // Inbox — all messages across all inboxes $inbox = Smstools::account()->inbox( limit: 100, page: 1, type: 'sms', // optional: "sms", "whatsapp", or "call" ); // Inbox — messages from a specific inbox number $inbox = Smstools::account()->inboxByNumber( inboxNr: 1, limit: 100, page: 1, type: 'sms', // optional: "sms", "whatsapp", or "call" ); // Statistics $stats = Smstools::account()->statistics( year: '2024', // optional, YYYY format month: '01', // optional, MM format ); echo $stats['sent']; echo $stats['delivered'];
Message Templates
// Add a template ([FIRSTNAME] and other placeholders are filled on send) $result = Smstools::templates()->add( message: 'Hi [FIRSTNAME], welcome to MyApp!', order: 1, title: 'Welcome', // optional ); echo $result['public_ID'][0]; // tpl_... — use it with messages()->sendTemplate() // Update a template (only pass fields to change) — by numeric or public ID Smstools::templates()->update( id: 'tpl_c6dab1d038504ac910f1254f20383622', message: 'Hi [FIRSTNAME]! Welcome.', order: 2, ); // List all templates $result = Smstools::templates()->list(); // Get a specific template $template = Smstools::templates()->get(10); echo $template['title']; echo $template['message']; // Remove a template Smstools::templates()->remove('tpl_c6dab1d038504ac910f1254f20383622');
Birthday Messages
A birthday message is a schedule for a contact group, not a message to one person: Smstools
sends it automatically to every contact of the group on that contact's birthday (from the
contact's birthday field), shifted by offsetDays, at the given hour.
// Schedule a birthday message for group 3, sent at 07:00 on the birthday $result = Smstools::birthdayMessages()->add( message: 'Happy Birthday [FIRSTNAME]! 🎂', hour: 7, // 0–23 groupid: 3, // numeric or public group ID (gid_...) sender: 'MyApp', ); echo $result['public_ID'][0]; // bdy_... // A reminder three days before, paused for now Smstools::birthdayMessages()->add( message: 'Almost your birthday, [FIRSTNAME]!', hour: 9, groupid: 3, sender: 'MyApp', offsetDays: -3, // negative: before the birthday active: false, // sent as status 0 ); // List all birthday messages $result = Smstools::birthdayMessages()->list(); // Get a specific birthday message — by numeric or public ID $entry = Smstools::birthdayMessages()->get('bdy_c6dab1d038504ac910f1254f20383622'); echo $entry['hour']; echo $entry['offset_days']; // Update a birthday message (only pass fields to change) Smstools::birthdayMessages()->update( id: 7, hour: 8, active: true, ); // Remove a birthday message Smstools::birthdayMessages()->remove(7);
Opt-out Management
// List all opt-out numbers $result = Smstools::optouts()->list(limit: 100, page: 1); // Add a number to the opt-out list Smstools::optouts()->add('436501234567'); // Remove a number from the opt-out list Smstools::optouts()->remove('436501234567');
Webhooks
Register and manage webhook endpoints that Smstools will call on SMS events.
use GraystackIT\SmstoolsApi\Facades\Smstools; use GraystackIT\SmstoolsApi\Enums\WebhookMethod; // List all registered webhooks $result = Smstools::webhooks()->list(); foreach ($result['webhooks'] as $hook) { echo $hook['id'] . ': ' . implode(', ', $hook['webhook_types']) . ' → ' . $hook['webhook_endpoint']; } // Create a webhook $result = Smstools::webhooks()->create( webhookEndpoint: 'https://yourapp.com/sms/webhook', webhookMethod: WebhookMethod::Post, webhookTypes: ['sms_inbound', 'sms_delivered'], ); echo $result['secret']; // shared secret for signature verification // Delete a webhook by its secret token (returned when the webhook was created) Smstools::webhooks()->delete('ccc14fb1-bf8c-4ebf-882c-caccd4c95a2c');
Verifying webhook signatures
Smstools signs every webhook (v2) request with the endpoint's secret:
X-Smstools-Signature: t={timestamp},v1={hex HMAC-SHA256 of "{t}.{raw body}"}. Verify it on the
raw body, before decoding the JSON; for GET webhooks pass the url-encoded query string instead.
Signatures older than 5 minutes are rejected by default to block replays.
use GraystackIT\SmstoolsApi\Facades\Smstools; use Illuminate\Http\Request; public function __invoke(Request $request) { $valid = Smstools::verifyWebhookSignature( payload: $request->getContent(), signatureHeader: $request->header('X-Smstools-Signature'), secret: config('services.smstools.webhook_secret'), ); abort_unless($valid, 401); // ... handle $request->json() }
Endpoints created without webhooks v2 are not signed at all. On a v2 endpoint, treat a missing
signature as invalid — verifyWebhookSignature() returns false for it. The check is also
available without the container as GraystackIT\SmstoolsApi\Webhooks\WebhookSignature::verify().
Testing
Tests use Saloon's MockClient — no real API calls are made.
use GraystackIT\SmstoolsApi\Connectors\SmstoolsConnector; use GraystackIT\SmstoolsApi\Requests\SendMessageRequest; use GraystackIT\SmstoolsApi\SmstoolsClient; use Saloon\Http\Faking\MockClient; use Saloon\Http\Faking\MockResponse; $mockClient = new MockClient([ SendMessageRequest::class => MockResponse::make( ['messageid' => 'abc123'], 200 ), ]); $connector = new SmstoolsConnector('client-id', 'client-secret'); $connector->withMockClient($mockClient); $result = (new SmstoolsClient($connector))->messages()->send( to: '436501234567', message: 'Hello', sender: 'MyApp', );
Run the package test suite:
vendor/bin/pest
Every API test answers through MockClient, and tests/TestCase.php sets placeholder credentials
when SMSTOOLS_CLIENT_ID / SMSTOOLS_CLIENT_SECRET are not set, so no real credentials are needed.
License
MIT.