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

Api Social Bundle Laravel Package

antwebes/api-social-bundle

View on GitHub
Deep Wiki
Context7

Getting Started

Minimal Setup

  1. Installation

    composer require antwebes/api-social-bundle
    

    Ensure Antwebes\ApiSocialBundle\AntwebesApiSocialBundle is enabled in config/bundles.php:

    return [
        // ...
        Antwebes\ApiSocialBundle\AntwebesApiSocialBundle::class => ['all' => true],
    ];
    
  2. Configuration Publish the default config:

    php bin/console config:dump-reference AntwebesApiSocialBundle
    

    Update config/packages/antwebes_api_social.yaml with your Chatsfree API credentials (client ID, secret, etc.).

  3. First Use Case: Authenticate a User Inject the ChatsfreeClient service in a controller:

    use Antwebes\ApiSocialBundle\Service\ChatsfreeClient;
    
    class ChatController extends AbstractController
    {
        public function __construct(private ChatsfreeClient $chatsfreeClient) {}
    
        public function login(User $user)
        {
            $token = $this->chatsfreeClient->authenticate([
                'username' => $user->getEmail(),
                'password' => $user->getPlainPassword(),
            ]);
            return new JsonResponse(['token' => $token]);
        }
    }
    

Implementation Patterns

Core Workflows

  1. User Authentication Use ChatsfreeClient::authenticate() to generate tokens for Chatsfree API calls:

    $token = $this->chatsfreeClient->authenticate([
        'username' => 'user@example.com',
        'password' => 'secure123',
    ]);
    
  2. Chat Session Management Create/join chat rooms via ChatsfreeClient::createChat():

    $chatId = $this->chatsfreeClient->createChat([
        'title' => 'Support Room',
        'participants' => [$user1->getId(), $user2->getId()],
    ]);
    
  3. Message Handling Send/retrieve messages using ChatsfreeClient::sendMessage() and ChatsfreeClient::getMessages():

    $this->chatsfreeClient->sendMessage($chatId, 'Hello!');
    $messages = $this->chatsfreeClient->getMessages($chatId);
    

Integration Tips

  • Event Listeners: Extend functionality by listening to chatsfree.token.refresh events (if supported).
  • Dependency Injection: Prefer constructor injection for ChatsfreeClient in services/controllers.
  • Caching: Cache API responses (e.g., user profiles) using Symfony’s cache system:
    $cache = $this->container->get('cache.app');
    $profile = $cache->get('chatsfree_profile_' . $userId, function() use ($userId) {
        return $this->chatsfreeClient->getUserProfile($userId);
    });
    

Gotchas and Tips

Common Pitfalls

  1. API Rate Limits

    • Chatsfree may throttle requests. Implement exponential backoff in retries:
      try {
          $response = $this->chatsfreeClient->createChat($data);
      } catch (RateLimitException $e) {
          sleep($e->getRetryAfter());
          retry();
      }
      
  2. Token Expiry

    • Tokens expire; handle TokenExpiredException by refreshing:
      try {
          $this->chatsfreeClient->sendMessage($chatId, 'Hi');
      } catch (TokenExpiredException $e) {
          $this->chatsfreeClient->refreshToken();
          retry();
      }
      
  3. Configuration Overrides

    • Ensure antwebes_api_social.yaml is merged correctly. Use dump-reference to verify:
      php bin/console config:dump-reference AntwebesApiSocialBundle
      

Debugging Tips

  • Enable API Logging Set debug: true in config to log raw API responses:
    antwebes_api_social:
        debug: true
    
  • Mocking for Tests Use Mockery to stub ChatsfreeClient in unit tests:
    $mock = Mockery::mock(ChatsfreeClient::class);
    $mock->shouldReceive('authenticate')->andReturn('mock_token');
    $this->container->set('antwebes.chatsfree.client', $mock);
    

Extension Points

  1. Custom API Endpoints Extend Antwebes\ApiSocialBundle\Service\ChatsfreeClient to add unsupported endpoints:

    class CustomChatsfreeClient extends ChatsfreeClient
    {
        public function customEndpoint(array $data)
        {
            return $this->request('POST', '/custom', $data);
        }
    }
    

    Register as a service in services.yaml:

    services:
        App\Service\CustomChatsfreeClient:
            decorates: 'antwebes.chatsfree.client'
    
  2. Event Dispatching Dispatch custom events (e.g., chatsfree.message.sent) by extending the bundle’s event system (if not natively supported).

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.
emuniq/filament-browser-notifications
syriable/filament-translator
hungnm28/livewire-form
wenprise/eloquent
crudly/encrypted
fadion/bouncy
cuci/prototurk-sdk
gos/pubsub-router-bundle
cuci/prototurk-sdk-symfony
clementtalleu/easyadmin-markdown-bundle
codeflextech/permission-manager
karnoweb/livewire-datepicker
sayedenam/sayed-dashboard
milito/query-filter
apiboxsym/user-bundle
apiboxsym/health-check-bundle
jayeshmepani/jpl-moshier-ephemeris-php
elnasnato/laraliveui
labrodev/rest-sdk
sampaui/sampaui