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.
PHP ai-agentsblueskyfacebookinstagramlaravellinkedinmastodonmcpmcp-serveropen-sourcerest-apiself-hostedsocial-mediasocial-media-managementsocial-media-schedulerthreadstiktokvuejsxyoutube
feat(ai-templates): extract image-card + carousel templates
Paulo Castellano97798c010ac0
diff --git a/app/Ai/Templates/CarouselTemplate.php b/app/Ai/Templates/CarouselTemplate.phpnew file mode 100644index 000000000..9bdf3fcf2--- /dev/null+++ b/app/Ai/Templates/CarouselTemplate.php@@ -0,0 +1,104 @@+<?php++declare(strict_types=1);++namespace App\Ai\Templates;++use App\Ai\Templates\Concerns\ResolvesContentType;+use App\Enums\PostPlatform\ContentType;+use App\Services\Image\PostImagePipeline;+use Illuminate\Contracts\JsonSchema\JsonSchema;++class CarouselTemplate implements AiContentTemplate+{+ use ResolvesContentType;++ public function key(): string+ {+ return 'carousel';+ }++ public function name(): string+ {+ return 'posts.ai.templates.carousel.name';+ }++ public function description(): string+ {+ return 'posts.ai.templates.carousel.description';+ }++ public function previewAsset(): string+ {+ return '/images/ai-templates/carousel.png';+ }++ public function needsAccount(): bool+ {+ return false;+ }++ public function supportedFormats(): array+ {+ return [ContentType::CAROUSEL_FORMAT];+ }++ public function generatorFormat(): string+ {+ return 'carousel';+ }++ public function promptView(): string+ {+ return 'prompts.post_content.generator';+ }++ public function schema(JsonSchema $schema, TemplateContext $context): array+ {+ $slideCount = $context->imageCount > 0 ? $context->imageCount : 1;++ return [+ 'caption' => $schema->string()->description('The Instagram caption for the carousel post.')->required(),+ 'slides' => $schema->array()+ ->items($schema->object(fn ($s) => [+ 'role' => $s->string()+ ->enum(['hook', 'development', 'proof', 'cta'])+ ->description('The role of this slide in the carousel arc. First slide is `hook` (specific real problem). Last slide is `cta` (one specific next action). Middle slides are `development` (unfold the idea) or `proof` (concrete result, before/after, behind-the-scenes, real learning). For 4+ slides, at least one middle slide must be `proof`.')+ ->required(),+ 'title' => $s->string()->description('Headline of the slide. Short, impactful.')->required(),+ 'body' => $s->string()->description('Supporting text below the headline. 1-3 sentences.')->required(),+ 'image_keywords' => $s->array()->items($schema->string())->description('2-4 search keywords for Unsplash.')->required(),+ ]))+ ->min($slideCount)+ ->max($slideCount)+ ->description("Exactly {$slideCount} slides for the carousel, in order. First slide must have role `hook`, last slide must have role `cta`.")+ ->required(),+ ];+ }++ public function humanizableFields(): array+ {+ return ['caption' => 'caption'];+ }++ /**+ * @param array<string, mixed> $structured+ */+ public function assemble(array $structured, TemplateContext $context): GeneratedPost+ {+ $caption = (string) data_get($structured, 'caption', '');++ $media = [];++ if ($context->socialAccount) {+ $media = app(PostImagePipeline::class)->forCarousel(+ workspace: $context->workspace,+ account: $context->socialAccount,+ structured: $structured,+ contentType: ContentType::InstagramFeed,+ );+ }++ return new GeneratedPost($caption, $media, ContentType::InstagramFeed);+ }+}diff --git a/app/Ai/Templates/Concerns/ResolvesContentType.php b/app/Ai/Templates/Concerns/ResolvesContentType.phpnew file mode 100644index 000000000..200875538--- /dev/null+++ b/app/Ai/Templates/Concerns/ResolvesContentType.php@@ -0,0 +1,19 @@+<?php++declare(strict_types=1);++namespace App\Ai\Templates\Concerns;++use App\Enums\PostPlatform\ContentType;++trait ResolvesContentType+{+ private static function resolveContentType(string $format): ?ContentType+ {+ if ($format === ContentType::CAROUSEL_FORMAT) {+ return ContentType::InstagramFeed;+ }++ return ContentType::tryFrom($format);+ }+}diff --git a/app/Ai/Templates/ImageCardTemplate.php b/app/Ai/Templates/ImageCardTemplate.phpnew file mode 100644index 000000000..4213a7392--- /dev/null+++ b/app/Ai/Templates/ImageCardTemplate.php@@ -0,0 +1,99 @@+<?php++declare(strict_types=1);++namespace App\Ai\Templates;++use App\Ai\Templates\Concerns\ResolvesContentType;+use App\Services\Image\PostImagePipeline;+use Illuminate\Contracts\JsonSchema\JsonSchema;++class ImageCardTemplate implements AiContentTemplate+{+ use ResolvesContentType;++ public function key(): string+ {+ return 'image_card';+ }++ public function name(): string+ {+ return 'posts.ai.templates.image_card.name';+ }++ public function description(): string+ {+ return 'posts.ai.templates.image_card.description';+ }++ public function previewAsset(): string+ {+ return '/images/ai-templates/image-card.png';+ }++ public function needsAccount(): bool+ {+ return false;+ }++ public function supportedFormats(): array+ {+ return [];+ }++ public function generatorFormat(): string+ {+ return 'single';+ }++ public function promptView(): string+ {+ return 'prompts.post_content.generator';+ }++ public function schema(JsonSchema $schema, TemplateContext $context): array+ {+ return [+ 'content' => $schema->string()->description('The full post caption text that will be published on the platform.')->required(),+ 'image_title' => $schema->string()->description('Short headline (5-12 words) overlaid on the image. The hook — should make a scroller stop. Distinct from content.')->required(),+ 'image_body' => $schema->string()->description('1-2 short sentences (max 25 words) overlaid below the image_title. Expands the hook just enough to compel reading the caption.')->required(),+ 'image_keywords' => $schema->array()->items($schema->string())->description('2-4 search keywords for Unsplash for the single image.')->required(),+ ];+ }++ public function humanizableFields(): array+ {+ return [+ 'content' => 'content',+ 'image_title' => 'image_title',+ 'image_body' => 'image_body',+ ];+ }++ /**+ * @param array<string, mixed> $structured+ */+ public function assemble(array $structured, TemplateContext $context): GeneratedPost+ {+ $contentType = self::resolveContentType($context->format);+ $supportsCaption = $contentType?->supportsCaption() ?? true;++ $rawContent = (string) data_get($structured, 'content', data_get($structured, 'text', ''));++ $media = [];++ if ($context->imageCount > 0 && $context->socialAccount) {+ $media = app(PostImagePipeline::class)->forSingle(+ workspace: $context->workspace,+ account: $context->socialAccount,+ structured: $structured,+ contentType: $contentType,+ );+ }++ $caption = $supportsCaption ? $rawContent : '';++ return new GeneratedPost($caption, $media, $contentType);+ }+}diff --git a/public/images/ai-templates/carousel.png b/public/images/ai-templates/carousel.pngnew file mode 100644index 000000000..389d7eb5eBinary files /dev/null and b/public/images/ai-templates/carousel.png differdiff --git a/public/images/ai-templates/image-card.png b/public/images/ai-templates/image-card.pngnew file mode 100644index 000000000..389d7eb5eBinary files /dev/null and b/public/images/ai-templates/image-card.png differdiff --git a/tests/Feature/Ai/Templates/TemplateContractTest.php b/tests/Feature/Ai/Templates/TemplateContractTest.phpnew file mode 100644index 000000000..f2c5ef9d0--- /dev/null+++ b/tests/Feature/Ai/Templates/TemplateContractTest.php@@ -0,0 +1,23 @@+<?php++declare(strict_types=1);++use App\Ai\Templates\CarouselTemplate;+use App\Ai\Templates\ImageCardTemplate;+use App\Enums\PostPlatform\ContentType;++test('image card template exposes its identity', function () {+ $t = new ImageCardTemplate;+ expect($t->key())->toBe('image_card')+ ->and($t->needsAccount())->toBeFalse()+ ->and($t->generatorFormat())->toBe('single')+ ->and($t->promptView())->toBe('prompts.post_content.generator')+ ->and($t->supportedFormats())->toBe([]);+});++test('carousel template exposes its identity', function () {+ $t = new CarouselTemplate;+ expect($t->key())->toBe('carousel')+ ->and($t->generatorFormat())->toBe('carousel')+ ->and($t->supportedFormats())->toContain(ContentType::CAROUSEL_FORMAT);+});