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
<?php
declare(strict_types=1);
use App\Actions\Post\CreatePosts;
use App\Enums\PostPlatform\ContentType;
use App\Enums\User\TimeFormat;
use App\Models\Post;
use App\Models\SocialAccount;
use App\Models\User;
use App\Models\Workspace;
use App\Support\PostingSchedule;
use Carbon\CarbonImmutable;
function waitForComposerTimezoneTrigger(mixed $page, string $label): void
{
waitForState($page, '@composer-schedule-trigger', "element.textContent.trim() === '{$label}'");
}
/**
* @return array{0: User, 1: Workspace}
*/
function composerTimezoneWorkspace(): array
{
$user = User::factory()->create(['timezone' => 'Asia/Tokyo', 'time_format' => TimeFormat::TwentyFourHour]);
$workspace = Workspace::factory()->create(['user_id' => $user->id, 'account_id' => $user->account_id]);
$workspace->members()->attach($user->id, membershipPivot('admin'));
$user->update(['current_workspace_id' => $workspace->id]);
subscribeAccount($user->account);
return [$user->fresh(), $workspace];
}
function composerTimezoneChannel(Workspace $workspace, string $timezone, ?PostingSchedule $schedule = null): SocialAccount
{
return SocialAccount::factory()->linkedin()->create([
'workspace_id' => $workspace->id,
'timezone' => $timezone,
'posting_schedule' => $schedule,
]);
}
function composerTimezoneSelect(mixed $page, SocialAccount ...$channels): void
{
waitFor($page, '@composer-add-account');
$page->click('@composer-add-account');
foreach ($channels as $channel) {
waitFor($page, "@composer-account-option-{$channel->id}");
$page->click("@composer-account-option-{$channel->id}");
}
}
/**
* Opens the date and time picker: straight away when a custom time is set,
* through the When menu otherwise.
*/
function composerTimezoneOpenPicker(mixed $page): void
{
waitFor($page, '@composer-schedule-trigger');
$page->click('@composer-schedule-trigger');
waitForState($page, '@composer-schedule-picker, @composer-schedule-custom', 'true');
if (! $page->script('Boolean(document.querySelector(\'[data-testid="composer-schedule-picker"]\'))')) {
$page->click('@composer-schedule-custom');
}
waitFor($page, '@composer-schedule-picker');
}
function composerTimezonePickFutureDay(mixed $page): string
{
$query = '[...document.querySelectorAll("[data-testid^=composer-schedule-day-]")].find((day) => !day.hasAttribute("data-disabled") && !day.hasAttribute("data-outside-view") && !day.hasAttribute("data-zone-today"))?.dataset.testid.replace("composer-schedule-day-", "") ?? null';
$day = $page->script($query);
if ($day === null) {
$page->click('@composer-schedule-calendar-next');
$day = $page->script($query);
}
$page->click("@composer-schedule-day-{$day}");
return $day;
}
function composerTimezoneTrigger(mixed $page): string
{
return trim((string) $page->script('document.querySelector("[data-testid=composer-schedule-trigger]").textContent'));
}
function composerTimezoneZoneLabel(mixed $page): string
{
return trim((string) $page->script('document.querySelector("[data-testid=composer-schedule-timezone]").textContent'));
}
function composerTimezoneLabel(CarbonImmutable $local): string
{
return $local->format($local->year === now('Asia/Tokyo')->year ? 'M j' : 'M j, Y').", {$local->format('H:i')}";
}
test('one channel shows and takes times in its own zone', function () {
[$user, $workspace] = composerTimezoneWorkspace();
$saoPaulo = composerTimezoneChannel($workspace, 'America/Sao_Paulo');
$this->actingAs($user);
$page = visit(route('app.posts.create'));
composerTimezoneSelect($page, $saoPaulo);
$page->fill("@composer-caption-{$saoPaulo->id}", 'Zone check');
composerTimezoneOpenPicker($page);
expect(composerTimezoneZoneLabel($page))->toBe('America/Sao Paulo');
$day = composerTimezonePickFutureDay($page);
$page->fill('@composer-schedule-time-input', '1000')->click('@composer-schedule-done');
$instant = CarbonImmutable::parse("{$day} 10:00", 'America/Sao_Paulo');
expect(composerTimezoneTrigger($page))->toBe(composerTimezoneLabel($instant));
$page->click('@composer-submit');
waitForGone($page, '@post-composer-dialog');
expect(Post::query()->where('workspace_id', $workspace->id)->sole()->scheduled_at->toIso8601String())
->toBe($instant->utc()->toIso8601String());
$page->assertNoJavaScriptErrors();
});
test('changing the channels keeps the picked instant and shows it in the new zone', function () {
[$user, $workspace] = composerTimezoneWorkspace();
$saoPaulo = composerTimezoneChannel($workspace, 'America/Sao_Paulo');
$warsaw = composerTimezoneChannel($workspace, 'Europe/Warsaw');
$this->actingAs($user);
$page = visit(route('app.posts.create'));
composerTimezoneSelect($page, $saoPaulo);
$page->fill("@composer-caption-{$saoPaulo->id}", 'Same moment everywhere');
composerTimezoneOpenPicker($page);
$day = composerTimezonePickFutureDay($page);
$page->fill('@composer-schedule-time-input', '1000')->click('@composer-schedule-done');
$instant = CarbonImmutable::parse("{$day} 10:00", 'America/Sao_Paulo');
composerTimezoneSelect($page, $warsaw);
waitForComposerTimezoneTrigger($page, composerTimezoneLabel($instant->setTimezone('Asia/Tokyo')));
expect(composerTimezoneTrigger($page))->toBe(composerTimezoneLabel($instant->setTimezone('Asia/Tokyo')));
$page->click("@composer-account-option-{$warsaw->id}");
waitForComposerTimezoneTrigger($page, composerTimezoneLabel($instant));
expect(composerTimezoneTrigger($page))->toBe(composerTimezoneLabel($instant));
$page->click('@composer-submit');
waitForGone($page, '@post-composer-dialog');
expect(Post::query()->where('workspace_id', $workspace->id)->sole()->scheduled_at->toIso8601String())
->toBe($instant->utc()->toIso8601String());
$page->assertNoJavaScriptErrors();
});
test('editing a scheduled post shows its time in the channel zone', function () {
[$user, $workspace] = composerTimezoneWorkspace();
$saoPaulo = composerTimezoneChannel($workspace, 'America/Sao_Paulo');
$instant = CarbonImmutable::parse(now('America/Sao_Paulo')->addDays(3)->format('Y-m-d').' 10:00', 'America/Sao_Paulo');
$post = CreatePosts::execute($workspace, $user, [
'status' => 'scheduled',
'scheduled_at' => $instant->utc()->toIso8601String(),
'content' => 'Edit me',
'media' => [],
'label_ids' => [],
'destinations' => [[
'social_account_id' => $saoPaulo->id,
'content_type' => ContentType::LinkedInPost->value,
'meta' => [],
]],
])->sole();
$this->actingAs($user);
$page = visit(route('app.posts.edit', $post));
waitForComposerTimezoneTrigger($page, composerTimezoneLabel($instant));
expect(composerTimezoneTrigger($page))->toBe(composerTimezoneLabel($instant));
composerTimezoneOpenPicker($page);
expect(composerTimezoneZoneLabel($page))->toBe('America/Sao Paulo')
->and($page->script('document.querySelector("[data-testid=composer-schedule-time-input]").value'))->toBe('10:00');
$page->click('@composer-schedule-done')->click('@composer-submit');
waitForGone($page, '@post-composer-dialog');
expect($post->fresh()->scheduled_at->toIso8601String())->toBe($instant->utc()->toIso8601String());
$page->assertNoJavaScriptErrors();
});
function composerTimezoneSchedule(): PostingSchedule
{
$schedule = PostingSchedule::empty();
foreach (range(0, 6) as $day) {
$schedule = $schedule->withTime($day, composerTimezoneMorningSlot($day))->withTime($day, composerTimezoneEveningSlot($day));
}
return $schedule;
}
function composerTimezoneMorningSlot(int $weekday): string
{
return sprintf('08:%02d', $weekday * 5);
}
function composerTimezoneEveningSlot(int $weekday): string
{
return sprintf('%02d:20', 10 + $weekday);
}
/**
* A fixed-offset zone where it is around noon right now, so a slot two hours
* earlier is always past and one three hours later is always ahead.
*/
function composerTimezoneNoonZone(): string
{
$offset = 12 - now('UTC')->hour;
return match (true) {
$offset === 0 => 'UTC',
$offset > 0 => "Etc/GMT-{$offset}",
default => 'Etc/GMT+'.abs($offset),
};
}
test('one channel offers its posting slots for the picked day', function () {
[$user, $workspace] = composerTimezoneWorkspace();
$saoPaulo = composerTimezoneChannel($workspace, 'America/Sao_Paulo', composerTimezoneSchedule());
$this->actingAs($user);
$page = visit(route('app.posts.create'));
composerTimezoneSelect($page, $saoPaulo);
$page->fill("@composer-caption-{$saoPaulo->id}", 'From a slot');
composerTimezoneOpenPicker($page);
$day = composerTimezonePickFutureDay($page);
$weekday = CarbonImmutable::parse($day)->dayOfWeek;
$evening = composerTimezoneEveningSlot($weekday);
$testId = fn (string $time): string => 'composer-schedule-slot-'.str_replace(':', '', $time);
waitFor($page, '@'.$testId($evening));
$page->assertVisible('@'.$testId(composerTimezoneMorningSlot($weekday)))
->assertMissing('@'.$testId(composerTimezoneEveningSlot(($weekday + 1) % 7)))
->click('@'.$testId($evening))
->assertValue('@composer-schedule-time-input', $evening)
->click('@composer-schedule-done');
$instant = CarbonImmutable::parse("{$day} {$evening}", 'America/Sao_Paulo');
expect(composerTimezoneTrigger($page))->toBe(composerTimezoneLabel($instant));
$page->click('@composer-submit');
waitForGone($page, '@post-composer-dialog');
expect(Post::query()->where('workspace_id', $workspace->id)->sole()->scheduled_at->toIso8601String())
->toBe($instant->utc()->toIso8601String());
$page->assertNoJavaScriptErrors();
});
test('posting slots already taken by a scheduled post are disabled', function () {
[$user, $workspace] = composerTimezoneWorkspace();
$zone = composerTimezoneNoonZone();
$channel = composerTimezoneChannel($workspace, $zone, PostingSchedule::empty()
->withTime(now($zone)->dayOfWeek, '15:00')
->withTime(now($zone)->dayOfWeek, '16:00'));
Post::factory()->forAccount($channel)->scheduled()->create([
'user_id' => $user->id,
'scheduled_at' => CarbonImmutable::parse(now($zone)->format('Y-m-d').' 15:00', $zone)->utc(),
]);
$this->actingAs($user);
$page = visit(route('app.posts.create'));
composerTimezoneSelect($page, $channel);
composerTimezoneOpenPicker($page);
waitFor($page, '@composer-schedule-slot-1600');
waitForState($page, '@composer-schedule-slot-1500', 'element.disabled');
expect($page->script('document.querySelector("[data-testid=composer-schedule-slot-1500]").disabled'))->toBeTrue()
->and($page->script('document.querySelector("[data-testid=composer-schedule-slot-1600]").disabled'))->toBeFalse();
$page->assertNoJavaScriptErrors();
});
test('the picker marks today in the channel zone, not the browser zone', function () {
[$user, $workspace] = composerTimezoneWorkspace();
$channel = composerTimezoneChannel($workspace, 'Pacific/Pago_Pago');
$this->actingAs($user);
$page = visit(route('app.posts.create'))->withTimezone('Pacific/Kiritimati');
composerTimezoneSelect($page, $channel);
composerTimezoneOpenPicker($page);
$today = now('Pacific/Pago_Pago')->toDateString();
if (! $page->script("Boolean(document.querySelector('[data-testid=\"composer-schedule-day-{$today}\"]:not([data-outside-view])'))")) {
$page->click('@composer-schedule-calendar-prev');
}
expect($page->script('[...document.querySelectorAll("[data-zone-today]:not([data-outside-view])")].map((day) => day.dataset.testid)'))
->toBe(["composer-schedule-day-{$today}"]);
$page->assertNoJavaScriptErrors();
});
test('a calendar hour opens the composer at the same moment, shown in the channel zone', function () {
[$user, $workspace] = composerTimezoneWorkspace();
$warsaw = composerTimezoneChannel($workspace, 'Europe/Warsaw');
$day = now('America/Sao_Paulo')->addDays(2)->format('Y-m-d');
$this->actingAs($user);
$page = visit(route('app.channels.calendar', ['account' => $warsaw->id, 'view' => 'week', 'week' => $day, 'tz' => 'America/Sao_Paulo']));
waitFor($page, "@calendar-add-{$day}-10");
$page->click("@calendar-add-{$day}-10");
waitFor($page, "@composer-caption-{$warsaw->id}");
$instant = CarbonImmutable::parse("{$day} 10:00", 'America/Sao_Paulo');
waitForComposerTimezoneTrigger($page, composerTimezoneLabel($instant->setTimezone('Europe/Warsaw')));
expect(composerTimezoneTrigger($page))->toBe(composerTimezoneLabel($instant->setTimezone('Europe/Warsaw')));
$page->fill("@composer-caption-{$warsaw->id}", 'From the calendar')->click('@composer-submit');
waitForGone($page, '@post-composer-dialog');
expect(Post::query()->where('workspace_id', $workspace->id)->sole()->scheduled_at->toIso8601String())
->toBe($instant->utc()->toIso8601String());
$page->assertNoJavaScriptErrors();
});