Weave 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

Sendbird Client Laravel Package

axelbest/sendbird-client

View on GitHub
Deep Wiki
Context7

Getting Started

Minimal Setup

  1. Installation

    composer require axelbest/sendbird-client
    

    Ensure your project meets the PHP 8.0+ and Symfony 6.0+ requirements.

  2. Configuration Create a sendbird.yaml in config/packages/ (or merge into existing config):

    sendbird:
        api_key: 'YOUR_SENDBIRD_API_KEY'
        api_secret: 'YOUR_SENDBIRD_API_SECRET'
        application_id: 'YOUR_APP_ID'
        base_uri: 'https://api.sendbird.com/v3'  # Default, optional
    
  3. First Use Case Initialize the client in a service or controller:

    use Axelbest\SendbirdClient\SendbirdClient;
    
    $client = new SendbirdClient();
    $users = $client->users()->listUsers();
    

Key Entry Points

  • Service Container Integration Bind the client in config/services.yaml:
    services:
        Axelbest\SendbirdClient\SendbirdClient: '@sendbird.client'
    
    Then autowire it:
    public function __construct(private SendbirdClient $sendbird) {}
    

Implementation Patterns

Common Workflows

  1. User Management

    // Create user
    $user = $sendbird->users()->createUser('user_id', 'nickname', 'profile_url');
    
    // Update user
    $sendbird->users()->updateUser('user_id', ['nickname' => 'new_name']);
    
    // List users (paginated)
    $users = $sendbird->users()->listUsers(['limit' => 20, 'offset' => 0]);
    
  2. Channel Operations

    // Create group channel
    $channel = $sendbird->channels()->createGroupChannel(
        'channel_url',
        ['name' => 'General', 'is_distinct' => true]
    );
    
    // Send message
    $sendbird->messages()->sendUserMessage(
        'channel_url',
        'user_id',
        'Hello world!'
    );
    
  3. Webhook Handling Use Symfony’s HTTP client to verify webhooks (not wrapped by the package):

    $response = $this->httpClient->request('GET', 'https://api.sendbird.com/v3/webhooks/verify', [
        'query' => ['timestamp' => $timestamp, 'token' => $token]
    ]);
    

Integration Tips

  • Event-Driven Architecture Pair with Symfony’s Messenger component to process Sendbird webhooks asynchronously:

    $message = new SendbirdWebhookMessage($payload);
    $this->messageBus->dispatch($message);
    
  • Caching Responses Cache user/channel lists (TTL: 5–10 minutes) to reduce API calls:

    $cacheKey = "sendbird:users:{$offset}";
    return $cache->get($cacheKey, fn() => $sendbird->users()->listUsers(['offset' => $offset]));
    
  • Error Handling Wrap calls in try-catch for SendbirdException:

    try {
        $sendbird->users()->banUser('user_id');
    } catch (SendbirdException $e) {
        $this->addFlash('error', $e->getMessage());
    }
    

Gotchas and Tips

Pitfalls

  1. API Key Exposure

    • Issue: Hardcoding api_secret in sendbird.yaml risks exposure.
    • Fix: Use Symfony’s parameter_bag with environment variables:
      sendbird:
          api_secret: '%env(SENDBIRD_API_SECRET)%'
      
  2. Rate Limiting

    • Issue: Unbounded pagination (e.g., listUsers()) can hit Sendbird’s 1000-requests/minute limit.
    • Fix: Implement client-side pagination with next cursors or limit results:
      $users = $sendbird->users()->listUsers(['limit' => 100]);
      
  3. Webhook Verification

    • Issue: The package doesn’t handle webhook verification. Use Symfony’s HttpClient manually:
      $isValid = $this->httpClient->request('GET', 'https://api.sendbird.com/v3/webhooks/verify', [
          'query' => ['timestamp' => $payload['timestamp'], 'token' => $payload['token']]
      ])->getStatusCode() === 200;
      
  4. Deprecated Methods

    • Issue: The package is unmaintained (last release: 2021). Some Sendbird API endpoints may no longer align.
    • Fix: Check Sendbird’s v3 API docs for breaking changes and extend the wrapper if needed.

Debugging

  • Enable Debug Mode Set debug: true in config to log raw API responses:

    sendbird:
        debug: true
    
  • Symfony Profiler Use the VarDumper component to inspect responses:

    $users = $sendbird->users()->listUsers();
    dump($users); // Symfony's VarDumper
    

Extension Points

  1. Custom Responses Override the Serializer to transform responses:

    $client->setSerializer(new CustomSendbirdSerializer());
    
  2. Middleware Add HTTP middleware (e.g., retry logic) via Symfony’s HttpClient:

    $client->setHttpClient($httpClient->withOptions([
        'max_retries' => 3,
        'timeout' => 10,
    ]));
    
  3. Testing Mock the client in PHPUnit:

    $mockClient = $this->createMock(SendbirdClient::class);
    $mockClient->method('users')->willReturnSelf();
    $mockClient->method('listUsers')->willReturn(['users' => []]);
    
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.
adachsoft/changelog-linter
adachsoft/collection
payerurl/telegrambot-crypto-payment-instant-payout
dskripchenko/laravel-hybrid-search
riorizkyrainey/lara-ced
mehedimi/static-vel
zharp/zharp
nonsapiens/bigquery-model-sync
lgu-bayambang-ict-office/lgu-laravel-development-standards
andydefer/laravel-support
se7enxweb/flysystem
lampwick/laravel
jeslage/statamic-emojis
micahdshackelford/rmap-laravel
draftsmaninc/draftsman
square-bit/laravel-volition
himito/laravel-mailman
htinlynn/genius-helper
maco-studios/hephaestus
adachsoft/php-code-style