Download the PHP package tekkenking/swissecho without Composer
On this page you can find all versions of the php package tekkenking/swissecho. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download tekkenking/swissecho
More information about tekkenking/swissecho
Files in tekkenking/swissecho
Package swissecho
Short Description A multigateway laravel SMS notification channel package
License MIT
Informations about the package swissecho
๐จ Swissecho โ Laravel Multi-Channel Notification Package
What is Swissecho?
Swissecho is a Laravel package that provides a unified, fluent API for sending messages across multiple channels and multiple gateway providers. Instead of writing separate integration code for each provider, you configure them all in one place and switch between them with a single method call.
Supported Channels (Routes)
| Channel | Description | Supported Gateways |
|---|---|---|
| SMS | Traditional text messages | Termii, RouteMobile, SmsBroadcast (AU), TNZ (NZ), NigerianBulkSMS, Montnets, Wirepick |
| Voice | Voice OTP / voice calls | Termii, Textng.xyz |
| WhatsApp messaging | KudiSMS | |
| Slack | Slack notifications | Built-in Slack route |
Key Features
- ๐ Multi-gateway โ Switch SMS providers per-request or per-country
- ๐ Geo-routing (Places) โ Automatically route messages to the correct gateway based on the recipient's country
- ๐งช Mock mode โ In development, messages are logged to file or sent to email instead of hitting live APIs
- ๐ Laravel Notification integration โ Use it as a standard Laravel notification channel
- โก Direct sending โ Send messages without creating a Notification class
- ๐ฃ Events โ An
AfterSendevent is dispatched after every message, giving you full insight into requests and responses - ๐ช Webhooks โ Built-in webhook handling for provider callbacks (e.g., delivery reports)
Requirements
| Dependency | Supported Versions |
|---|---|
| PHP | ^8.1 |
| Laravel | 11.x, 12.x, 13.x |
Installation
The package auto-discovers itself via Laravel's package auto-discovery โ no manual registration needed.
Configuration
Environment Variables
Add these to your .env file. Only configure the gateways you plan to use:
The Config File
You can publish and customize the full config at config/swissecho.php. The most important sections are:
| Key | Purpose |
|---|---|
live |
true = send real messages; false = mock mode |
sender |
Default sender ID/name |
fake |
Mock strategy: "log" or "mail" |
route |
Default channel: sms, voice, whatsapp, or slack |
routes_options |
Per-channel gateway definitions and geo-routing rules |
Geo-Routing with places
Each route (SMS, voice, WhatsApp) has a places map that automatically picks the right gateway based on the recipient's country:
The phone code is automatically prepended to phone numbers (stripping leading 0 or +).
๐ Adding a Custom SMS Gateway
Swissecho is designed to be easily extensible. If you need a gateway that isn't built in, you can wire up your own in three steps โ no need to touch the package source at all.
Step 1: Create Your Gateway Class
Create a folder anywhere in your project (e.g., app/Sms/Gateways/MyProvider/) and add a class inside it. The class must:
- Extend
Tekkenking\Swissecho\Routes\Sms\Gateways\BaseGateway - Implement two methods:
init()andsend()
How it works under the hood: after
send()returns the cURL handle, Swissecho'sSwissechoGatewayTrait::execCurl()callscurl_exec(), collects the response, formats it, and fires theAfterSendevent.
Step 2: Register the Gateway in the Config
Open config/swissecho.php and add your gateway to the routes_options.sms.gateway_options array:
Add the corresponding values to your .env:
Step 3: Use Your Gateway
That's it โ your gateway is now a first-class citizen in Swissecho. Use it exactly like any built-in gateway:
You can also map it to a country in places for automatic geo-routing:
BaseGateway Quick Reference
| Member | Type | Description |
|---|---|---|
$this->to |
array |
Recipient phone numbers |
$this->sender |
string |
Sender ID / name |
$this->body |
string |
The message text |
$this->config |
array |
Your gateway's full config block from swissecho.php |
init(): mixed |
abstract method | Build the request payload; return value is passed to send() |
send($data): \CurlHandle|bool |
abstract method | Set up and return a cURL handle; Swissecho executes it |
Usage
Swissecho can be used in two ways: directly (without a Notification class), or through Laravel's notification system.
Access Methods
You have three ways to get a Swissecho instance:
A) Direct Sending (Without Notification Classes)
Quick Send โ One Liner
The simplest way to send a message. Uses the default route and default gateway from config:
Quick Send with a Specific Gateway
Fluent Builder โ Full Control
Property-Based Sending
You can also set properties directly on the Swissecho instance:
Sending via WhatsApp
Sending via Slack
Sending via Voice Call
B) Laravel Notification Channel Integration
Swissecho integrates with Laravel's built-in notification system. Create a notification class and define a toSms (or toVoice, toWhatsapp, toSlack) method:
Step 1: Create the Notification
Step 2: Make Your User Model "Notifiable"
Swissecho pulls the phone number from the notifiable model. Implement one of these:
Step 3: Send the Notification
SwissechoMessage API Reference
The SwissechoMessage class is the message builder used in callbacks and notification methods:
| Method | Description | Example |
|---|---|---|
->line($text) |
Appends a line of text to the message body. Multiple calls add new lines. | ->line('Hello') |
->content($text) |
Alias for line(). |
->content('Hello') |
->to($recipient) |
Sets the recipient(s). Accepts a string or comma-separated list. | ->to('234801..., 234809...') |
->sender($name) |
Sets the sender ID (max 10 characters). | ->sender('MyApp') |
->from($name) |
Alias for sender(). |
->from('MyApp') |
->gateway($name) |
Overrides the gateway for this message. | ->gateway('termii') |
->place($code) |
Sets the country/place code (e.g., 'nga'). Overrides auto-detection. | ->place('nga') |
->phonecode($code) |
Manually sets the phone country code (e.g., '234'). | ->phonecode('234') |
->identifier($id) |
Attaches an identifier (e.g., user ID) to the message for tracking. | ->identifier($user->id) |
->route($name) |
Sets the route/channel on the message itself. | ->route('sms') |
Mock Mode (Development & Testing)
When SWISSECHO_ENABLED=false (the default), no real API calls are made. Instead, messages are captured by the mock system.
Mock via Log (Default)
Messages are written to storage/logs/swissecho_mock.log:
The log includes: sender, recipient, message body, route, gateway, gateway class, country, and phone code.
Mock via Email
Messages are emailed to the configured address:
Events
After every message send (including mock sends), Swissecho dispatches the AfterSend event:
Event Properties
| Property | Type | Description |
|---|---|---|
$insightPayload |
array |
Contains request (the payload sent to the gateway) and response (raw gateway response) |
$formattedResponse |
array |
Structured response with status, partner_response, from, to, body, route, gateway, identifier, timestamp |
$identifier |
mixed |
The identifier attached to the message (e.g., user ID) |
Listening to the Event
Webhooks
Swissecho includes a built-in webhook handler for receiving delivery reports or callbacks from gateway providers. The webhook system validates a secret key and routes the request to the appropriate gateway handler.
Configure webhooks per gateway in config/swissecho.php:
Helper Functions
Swissecho provides global helper functions for phone number manipulation:
| Function | Description |
|---|---|
swissecho() |
Returns the Swissecho singleton instance |
addCountryCodeToPhoneNumber($phone, $code) |
Prepends a country code (e.g., '234') to a phone number, stripping leading 0 or + |
removeCountryCodeFromPhoneNumber($phone, $code) |
Strips a country code prefix from a phone number |
convertPhoneNumberToArray($phone) |
Splits a comma-separated phone string into an array |
Examples
License
This package is open-sourced software licensed under the MIT license.