Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 9
0.00% covered (danger)
0.00%
0 / 2
CRAP
0.00% covered (danger)
0.00%
0 / 1
RolePlayVapiConfigController
0.00% covered (danger)
0.00%
0 / 9
0.00% covered (danger)
0.00%
0 / 2
6
0.00% covered (danger)
0.00%
0 / 1
 __construct
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 merged
0.00% covered (danger)
0.00%
0 / 8
0.00% covered (danger)
0.00%
0 / 1
2
1<?php
2
3namespace App\Http\Controllers\v2\RolePlay;
4
5use App\Http\Controllers\Controller;
6use App\Http\Services\VapiConfigService;
7use Illuminate\Http\JsonResponse;
8use Illuminate\Http\Request;
9
10/**
11 * Controller for serving merged VAPI configuration to the roleplay frontend.
12 *
13 * Returns the fully resolved configuration by merging global defaults,
14 * company overrides, and user overrides for the authenticated user.
15 */
16class RolePlayVapiConfigController extends Controller
17{
18    public function __construct(
19        private readonly VapiConfigService $vapiConfigService
20    ) {}
21
22    /**
23     * Get the merged VAPI config for the authenticated user.
24     *
25     * Resolves configuration hierarchy: global → company → user.
26     *
27     * @param Request $request
28     * @return JsonResponse
29     *
30     * @response 200 {
31     *   "result": {
32     *     "data": {
33     *       "transcriber": {"provider": "deepgram", "model": "nova-2", "language": "en-US"},
34     *       "model": {"available_models": [...], "default_model": "openai5"},
35     *       "voice": {"provider": "playht"},
36     *       "assistant": {"name": "FlyMSG Assistant", "silence_timeout_seconds": 10, ...},
37     *       "first_messages": [...]
38     *     }
39     *   }
40     * }
41     */
42    public function merged(Request $request): JsonResponse
43    {
44        $user = $request->user();
45
46        $config = $this->vapiConfigService->getMergedConfig(
47            $user->id,
48            $user->company_id ?? null
49        );
50
51        return response()->json([
52            'data' => $config,
53        ]);
54    }
55}