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

Symfony Turbosms Laravel Package

avator/symfony-turbosms

View on GitHub
Deep Wiki
Context7

Getting Started

Minimal Setup

  1. Install the Bundle
    composer require avator/symfony-turbosms
    
  2. Register the Bundle Add to app/AppKernel.php:
    new AVATOR\TurbosmsBundle\AVATORTurbosmsBundle(),
    
  3. Configure Add to config.yml:
    avator_turbosms:
        login: 'your_turbosms_login'
        password: 'your_turbosms_password'
        sender: 'YourSenderName'
        debug: false
        save_to_db: true
    
  4. Create Database Tables Run:
    php bin/console doctrine:schema:update --dump-sql
    
    Review SQL, then execute --force if needed.

First Use Case

Send an SMS in a controller:

use AVATOR\TurbosmsBundle\Service\TurbosmsService;

class DefaultController extends Controller
{
    public function sendSmsAction()
    {
        $turbosms = $this->get('avator_turbosms.turbosms');
        $success = $turbosms->send("Hello via Turbosms!", "+380991234567");
        return new Response($success ? 'SMS sent!' : 'Failed');
    }
}

Implementation Patterns

Core Workflow

  1. Service Injection Use dependency injection to access the service:

    $turbosms = $this->container->get('avator_turbosms.turbosms');
    

    Or via autowiring (Symfony 3.3+):

    use AVATOR\TurbosmsBundle\Service\TurbosmsService;
    
    public function __construct(TurbosmsService $turbosms) {
        $this->turbosms = $turbosms;
    }
    
  2. Sending SMS Basic usage:

    $this->turbosms->send("Message", "+380991234567");
    

    With options (if extended):

    $this->turbosms->send("Message", "+380991234567", ['priority' => 'high']);
    
  3. Database Logging If save_to_db: true, logs are stored in avator_turbosms_message table. Query logs via:

    $logs = $this->getDoctrine()->getRepository('AVATORTurbosmsBundle:Message')->findAll();
    
  4. Debug Mode Set debug: true to prevent actual sends (useful for testing).

Integration Tips

  • Event Listeners Trigger actions post-send (e.g., notifications):
    services:
        app.turbosms_listener:
            class: AppBundle\EventListener\TurbosmsListener
            tags:
                - { name: kernel.event_listener, event: avator.turbosms.post_send, method: onPostSend }
    
  • Batch Processing Loop through recipients:
    $recipients = ['+380991234567', '+380991234568'];
    foreach ($recipients as $phone) {
        $this->turbosms->send("Batch message", $phone);
    }
    
  • Validation Validate phone numbers before sending (e.g., using libphonenumber):
    use libphonenumber\PhoneNumberUtil;
    $phoneUtil = PhoneNumberUtil::getInstance();
    $phone = $phoneUtil->parse($phoneNumber);
    if (!$phoneUtil->isValidNumber($phone)) {
        throw new \InvalidArgumentException("Invalid phone number");
    }
    

Gotchas and Tips

Pitfalls

  1. Deprecated Symfony Version

    • The package targets Symfony 2.6–3.x. Do not use with Symfony 5+ without forking/updating.
    • SOAP client may fail if Turbosms updates their WSDL. Check for errors like:
      catch (\SoapFault $fault) {
          // Handle SOAP errors (e.g., login/password mismatch)
      }
      
  2. Database Schema

    • The doctrine:schema:update step is critical. Skipping it will cause EntityManager errors.
    • If tables exist but are misconfigured, drop them manually:
      php bin/console doctrine:schema:drop --force
      
  3. Debug Mode Misuse

    • debug: true blocks all sends. Forgetting to disable it in production will silently fail SMS delivery.
  4. Character Limits

    • Turbosms has a 70-character limit per SMS. Longer messages auto-split (but may incur extra costs). Test with:
      $this->turbosms->send(str_repeat("a", 100), "+380991234567");
      
  5. Sender Restrictions

    • Turbosms may block certain sender names (e.g., "INFO"). Verify with their support before using.

Debugging

  • Enable SOAP Logging Add to config.yml:

    avator_turbosms:
        soap_debug: true
    

    Logs appear in var/log/dev.log.

  • Check Database Logs Query failed sends:

    SELECT * FROM avator_turbosms_message WHERE status = 'failed';
    
  • Test Credentials Validate login/password with Turbosms’ test API or their web panel first.

Extension Points

  1. Custom Message Class Extend AVATOR\TurbosmsBundle\Entity\Message to add fields (e.g., template_id):

    namespace AppBundle\Entity;
    use AVATOR\TurbosmsBundle\Entity\Message as BaseMessage;
    
    class Message extends BaseMessage {
        protected $templateId;
        // Add getters/setters
    }
    

    Update the bundle’s Message entity mapping in Resources/config/doctrine/Message.orm.yml.

  2. Override Service Replace the default service in services.yml:

    services:
        avator_turbosms.turbosms:
            class: AppBundle\Service\CustomTurbosmsService
            arguments: ['@avator_turbosms.client']
    
  3. Add Pre/Post-Send Hooks Use Symfony events (if the bundle supports them). Example listener:

    namespace AppBundle\EventListener;
    use AVATOR\TurbosmsBundle\Event\PostSendEvent;
    
    class TurbosmsListener {
        public function onPostSend(PostSendEvent $event) {
            if (!$event->isSuccess()) {
                // Trigger fallback (e.g., email)
            }
        }
    }
    
  4. Localization Override translation files in Resources/translations/ to customize error messages.

Performance Tips

  • Batch Writes For bulk sends, use transactions:
    $em = $this->getDoctrine()->getManager();
    $em->beginTransaction();
    try {
        foreach ($phones as $phone) {
            $this->turbosms->send("Message", $phone);
        }
        $em->commit();
    } catch (\Exception $e) {
        $em->rollBack();
        throw $e;
    }
    
  • Cache SOAP Client Reuse the SOAP client instance to avoid reconnecting:
    $client = $this->get('avator_turbosms.client');
    // Reuse $client across requests
    
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.
milito/query-filter
apiboxsym/user-bundle
apiboxsym/health-check-bundle
jayeshmepani/jpl-moshier-ephemeris-php
elnasnato/laraliveui
labrodev/rest-sdk
sampaui/sampaui
babelqueue/php-sdk
facebook/capi-param-builder-php
babelqueue/symfony
hamzi/corewatch
minionfactory/raw-hydrator
hexters/coinpayment
rjcodes/rjcms
act-training/laravel-permissions-manager
alimarchal/laravel-chart-of-accounts
babenkoivan/elastic-scout-driver
mkwebdesign/filament-watchdog-v5
renatomarinho/laravel-page-speed
zedmagdy/filament-business-hours