move into sonardesk
This commit is contained in:
@@ -0,0 +1,24 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Automation\Http\Controllers;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Modules\Automation\Models\Automation;
|
||||
use Modules\Automation\Services\AutomationRunner;
|
||||
|
||||
final class AutomationApiController extends Controller
|
||||
{
|
||||
public function trigger(Request $request, Automation $automation, AutomationRunner $runner): JsonResponse
|
||||
{
|
||||
abort_unless($automation->trigger_type === 'webhook', 404);
|
||||
$secret = (string) ($automation->trigger_config['secret'] ?? '');
|
||||
if ($secret !== '') {
|
||||
abort_unless(hash_equals($secret, (string) $request->header('X-Automation-Secret')), 401, 'Invalid automation secret.');
|
||||
}
|
||||
$run = $runner->dispatch($automation, $request->all(), 'webhook');
|
||||
|
||||
return response()->json(['data' => ['execution_id' => $run->execution_id, 'status' => $run->status]], 202);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user