Add Twitter and LinkedIn publishers with Playwright sidecars

- Create twitter-post sidecar with Playwright for browser automation
- Create linkedin-post sidecar with Playwright for browser automation
- Add TwitterPublisher class that calls twitter-post sidecar
- Add LinkedInPublisher class that calls linkedin-post sidecar
- Register both publishers in PublisherManager via AppServiceProvider
- Update Posts index view to show Publish button for twitter/linkedin types

Both publishers use the same pattern as RedditPublisher:
- No API keys required (uses stored credentials from Social Accounts)
- Browser automation via Playwright
- Returns JSON result with success/failure and URL

Generated by Mistral Vibe.
Co-Authored-By: Mistral Vibe <vibe@mistral.ai>
This commit is contained in:
m105
2026-07-27 21:08:39 +03:00
parent 2a41328130
commit 44f979820f
16 changed files with 604 additions and 1 deletions
@@ -0,0 +1,54 @@
<?php
namespace App\Support\Publishing;
use App\Models\Post;
use Illuminate\Support\Facades\Log;
use Illuminate\Support\Facades\Process;
class LinkedInPublisher implements Publisher
{
public function supports(Post $post): bool
{
return $post->type === 'linkedin';
}
public function publish(Post $post): PublishResult
{
if (! $post->body) {
return PublishResult::rejected("Post {$post->id} has no body, required for a LinkedIn post.");
}
$account = $post->socialAccount;
if (! $account || $account->network !== 'linkedin') {
return PublishResult::rejected("Post {$post->id} has no linked LinkedIn social account.");
}
// LinkedIn uses email and password
$result = Process::timeout(120)->run([
base_path('sidecars/linkedin-post/run.sh'),
"--email={$account->email}",
"--password={$account->password}",
"--post=" . escapeshellarg($post->body),
]);
$data = json_decode(trim($result->output()), true);
if (! is_array($data) || ! array_key_exists('success', $data)) {
Log::error('linkedin sidecar returned unparseable output', [
'post_id' => $post->id,
'output' => $result->output(),
'stderr' => $result->errorOutput(),
]);
return PublishResult::failed('LinkedIn sidecar returned unparseable output — check logs.');
}
if (! $data['success']) {
return PublishResult::failed($data['error'] ?? 'unknown LinkedIn sidecar failure');
}
return PublishResult::success($data['url']);
}
}
@@ -0,0 +1,54 @@
<?php
namespace App\Support\Publishing;
use App\Models\Post;
use Illuminate\Support\Facades\Log;
use Illuminate\Support\Facades\Process;
class TwitterPublisher implements Publisher
{
public function supports(Post $post): bool
{
return $post->type === 'twitter';
}
public function publish(Post $post): PublishResult
{
if (! $post->body) {
return PublishResult::rejected("Post {$post->id} has no body, required for a Twitter post.");
}
$account = $post->socialAccount;
if (! $account || $account->network !== 'twitter') {
return PublishResult::rejected("Post {$post->id} has no linked Twitter social account.");
}
// Twitter uses username (which may be email or username) and password
$result = Process::timeout(120)->run([
base_path('sidecars/twitter-post/run.sh'),
"--username={$account->username}",
"--password={$account->password}",
"--tweet=" . escapeshellarg($post->body),
]);
$data = json_decode(trim($result->output()), true);
if (! is_array($data) || ! array_key_exists('success', $data)) {
Log::error('twitter sidecar returned unparseable output', [
'post_id' => $post->id,
'output' => $result->output(),
'stderr' => $result->errorOutput(),
]);
return PublishResult::failed('Twitter sidecar returned unparseable output — check logs.');
}
if (! $data['success']) {
return PublishResult::failed($data['error'] ?? 'unknown Twitter sidecar failure');
}
return PublishResult::success($data['url']);
}
}