- Does this package support Twitter’s API v2 (now X API) with OAuth 2.0 Bearer Tokens?
- No, this package was last updated in 2021 and uses Twitter API v1.1 authentication (OAuth 1.0a). Twitter’s API v2 requires OAuth 2.0 Bearer Tokens, so you’ll need to fork or rewrite the package to support it. Start by updating endpoints and auth logic using `symfony/http-client`.
- How do I integrate this with Laravel queues for async tweet processing?
- Use Laravel’s queue system by dispatching a job when a tweet is received. For example, trigger a `TweetReceived` event in the `whenHears` callback, then listen to that event in a queued job. This decouples stream processing from your main app. Requires Laravel 8+ with Redis or database queues.
- Can I use this package in a serverless environment like AWS Lambda?
- Yes, but you’ll need to handle cold starts and connection timeouts manually. The package maintains a persistent HTTP connection, which may not work well with Lambda’s ephemeral nature. Consider using a wrapper to manage reconnections or switch to a serverless-friendly alternative like direct HTTP clients with exponential backoff.
- What Laravel versions does this package support, and what PHP versions?
- The package assumes PHP 7.4+ and is compatible with Laravel 8+. If you’re using Laravel 7 or older, test thoroughly for compatibility issues, especially with dependency versions like `guzzlehttp/guzzle`. PHP 8.x may require minor adjustments due to type changes.
- How do I secure Twitter API keys in production? Should I use Laravel’s Vault or environment variables?
- Store credentials in environment variables (e.g., `.env`) or use Laravel’s Vault for enhanced security. Avoid hardcoding keys. For example, configure keys in `config/services.php` and load them via `$bearerToken = config('services.twitter.bearer_token')`. Rotate keys periodically and restrict access to the `.env` file.
- Is there built-in support for reconnecting if the Twitter stream drops?
- No, the package does not include reconnection logic or backpressure handling. Implement custom retry logic with exponential backoff using Laravel’s `retry` helper or a library like `spatie/backoff`. Monitor stream health with Laravel Telescope or Prometheus for alerts.
- Can I filter tweets by multiple keywords or complex rules (e.g., regex, boolean logic)?
- The package supports basic keyword filtering via `whenHears()`. For advanced rules, you’ll need to extend the `PublicStream` class or pre-filter tweets in a Laravel job. Twitter’s API v2 offers more robust filtering, but this package lacks native support for it. Consider post-processing with Laravel’s query builder or a dedicated library.
- How do I broadcast real-time tweets to a frontend using Laravel Echo or Pusher?
- Dispatch a Laravel event (e.g., `TweetReceived`) when a tweet arrives, then listen to that event in your frontend via Laravel Echo. For example, use `event(new TweetReceived($tweet))` in the `whenHears` callback and configure Echo to broadcast the event to a Pusher/Redis channel. Requires Laravel Broadcasting setup.
- Are there alternatives to this package that support Twitter API v2?
- Yes, consider `abraham/twitteroauth` (for v1.1) or rewrite using `symfony/http-client` for v2. Spatie’s newer `spatie/twitter-api` package may also offer v2 support. Evaluate alternatives based on your needs: some focus on simplicity, while others provide richer data models or async support.
- How do I test this package locally without hitting Twitter’s rate limits?
- Use Twitter’s sandbox environment or mock the HTTP client with Laravel’s `Http::fake()`. For example, stub responses in a test case: `Http::fake([...]);` and verify events are dispatched. Avoid real API calls in CI/CD pipelines to prevent rate-limiting issues. Test edge cases like connection drops with `Http::shouldReceive()`.