symfony/octopush-notifier
Symfony Notifier transport for Octopush SMS. Configure with an octopush:// DSN using your Octopush email and API key, plus sender and SMS type (LowCost, Premium, World) to send SMS notifications through Octopush.
Install Dependencies (if using Symfony Notifier):
composer require symfony/http-client symfony/notifier symfony/octopush-notifier
For minimal risk, skip symfony/notifier and use Laravel’s Http facade instead.
Configure DSN in .env:
OCTOPUSH_DSN=octopush://USERLOGIN:APIKEY@default?from=YOUR_SENDER&type=FR
USERLOGIN with your Octopush email.APIKEY with your Octopush API token.from = Sender ID (e.g., "+1234567890" or "YourApp").type = SMS route (XXX for LowCost, FR for Premium, WWW for World).First Use Case: Send an SMS Option A (Direct HTTP - Recommended for Laravel):
use Illuminate\Support\Facades\Http;
$response = Http::withOptions(['auth' => [env('OCTOPUSH_USER'), env('OCTOPUSH_KEY')]])
->post('https://api.octopush.com/sms', [
'to' => '+33612345678',
'message' => 'Hello from Laravel!',
'from' => env('OCTOPUSH_FROM'),
'type' => env('OCTOPUSH_TYPE', 'FR'),
]);
Option B (Symfony Notifier - Higher Risk):
use Symfony\Component\Notifier\NotifierInterface;
use Symfony\Component\Notifier\Message\SmsMessage;
$notifier = new NotifierInterface([new OctopushTransport(env('OCTOPUSH_DSN'))]);
$notifier->send(new SmsMessage('Hello from Symfony!', '+33612345678'));
Verify Credentials:
from formats (e.g., alphanumeric sender IDs may require approval).XXX) first.Pattern: Use Laravel’s Http facade for simplicity.
// app/Services/OctopushService.php
class OctopushService {
public function send(string $to, string $message): bool {
$response = Http::post('https://api.octopush.com/sms', [
'to' => $to,
'message' => $message,
'from' => config('services.octopush.from'),
'type' => config('services.octopush.type'),
])->auth(config('services.octopush.login'), config('services.octopush.key'));
return $response->successful();
}
}
Usage:
OctopushService::send('+33612345678', 'Your verification code: 12345');
Pattern: Dispatch a job to avoid blocking the request.
// app/Jobs/SendOctopushSms.php
class SendOctopushSms implements ShouldQueue {
use Dispatchable, InteractsWithQueue, Queueable;
public function handle() {
Http::post('https://api.octopush.com/sms', [
'to' => $this->to,
'message' => $this->message,
// ... other params
]);
}
}
Dispatch:
SendOctopushSms::dispatch('+33612345678', 'Your order is confirmed!');
Pattern: Useful if already using Symfony’s Notifier for multi-channel notifications.
// config/services.php
'octopush' => [
'dsn' => env('OCTOPUSH_DSN'),
],
// app/Providers/AppServiceProvider.php
public function register() {
$this->app->singleton('octopush.transport', function () {
return new \Symfony\Component\Notifier\Transport\OctopushTransport(
env('OCTOPUSH_DSN')
);
});
}
Usage:
$notifier = new \Symfony\Component\Notifier\Notifier([
$this->app->make('octopush.transport'),
]);
$notifier->send(new \Symfony\Component\Notifier\Message\SmsMessage(
'Hello via Symfony!',
'+33612345678'
));
Pattern: Override from or type per message.
$response = Http::withOptions([
'auth' => [env('OCTOPUSH_USER'), env('OCTOPUSH_KEY')],
'query' => [
'from' => 'DynamicSender',
'type' => 'WWW', // World SMS
],
])->post('https://api.octopush.com/sms', [
'to' => '+33612345678',
'message' => 'Global message!',
]);
.env:
OCTOPUSH_LOGIN=your_email@example.com
OCTOPUSH_KEY=your_api_token
OCTOPUSH_FROM=YourApp
OCTOPUSH_TYPE=FR
400 for invalid from, 429 for rate limits). Handle gracefully:
$response = Http::post(...)->throwUnlessSuccessful();
if (!$response->successful()) {
\Log::error('Octopush failed', [
'status' => $response->status(),
'body' => $response->body(),
'to' => $to,
]);
}
use Symfony\Component\Mime\Header\UnstructuredHeader;
$response = Http::withHeaders([
'X-RateLimit-Retry-After' => new UnstructuredHeader('Retry-After'),
])->post(...);
Sender ID Restrictions:
"MyApp") require pre-approval from Octopush. Use numeric IDs (e.g., "+1234567890") for testing.DSN Format Sensitivity:
octopush://USER:KEY@default?from=FROM&type=TYPE) must include @default and query params. Missing these causes:
new \Symfony\Component\Notifier\Exception\TransportException('Invalid DSN')
OCTOPUSH_DSN=octopush://user:key@default?from=Sender&type=FR
Symfony Dependency Conflicts:
guzzlehttp/guzzle, symfony/http-client may conflict. Symptom:
Composer could not find a compatible version of guzzlehttp/guzzle.
Http facade instead of Symfony’s Notifier.Character Limits:
type=FR) for longer messages.API Key Exposure:
new \Symfony\Component\Notifier\Exception\TransportException('Invalid credentials')
.env and avoid exposing keys in logs:
// In OctopushTransport (if extending)
$this->client->setCredentials(
env('OCTOPUSH_LOGIN'),
env('OCTOPUSH_KEY')
);
Timeouts:
cURL error 28: Connection timed out
How can I help you explore Laravel packages today?