Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Php Client Laravel Package

smsapi/php-client

PHP client library for SMSAPI, providing a simple way to send SMS and manage messaging features from PHP applications. Suitable for integrating SMS notifications and related services into Laravel or custom PHP projects.

View on GitHub
Deep Wiki
Context7

Getting Started

Minimal Setup

  1. Installation

    composer require smsapi/php-client
    

    (Note: Since the package is archived, verify compatibility with your PHP version and Laravel setup.)

  2. Basic Configuration Create a config file (e.g., config/smsapi.php) with your API credentials:

    return [
        'api_key' => env('SMSAPI_KEY'),
        'base_url' => env('SMSAPI_BASE_URL', 'https://api.smsapi.com'),
    ];
    
  3. First Use Case: Sending a Text Message

    use Smsapi\Client;
    
    $client = new Client(config('smsapi.api_key'), config('smsapi.base_url'));
    $response = $client->sendSms(
        'from' => 'YourBrand',
        'to' => '1234567890',
        'text' => 'Hello from Laravel!'
    );
    
  4. Laravel Service Provider (Optional) Bind the client to the container for dependency injection:

    // app/Providers/AppServiceProvider.php
    public function register()
    {
        $this->app->singleton(Client::class, function ($app) {
            return new Client(config('smsapi.api_key'), config('smsapi.base_url'));
        });
    }
    

Implementation Patterns

Common Workflows

  1. Sending Bulk SMS

    $client->sendSms([
        'from' => 'YourBrand',
        'to' => ['1234567890', '0987654321'],
        'text' => 'Bulk message to multiple recipients.'
    ]);
    
  2. Handling Responses Check the response status and data:

    if ($response->isSuccess()) {
        $messageId = $response->getMessageId();
        // Log or store $messageId for tracking.
    } else {
        $error = $response->getError();
        Log::error("SMS failed: " . $error);
    }
    
  3. Laravel Notifications Integration Extend the MustBeVerified notification channel:

    // app/Notifications/SmsVerification.php
    use Smsapi\Client;
    
    public function via($notifiable)
    {
        return ['sms'];
    }
    
    public function toSms($notifiable)
    {
        return [
            'from' => 'YourBrand',
            'to' => $notifiable->phone,
            'text' => 'Your verification code: ' . $this->verificationCode,
        ];
    }
    
  4. Queueing SMS Jobs Dispatch a job for async sending:

    // app/Jobs/SendSmsJob.php
    use Smsapi\Client;
    
    public function handle(Client $client)
    {
        $client->sendSms($this->messageData);
    }
    

Integration Tips

  • Environment Variables: Use .env for sensitive data (e.g., SMSAPI_KEY).
  • Rate Limiting: Implement a queue (e.g., Laravel Queues) to avoid hitting API limits.
  • Logging: Log all SMS attempts (success/failure) for auditing.
  • Fallbacks: Combine with another SMS provider (e.g., Twilio) as a backup.

Gotchas and Tips

Pitfalls

  1. Archived Package Risks

    • No active maintenance; test thoroughly before production use.
    • Monitor for breaking changes if the underlying API evolves.
  2. Error Handling

    • The package may lack detailed error messages. Wrap calls in try-catch:
      try {
          $response = $client->sendSms(...);
      } catch (\Exception $e) {
          Log::error("SMS API error: " . $e->getMessage());
      }
      
  3. API Key Exposure

    • Avoid hardcoding keys. Use Laravel’s .env and config/services.php.
  4. Character Limits

    • SMS messages are typically limited to 160 characters. Split long messages:
      $client->sendSms([
          'from' => 'YourBrand',
          'to' => '1234567890',
          'text' => chunk_split($longText, 153, "\n"), // Split into parts
      ]);
      

Debugging Tips

  • Enable API Debugging: Check the package’s docs for a debug mode or enable HTTP logging:
    \Smsapi\Client::setDebug(true); // If supported.
    
  • Inspect Raw Responses: Dump the raw API response for troubleshooting:
    dd($response->getRawResponse());
    
  • Test with Sandbox: Use a sandbox/test API key if available.

Extension Points

  1. Custom Response Handling Extend the Response class to add domain-specific logic:

    class CustomResponse extends \Smsapi\Response
    {
        public function isDelivered()
        {
            return $this->getStatus() === 'DELIVERED';
        }
    }
    
  2. Middleware for SMS Add middleware to validate phone numbers or log metadata:

    // app/Http/Middleware/SmsValidation.php
    public function handle($request, Closure $next)
    {
        if ($request->input('to') && !preg_match('/^\d{10,15}$/', $request->input('to'))) {
            abort(422, 'Invalid phone number.');
        }
        return $next($request);
    }
    
  3. Mocking for Tests Use Laravel’s mocking to test SMS logic without hitting the API:

    $mock = Mockery::mock(Client::class);
    $mock->shouldReceive('sendSms')->once()->andReturn(new \Smsapi\Response(true));
    $this->app->instance(Client::class, $mock);
    
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
phpshko/laravel-livewire-depdrop
larasell-dev/larasell
calliostro/spotify-bundle
calmfox/watch-sylius
damienfern/grpc-symfony-bundle
atoolo/index-bundle
atoolo/genai-bundle
coprotoai/laravel-ticket
davidjln/llm-carbon-bundle
cryonighter/valid-request-bundle
coolms/taxonomy-bundle
coolms/field-bundle
articulate-orm/symfony
aaix/laravel-tall-architect
ephoto/akeneo-connector
emmanuelballery/eb-plantumlbundle
emielburgman/symfony-visitor-beacon
emielburgman/symfony-visit-storage
emielburgman/symfony-security-headers
emielburgman/symfony-log-viewer