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
Track post creation origin via created_via.
Paulo Castellano06f83a657173
diff --git a/app/Actions/Automation/Node/RunGenerateNode.php b/app/Actions/Automation/Node/RunGenerateNode.phpindex c44652562..41e7da30d 100644--- a/app/Actions/Automation/Node/RunGenerateNode.php+++ b/app/Actions/Automation/Node/RunGenerateNode.php@@ -12,6 +12,7 @@ use App\Ai\Templates\TemplateContext;use App\DataTransferObjects\Automation\NodeRunResult;use App\Enums\Ai\ContentStyle;use App\Enums\Ai\GeneratorFormat;+use App\Enums\Post\CreatedVia;use App\Enums\PostPlatform\ContentType;use App\Models\AutomationRun;use App\Models\SocialAccount;@@ -145,6 +146,7 @@ class RunGenerateNode'content' => $generated->content,'media' => $generated->media,'platforms' => $platforms,+ 'created_via' => CreatedVia::Automation,]);$run->update(['generated_post_id' => $post->id]);diff --git a/app/Actions/Post/CreatePost.php b/app/Actions/Post/CreatePost.phpindex 215838b6e..7950339d4 100644--- a/app/Actions/Post/CreatePost.php+++ b/app/Actions/Post/CreatePost.php@@ -4,6 +4,7 @@ declare(strict_types=1);namespace App\Actions\Post;+use App\Enums\Post\CreatedVia;use App\Enums\Post\Status as PostStatus;use App\Events\PostCreated;use App\Models\Post;@@ -26,11 +27,15 @@ class CreatePost* `label_ids[]` are attached after creation so the same set of UUIDs* works for REST, MCP, and web callers.*+ * `created_via` records which entry point created the post (web, mcp,+ * api, or automation). Callers must set it explicitly.+ ** @param array{* content?: ?string,* media?: array<int, mixed>,* date?: ?string,* scheduled_at?: ?string,+ * created_via: CreatedVia,* platforms?: array<int, array{social_account_id: string, content_type?: string, meta?: array<string, mixed>}>,* label_ids?: array<int, string>* } $data@@ -45,6 +50,7 @@ class CreatePost'content' => data_get($data, 'content', ''),'media' => data_get($data, 'media', []),'status' => PostStatus::Draft,+ 'created_via' => data_get($data, 'created_via'),'scheduled_at' => $scheduledAt,]);diff --git a/app/Enums/Post/CreatedVia.php b/app/Enums/Post/CreatedVia.phpnew file mode 100644index 000000000..bd7143328--- /dev/null+++ b/app/Enums/Post/CreatedVia.php@@ -0,0 +1,13 @@+<?php++declare(strict_types=1);++namespace App\Enums\Post;++enum CreatedVia: string+{+ case Web = 'web';+ case Mcp = 'mcp';+ case Api = 'api';+ case Automation = 'automation';+}diff --git a/app/Http/Controllers/Api/PostController.php b/app/Http/Controllers/Api/PostController.phpindex bd020741e..7460612ea 100644--- a/app/Http/Controllers/Api/PostController.php+++ b/app/Http/Controllers/Api/PostController.php@@ -10,6 +10,7 @@ use App\Actions\Post\HostInlineMedia;use App\Actions\Post\UpdatePost;use App\Enums\Media\Type as MediaType;use App\Enums\Post\Action as PostAction;+use App\Enums\Post\CreatedVia;use App\Http\Requests\Api\Post\AttachMediaFromUrlRequest;use App\Http\Requests\Api\Post\StoreMediaRequest;use App\Http\Requests\Api\Post\StorePostRequest;@@ -61,6 +62,8 @@ class PostController extends Controller);}+ $data['created_via'] = CreatedVia::Api;+$post = CreatePost::execute($workspace, $workspace->owner, $data);$post->load(['postPlatforms.socialAccount']);diff --git a/app/Http/Controllers/App/PostController.php b/app/Http/Controllers/App/PostController.phpindex 3b6e6ef7c..7ef6f6332 100644--- a/app/Http/Controllers/App/PostController.php+++ b/app/Http/Controllers/App/PostController.php@@ -12,6 +12,7 @@ use App\Actions\Post\UpdatePost;use App\Ai\Templates\AiContentTemplate;use App\Ai\Templates\AiTemplateRegistry;use App\Enums\Post\Action as PostAction;+use App\Enums\Post\CreatedVia;use App\Enums\Post\Status as PostStatus;use App\Enums\SocialAccount\Platform;use App\Http\Requests\App\Post\StorePostRequest;@@ -189,6 +190,7 @@ class PostController extends Controller$post = CreatePost::execute($workspace, $request->user(), ['date' => $request->input('date'),'media' => $request->input('media', []),+ 'created_via' => CreatedVia::Web,]);return Inertia::location(route('app.posts.edit', $post));diff --git a/app/Http/Controllers/App/PostTemplateController.php b/app/Http/Controllers/App/PostTemplateController.phpindex c7889097b..18ce4cdc8 100644--- a/app/Http/Controllers/App/PostTemplateController.php+++ b/app/Http/Controllers/App/PostTemplateController.php@@ -6,6 +6,7 @@ namespace App\Http\Controllers\App;use App\Actions\Post\CreatePost;use App\Enums\Media\Type as MediaType;+use App\Enums\Post\CreatedVia;use App\Http\Requests\App\PostTemplate\ApplyPostTemplateRequest;use App\Http\Requests\App\PostTemplate\IndexPostTemplateRequest;use App\Http\Resources\App\PostTemplateResource;@@ -89,6 +90,7 @@ class PostTemplateController extends Controller'content' => $content,'media' => $media,'date' => $request->input('date'),+ 'created_via' => CreatedVia::Web,]);return response()->json([diff --git a/app/Jobs/Ai/StreamPostCreation.php b/app/Jobs/Ai/StreamPostCreation.phpindex f8c9eb144..ad8b8f264 100644--- a/app/Jobs/Ai/StreamPostCreation.php+++ b/app/Jobs/Ai/StreamPostCreation.php@@ -14,6 +14,7 @@ use App\Enums\Ai\ContentStyle;use App\Enums\Ai\GeneratorFormat;use App\Enums\Notification\Channel as NotificationChannel;use App\Enums\Notification\Type as NotificationType;+use App\Enums\Post\CreatedVia;use App\Enums\PostPlatform\ContentType;use App\Events\Ai\PostCreationReady;use App\Jobs\SendNotification;@@ -195,6 +196,7 @@ class StreamPostCreation implements ShouldQueue'content' => $generated->content,'media' => $generated->media,'date' => $this->date,+ 'created_via' => CreatedVia::Web,]);if ($generated->contentType && $socialAccount) {diff --git a/app/Mcp/Tools/Post/CreatePostTool.php b/app/Mcp/Tools/Post/CreatePostTool.phpindex 80851f06a..50c1ce08d 100644--- a/app/Mcp/Tools/Post/CreatePostTool.php+++ b/app/Mcp/Tools/Post/CreatePostTool.php@@ -5,6 +5,7 @@ declare(strict_types=1);namespace App\Mcp\Tools\Post;use App\Actions\Post\CreatePost;+use App\Enums\Post\CreatedVia;use App\Enums\PostPlatform\ContentType;use App\Http\Resources\Api\PostResource;use App\Rules\ContentTypeMatchesPlatform;@@ -41,6 +42,8 @@ class CreatePostTool extends Tool...PostPlatformMetaRules::rules(),]);+ $validated['created_via'] = CreatedVia::Mcp;+$post = CreatePost::execute($workspace, $request->user(), $validated);$post->load(['postPlatforms.socialAccount', 'labels']);diff --git a/app/Models/Post.php b/app/Models/Post.phpindex 1fa414560..8d587d7f1 100644--- a/app/Models/Post.php+++ b/app/Models/Post.php@@ -6,6 +6,7 @@ namespace App\Models;use App\DataTransferObjects\MediaItem;use App\Enums\Media\Type;+use App\Enums\Post\CreatedVia;use App\Enums\Post\Status as PostStatus;use App\Enums\SocialAccount\Platform;use App\Observers\PostObserver;@@ -34,6 +35,7 @@ class Post extends Model'content','media','status',+ 'created_via','scheduled_at','published_at',];@@ -42,6 +44,7 @@ class Post extends Model{return ['status' => PostStatus::class,+ 'created_via' => CreatedVia::class,'media' => 'array','scheduled_at' => 'datetime','published_at' => 'datetime',diff --git a/database/migrations/2026_07_24_141454_add_created_via_to_posts_table.php b/database/migrations/2026_07_24_141454_add_created_via_to_posts_table.phpnew file mode 100644index 000000000..17cd8c7de--- /dev/null+++ b/database/migrations/2026_07_24_141454_add_created_via_to_posts_table.php@@ -0,0 +1,28 @@+<?php++use Illuminate\Database\Migrations\Migration;+use Illuminate\Database\Schema\Blueprint;+use Illuminate\Support\Facades\Schema;++return new class extends Migration+{+ /**+ * Run the migrations.+ */+ public function up(): void+ {+ Schema::table('posts', function (Blueprint $table) {+ $table->string('created_via')->nullable()->after('status');+ });+ }++ /**+ * Reverse the migrations.+ */+ public function down(): void+ {+ Schema::table('posts', function (Blueprint $table) {+ $table->dropColumn('created_via');+ });+ }+};diff --git a/tests/Feature/Actions/Post/CreatePostTest.php b/tests/Feature/Actions/Post/CreatePostTest.phpindex 4a1252e0b..690f3bb9f 100644--- a/tests/Feature/Actions/Post/CreatePostTest.php+++ b/tests/Feature/Actions/Post/CreatePostTest.php@@ -3,6 +3,7 @@declare(strict_types=1);use App\Actions\Post\CreatePost;+use App\Enums\Post\CreatedVia;use App\Events\PostCreated;use App\Models\User;use App\Models\Workspace;@@ -16,6 +17,7 @@ test('execute dispatches PostCreated with the persisted post', function () {$post = CreatePost::execute($workspace, $user, ['content' => 'Hello world',+ 'created_via' => CreatedVia::Web,]);Event::assertDispatched(@@ -24,3 +26,20 @@ test('execute dispatches PostCreated with the persisted post', function () {&& $event->post->workspace_id === $workspace->id,);});++test('execute persists created_via for each entry point', function (CreatedVia $createdVia) {+ $user = User::factory()->create();+ $workspace = Workspace::factory()->create(['user_id' => $user->id]);++ $post = CreatePost::execute($workspace, $user, [+ 'content' => 'Hello world',+ 'created_via' => $createdVia,+ ]);++ expect($post->fresh()->created_via)->toBe($createdVia);+})->with([+ 'web' => CreatedVia::Web,+ 'mcp' => CreatedVia::Mcp,+ 'api' => CreatedVia::Api,+ 'automation' => CreatedVia::Automation,+]);diff --git a/tests/Feature/Api/PostApiTest.php b/tests/Feature/Api/PostApiTest.phpindex 5163af934..444bcbfd8 100644--- a/tests/Feature/Api/PostApiTest.php+++ b/tests/Feature/Api/PostApiTest.php@@ -2,6 +2,7 @@declare(strict_types=1);+use App\Enums\Post\CreatedVia;use App\Enums\Post\Status as PostStatus;use App\Enums\PostPlatform\ContentType;use App\Enums\SocialAccount\Platform;@@ -72,7 +73,9 @@ it('creates a post', function () {->assertCreated()->assertJsonPath('status', PostStatus::Draft->value);- expect(Post::where('workspace_id', $this->workspace->id)->count())->toBe(1);+ $post = Post::where('workspace_id', $this->workspace->id)->first();+ expect($post)->not->toBeNull();+ expect($post->created_via)->toBe(CreatedVia::Api);});it('creates a post with content, media, and labels', function () {diff --git a/tests/Feature/Mcp/PostToolTest.php b/tests/Feature/Mcp/PostToolTest.phpindex dfd631b49..ba60f0101 100644--- a/tests/Feature/Mcp/PostToolTest.php+++ b/tests/Feature/Mcp/PostToolTest.php@@ -2,6 +2,7 @@declare(strict_types=1);+use App\Enums\Post\CreatedVia;use App\Enums\SocialAccount\Platform;use App\Enums\UserWorkspace\Role;use App\Mcp\Servers\TryPostServer;@@ -109,7 +110,9 @@ test('create post with content and date', function () {->etc();});- expect(Post::where('workspace_id', $this->workspace->id)->count())->toBe(1);+ $post = Post::where('workspace_id', $this->workspace->id)->first();+ expect($post)->not->toBeNull();+ expect($post->created_via)->toBe(CreatedVia::Mcp);});test('create post with platforms enables only those', function () {diff --git a/tests/Feature/PostControllerTest.php b/tests/Feature/PostControllerTest.phpindex a7da0b149..2ea4c55b5 100644--- a/tests/Feature/PostControllerTest.php+++ b/tests/Feature/PostControllerTest.php@@ -2,6 +2,7 @@declare(strict_types=1);+use App\Enums\Post\CreatedVia;use App\Enums\Post\Status as PostStatus;use App\Enums\PostPlatform\ContentType;use App\Enums\PostPlatform\Status;@@ -257,6 +258,7 @@ test('store post creates draft and redirects to edit', function () {$post = Post::where('workspace_id', $this->workspace->id)->first();expect($post)->not->toBeNull();expect($post->status)->toBe(PostStatus::Draft);+ expect($post->created_via)->toBe(CreatedVia::Web);expect($post->postPlatforms)->toHaveCount(1);});