Skip to content

Open-source social media scheduler built for AI agents and the teams behind them. Create, schedule and publish posts to every network through MCP or the REST API, or write them yourself in a composer your team will love.

1.2 KB
Raw Blame
<?php

declare(strict_types=1);

namespace App\Console\Commands\Analytics;

use App\Jobs\Analytics\CollectAccountDailySnapshot;
use App\Models\SocialAccount;
use App\Services\Analytics\Collectors\Followers\FollowerCollectorFactory;
use Carbon\CarbonImmutable;
use Illuminate\Console\Attributes\Description;
use Illuminate\Console\Attributes\Signature;
use Illuminate\Console\Command;

#[Signature('analytics:dispatch-account-daily')]
#[Description('Dispatch daily follower collection for eligible social accounts')]
class DispatchAccountDailyAnalytics extends Command
{
    public function handle(FollowerCollectorFactory $collectors): int
    {
        $date = CarbonImmutable::now('UTC')->toDateString();

        SocialAccount::query()
            ->connected()
            ->with('workspace.account.subscriptions')
            ->lazyById(200)
            ->each(function (SocialAccount $channel) use ($collectors, $date): void {
                if ($channel->workspace->account->hasAppAccess() && $collectors->supports($channel->platform)) {
                    CollectAccountDailySnapshot::dispatch($channel->id, $date);
                }
            });

        return self::SUCCESS;
    }
}