From 0d1ca7138006d4417c987976b88aa109e824899a Mon Sep 17 00:00:00 2001 From: Paulo Castellano Date: Thu, 16 Apr 2026 10:03:14 -0300 Subject: [PATCH] feat: add platform rules for all 12 supported social networks MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Each platform has a rule class exposing specs() (char limits, aspect ratios, media limits, format-specific constraints) and summary() (a short concise description the agent can render into instructions). Registered in AppServiceProvider::configurePlatformRules() mapping Platform enum values to rule classes. Both InstagramFacebook and LinkedInPage share rules with their non-business siblings. Contract + Registry follow the lookup-map pattern. Registry is a static registry seeded at boot — rules are cheap enough to new up per request. Tests cover all 12 platforms via Pest dataset and verify the forMany fan-out, clear/register behavior, and representative summaries. --- app/Ai/PlatformRules/BlueskyRules.php | 30 +++++++++ app/Ai/PlatformRules/Contract.php | 19 ++++++ app/Ai/PlatformRules/FacebookRules.php | 39 ++++++++++++ app/Ai/PlatformRules/InstagramRules.php | 42 +++++++++++++ app/Ai/PlatformRules/LinkedInRules.php | 39 ++++++++++++ app/Ai/PlatformRules/MastodonRules.php | 30 +++++++++ app/Ai/PlatformRules/PinterestRules.php | 40 ++++++++++++ app/Ai/PlatformRules/Registry.php | 53 ++++++++++++++++ app/Ai/PlatformRules/ThreadsRules.php | 30 +++++++++ app/Ai/PlatformRules/TikTokRules.php | 31 ++++++++++ app/Ai/PlatformRules/XRules.php | 31 ++++++++++ app/Ai/PlatformRules/YouTubeRules.php | 33 ++++++++++ app/Providers/AppServiceProvider.php | 38 ++++++++++++ .../Feature/Ai/PlatformRules/RegistryTest.php | 61 +++++++++++++++++++ 14 files changed, 516 insertions(+) create mode 100644 app/Ai/PlatformRules/BlueskyRules.php create mode 100644 app/Ai/PlatformRules/Contract.php create mode 100644 app/Ai/PlatformRules/FacebookRules.php create mode 100644 app/Ai/PlatformRules/InstagramRules.php create mode 100644 app/Ai/PlatformRules/LinkedInRules.php create mode 100644 app/Ai/PlatformRules/MastodonRules.php create mode 100644 app/Ai/PlatformRules/PinterestRules.php create mode 100644 app/Ai/PlatformRules/Registry.php create mode 100644 app/Ai/PlatformRules/ThreadsRules.php create mode 100644 app/Ai/PlatformRules/TikTokRules.php create mode 100644 app/Ai/PlatformRules/XRules.php create mode 100644 app/Ai/PlatformRules/YouTubeRules.php create mode 100644 tests/Feature/Ai/PlatformRules/RegistryTest.php diff --git a/app/Ai/PlatformRules/BlueskyRules.php b/app/Ai/PlatformRules/BlueskyRules.php new file mode 100644 index 00000000..22f5df4a --- /dev/null +++ b/app/Ai/PlatformRules/BlueskyRules.php @@ -0,0 +1,30 @@ + 300, + 'max_images' => 4, + 'max_videos' => 1, + 'text_only_allowed' => true, + ]; + } + + public function summary(): string + { + return 'Bluesky: 300 chars max. Up to 4 images or 1 video. Similar to X but more concise.'; + } +} diff --git a/app/Ai/PlatformRules/Contract.php b/app/Ai/PlatformRules/Contract.php new file mode 100644 index 00000000..119047d1 --- /dev/null +++ b/app/Ai/PlatformRules/Contract.php @@ -0,0 +1,19 @@ + + */ + public function specs(): array; + + public function summary(): string; +} diff --git a/app/Ai/PlatformRules/FacebookRules.php b/app/Ai/PlatformRules/FacebookRules.php new file mode 100644 index 00000000..93926df7 --- /dev/null +++ b/app/Ai/PlatformRules/FacebookRules.php @@ -0,0 +1,39 @@ + 63206, + 'max_images' => 10, + 'text_only_allowed' => true, + 'formats' => [ + 'post' => ['max_media' => 10, 'text_only_allowed' => true], + 'reel' => ['aspect_ratio' => '9:16', 'video_only' => true, 'max_duration_seconds' => 90], + 'story' => ['aspect_ratio' => '9:16', 'ephemeral' => true], + ], + ]; + } + + public function summary(): string + { + return <<<'TXT' +Facebook: caption up to 63k chars but short posts perform better. Text-only allowed. +- Post: flexible aspect ratio, up to 10 images/videos. +- Reel: vertical 9:16 video only, up to 90s. +- Story: vertical 9:16, single image/video, ephemeral. +TXT; + } +} diff --git a/app/Ai/PlatformRules/InstagramRules.php b/app/Ai/PlatformRules/InstagramRules.php new file mode 100644 index 00000000..61412d91 --- /dev/null +++ b/app/Ai/PlatformRules/InstagramRules.php @@ -0,0 +1,42 @@ + 2200, + 'max_images' => 10, + 'max_videos' => 10, + 'text_only_allowed' => false, + 'formats' => [ + 'feed' => ['aspect_ratio' => '1:1 or 4:5', 'media_limit' => 10], + 'carousel' => ['aspect_ratio' => '1:1 or 4:5', 'media_limit' => 10], + 'reel' => ['aspect_ratio' => '9:16', 'video_only' => true, 'max_duration_seconds' => 90], + 'story' => ['aspect_ratio' => '9:16', 'media_limit' => 1, 'ephemeral' => true], + ], + ]; + } + + public function summary(): string + { + return <<<'TXT' +Instagram: caption max 2200 chars, up to 30 hashtags (3-5 recommended). +- Feed: square (1:1) or portrait (4:5). Up to 10 images/videos. +- Carousel: 2-10 slides, all same aspect ratio. First slide is the hook. +- Reel: vertical 9:16 video only, up to 90s (30-60s performs best). Hook in first 1-3s. +- Story: vertical 9:16, single image/video, ephemeral (24h). +TXT; + } +} diff --git a/app/Ai/PlatformRules/LinkedInRules.php b/app/Ai/PlatformRules/LinkedInRules.php new file mode 100644 index 00000000..4c0c7f35 --- /dev/null +++ b/app/Ai/PlatformRules/LinkedInRules.php @@ -0,0 +1,39 @@ + 3000, + 'max_images' => 1, + 'max_videos' => 1, + 'text_only_allowed' => true, + 'formats' => [ + 'post' => ['max_media' => 1], + 'carousel' => ['max_slides' => 20, 'optimal_slides' => '8-12', 'images_only' => true, 'document_based' => true], + ], + ]; + } + + public function summary(): string + { + return <<<'TXT' +LinkedIn: 3000 chars max. First 2-3 lines visible before "see more" — make them compelling. +Professional tone. Educational/how-to content performs well. +- Post: 1 image or 1 video. +- Carousel: PDF-based document, up to 20 slides (8-12 optimal), images only. +TXT; + } +} diff --git a/app/Ai/PlatformRules/MastodonRules.php b/app/Ai/PlatformRules/MastodonRules.php new file mode 100644 index 00000000..99dd770d --- /dev/null +++ b/app/Ai/PlatformRules/MastodonRules.php @@ -0,0 +1,30 @@ + 500, + 'max_images' => 4, + 'max_videos' => 1, + 'text_only_allowed' => true, + ]; + } + + public function summary(): string + { + return 'Mastodon: 500 chars max. Up to 4 images or 1 video. Community-focused, avoid commercial tone.'; + } +} diff --git a/app/Ai/PlatformRules/PinterestRules.php b/app/Ai/PlatformRules/PinterestRules.php new file mode 100644 index 00000000..11e60f43 --- /dev/null +++ b/app/Ai/PlatformRules/PinterestRules.php @@ -0,0 +1,40 @@ + 800, + 'max_images' => 5, + 'max_videos' => 1, + 'text_only_allowed' => false, + 'formats' => [ + 'pin' => ['aspect_ratio' => '2:3', 'media_limit' => 1, 'images_only' => true], + 'video_pin' => ['aspect_ratio' => '9:16 or 2:3', 'video_only' => true, 'min_duration_seconds' => 4, 'max_duration_seconds' => 900], + 'carousel' => ['aspect_ratio' => '2:3', 'max_slides' => 5, 'images_only' => true], + ], + ]; + } + + public function summary(): string + { + return <<<'TXT' +Pinterest: title max 100 chars, description max 500 chars. Text overlay on images helps discovery. +- Pin: portrait 2:3 (1000x1500px), single image. +- Video Pin: vertical 9:16 or portrait 2:3, 4s to 15 minutes. +- Carousel: portrait 2:3, up to 5 images. +TXT; + } +} diff --git a/app/Ai/PlatformRules/Registry.php b/app/Ai/PlatformRules/Registry.php new file mode 100644 index 00000000..11eac343 --- /dev/null +++ b/app/Ai/PlatformRules/Registry.php @@ -0,0 +1,53 @@ +> + */ + private static array $map = []; + + public static function for(Platform $platform): ?Contract + { + $class = self::$map[$platform->value] ?? null; + + return $class ? new $class : null; + } + + /** + * @param array $platforms + * @return array + */ + public static function forMany(array $platforms): array + { + $rules = []; + + foreach ($platforms as $platform) { + $rule = self::for($platform); + if ($rule) { + $rules[] = $rule; + } + } + + return $rules; + } + + /** + * @param class-string $ruleClass + */ + public static function register(Platform $platform, string $ruleClass): void + { + self::$map[$platform->value] = $ruleClass; + } + + public static function clear(): void + { + self::$map = []; + } +} diff --git a/app/Ai/PlatformRules/ThreadsRules.php b/app/Ai/PlatformRules/ThreadsRules.php new file mode 100644 index 00000000..9743a473 --- /dev/null +++ b/app/Ai/PlatformRules/ThreadsRules.php @@ -0,0 +1,30 @@ + 500, + 'max_images' => 10, + 'max_videos' => 10, + 'text_only_allowed' => true, + ]; + } + + public function summary(): string + { + return 'Threads: 500 chars max. Up to 10 images/videos. Conversational tone. Ask questions to drive replies.'; + } +} diff --git a/app/Ai/PlatformRules/TikTokRules.php b/app/Ai/PlatformRules/TikTokRules.php new file mode 100644 index 00000000..f694171b --- /dev/null +++ b/app/Ai/PlatformRules/TikTokRules.php @@ -0,0 +1,31 @@ + 2200, + 'max_videos' => 1, + 'text_only_allowed' => false, + 'aspect_ratio' => '9:16', + 'video_only' => true, + ]; + } + + public function summary(): string + { + return 'TikTok: vertical 9:16 video only. 15-60s performs best. Hook in first 1-2s. Trendy, authentic style. Caption max 2200 chars.'; + } +} diff --git a/app/Ai/PlatformRules/XRules.php b/app/Ai/PlatformRules/XRules.php new file mode 100644 index 00000000..380d5fee --- /dev/null +++ b/app/Ai/PlatformRules/XRules.php @@ -0,0 +1,31 @@ + 280, + 'max_images' => 4, + 'max_videos' => 1, + 'text_only_allowed' => true, + 'best_aspect_ratio' => '16:9', + ]; + } + + public function summary(): string + { + return 'X (Twitter): 280 chars max. Up to 4 images OR 1 video. 16:9 landscape performs best. Concise, punchy copy.'; + } +} diff --git a/app/Ai/PlatformRules/YouTubeRules.php b/app/Ai/PlatformRules/YouTubeRules.php new file mode 100644 index 00000000..17d0ec34 --- /dev/null +++ b/app/Ai/PlatformRules/YouTubeRules.php @@ -0,0 +1,33 @@ + 5000, + 'max_videos' => 1, + 'text_only_allowed' => false, + 'aspect_ratio' => '9:16', + 'video_only' => true, + 'max_duration_seconds' => 60, + 'requires_title' => true, + ]; + } + + public function summary(): string + { + return 'YouTube Shorts: vertical 9:16 video only, up to 60s. Hook immediately. Loop-friendly content helps. Description max 5000 chars. Title required.'; + } +} diff --git a/app/Providers/AppServiceProvider.php b/app/Providers/AppServiceProvider.php index a7028a48..880e9ebd 100644 --- a/app/Providers/AppServiceProvider.php +++ b/app/Providers/AppServiceProvider.php @@ -4,8 +4,20 @@ namespace App\Providers; +use App\Ai\PlatformRules\BlueskyRules; +use App\Ai\PlatformRules\FacebookRules; +use App\Ai\PlatformRules\InstagramRules; +use App\Ai\PlatformRules\LinkedInRules; +use App\Ai\PlatformRules\MastodonRules; +use App\Ai\PlatformRules\PinterestRules; +use App\Ai\PlatformRules\Registry; +use App\Ai\PlatformRules\ThreadsRules; +use App\Ai\PlatformRules\TikTokRules; +use App\Ai\PlatformRules\XRules; +use App\Ai\PlatformRules\YouTubeRules; use App\Ai\Providers\ExtendedGeminiProvider; use App\Ai\Tools\AttachmentCollector; +use App\Enums\SocialAccount\Platform; use App\Listeners\StripeEventListener; use App\Models\Account; use App\Models\AiMessage; @@ -82,6 +94,7 @@ public function boot(): void $this->configureDefaults(); $this->configureMorphMap(); $this->configureAi(); + $this->configurePlatformRules(); $this->configurePostHog(); $this->configureRateLimiting(); $this->configureSocialite(); @@ -107,6 +120,31 @@ protected function configureAi(): void }); } + protected function configurePlatformRules(): void + { + $map = [ + Platform::Instagram->value => InstagramRules::class, + Platform::InstagramFacebook->value => InstagramRules::class, + Platform::Facebook->value => FacebookRules::class, + Platform::X->value => XRules::class, + Platform::TikTok->value => TikTokRules::class, + Platform::YouTube->value => YouTubeRules::class, + Platform::LinkedIn->value => LinkedInRules::class, + Platform::LinkedInPage->value => LinkedInRules::class, + Platform::Threads->value => ThreadsRules::class, + Platform::Pinterest->value => PinterestRules::class, + Platform::Bluesky->value => BlueskyRules::class, + Platform::Mastodon->value => MastodonRules::class, + ]; + + foreach ($map as $value => $class) { + Registry::register( + Platform::from($value), + $class, + ); + } + } + protected function configureMorphMap(): void { Relation::enforceMorphMap([ diff --git a/tests/Feature/Ai/PlatformRules/RegistryTest.php b/tests/Feature/Ai/PlatformRules/RegistryTest.php new file mode 100644 index 00000000..14cc74bb --- /dev/null +++ b/tests/Feature/Ai/PlatformRules/RegistryTest.php @@ -0,0 +1,61 @@ +toBeInstanceOf(Contract::class) + ->and(strlen($rules->summary()))->toBeGreaterThan(30) + ->and($rules->specs())->toBeArray(); +})->with([ + [Platform::Instagram], + [Platform::InstagramFacebook], + [Platform::Facebook], + [Platform::X], + [Platform::TikTok], + [Platform::YouTube], + [Platform::LinkedIn], + [Platform::LinkedInPage], + [Platform::Threads], + [Platform::Pinterest], + [Platform::Bluesky], + [Platform::Mastodon], +]); + +test('forMany returns rules for the given platforms in order', function () { + $rules = Registry::forMany([Platform::X, Platform::Instagram, Platform::TikTok]); + + expect($rules)->toHaveCount(3); + expect($rules[0]->platform())->toBe(Platform::X); + expect($rules[1]->platform())->toBe(Platform::Instagram); + expect($rules[2]->platform())->toBe(Platform::TikTok); +}); + +test('forMany skips platforms with no registered rules', function () { + Registry::clear(); + Registry::register(Platform::X, XRules::class); + + $rules = Registry::forMany([Platform::X, Platform::Instagram]); + + expect($rules)->toHaveCount(1); + expect($rules[0]->platform())->toBe(Platform::X); +}); + +test('X rules summary mentions 280 char limit', function () { + expect(Registry::for(Platform::X)->summary())->toContain('280'); +}); + +test('Instagram rules summary mentions 9:16 for Reel', function () { + expect(Registry::for(Platform::Instagram)->summary())->toContain('9:16'); +}); + +test('TikTok rules specs indicate video only', function () { + expect(Registry::for(Platform::TikTok)->specs()['video_only'])->toBeTrue(); +});