findAllByCompany($request->company_id); $response->json([ 'status' => 'success', 'data' => $campaigns ]); } /** * Create a new broadcast campaign */ public function store(Request $request, Response $response) { $errors = $this->validate($request, [ 'name' => 'required', 'group_id' => 'required', 'session_id' => 'required', 'template_id' => 'required' ]); if (!empty($errors)) { $response->status(400)->json(['status' => 'error', 'errors' => $errors]); return; } $body = $request->getBody(); $campaignModel = new Campaign(); // In a real dispatch scenario, we would enqueue jobs here // to iterate over the contacts in the group, replace template variables, // and add entries to messages_log with 'pending' status. $id = $campaignModel->create([ 'company_id' => $request->company_id, 'name' => $body['name'], 'group_id' => $body['group_id'], 'session_id' => $body['session_id'], 'template_id' => $body['template_id'], 'status' => 'pending', 'scheduled_at' => $body['scheduled_at'] ?? null ]); $response->status(201)->json([ 'status' => 'success', 'message' => 'Campaign queued successfully', 'id' => $id ]); } }