neoban/backend/app/Services/SocialMediaService.php
kushal-saha d818c5f05d refactor(core): restructure chat models and services, integrate route-based chat IDs
- Updated `Chat` and `ChatMessage` models for new table structures with UUIDs and attributes.
- Integrated `ChatPolicy` for authorization checks.
- Updated `ChatMessageController` with authorization and refined logic.
- Adjusted routes and state in the frontend to handle chat IDs from the URL.
- Enhanced `SocialMediaService` for handling chat-specific user prompts.
- Removed unused migrations related to chats and chat messages.
2026-04-29 15:36:56 +00:00

36 lines
1.2 KiB
PHP

<?php
namespace App\Services;
use App\Actions\Chats\StoreChatMessageAction;
use App\Ai\Agents\ContentWriterAgent;
use App\Ai\Agents\CreativeDirectorAgent;
use App\Data\SocialMediaPostResponseDto;
use App\Models\Chat;
readonly class SocialMediaService
{
public function __construct(
private ContentWriterAgent $contentWriterAgent,
private CreativeDirectorAgent $creativeDirectorAgent,
private StoreChatMessageAction $chatMessage,
) {}
/**
* Generate a social media post with an image.
* We are not using database transactions here because we do not want to delete the user prompt
* if any of the ai agents fails.
*/
public function generatePostWithImage(string $prompt, Chat $chat): SocialMediaPostResponseDto
{
$socialMediaResponse = $this->contentWriterAgent->forUser($chat->user)->prompt($prompt);
$postText = $socialMediaResponse->text;
// Generate image prompt via creative director agent
$imagePromptResponse = $this->creativeDirectorAgent->prompt($postText);
$imagePrompt = $imagePromptResponse->text;
return new SocialMediaPostResponseDto($socialMediaResponse->conversationId, $postText, $imagePrompt, now());
}
}