Skip to content

Commit 462cd8d

Browse files
authored
Merge pull request #2 from chechojgb/extensionDetail
Add: Creacion api datos agente
2 parents c560a39 + 803cfbd commit 462cd8d

File tree

13 files changed

+567
-78
lines changed

13 files changed

+567
-78
lines changed

app/Http/Controllers/PostProxyController.php

Lines changed: 72 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -60,16 +60,52 @@ public function usersTable($area): JsonResponse
6060
return response()->json($data);
6161
}
6262

63-
// private function randomTimeBetween(int $minSeconds, int $maxSeconds): string
64-
// {
65-
// $seconds = rand($minSeconds, $maxSeconds);
66-
// return gmdate("H:i:s", $seconds);
67-
// }
63+
public function userData($extension): JsonResponse
64+
{
65+
$response = Http::get("http://10.57.251.181:3005/extension/info?ext={$extension}");
66+
if (!$response->successful()) {
67+
return response()->json(['error' => 'No se pudo obtener los datos'], 500);
68+
}
69+
70+
$data = $response->json();
71+
72+
$texto = $data['member'] ?? $data['member2'] ?? null;
73+
74+
if ($texto) {
75+
// Extraer nombre
76+
$nombre = explode(' ', $texto)[0];
77+
78+
// Extraer estado (Busy, In call, etc.)
79+
preg_match_all('/\((.*?)\)/', $texto, $matches);
80+
$estado = null;
81+
$pausa = null;
82+
83+
foreach ($matches[1] as $match) {
84+
if (str_contains($match, 'paused')) {
85+
$pausa = $match; // ej: paused:ACW was 2108 secs ago
86+
}
87+
if (in_array($match, ['Busy', 'On Hold', 'In call', 'Ringing', 'Not in use'])) {
88+
$estado = $match;
89+
}
90+
}
91+
92+
$data['member'] = [
93+
'nombre' => $nombre,
94+
'estado' => $estado,
95+
'pausa' => $pausa,
96+
];
97+
}
98+
99+
return response()->json($data);
100+
}
101+
102+
103+
68104

69105

70106
public function getOverview()
71107
{
72-
$response = Http::get('http://10.57.251.181:3004/extensions/overview');
108+
$response = Http::get('http://10.57.251.181:3007/extensions/overview');
73109

74110
if (!$response->successful()) {
75111
return response()->json(['error' => 'No se pudo obtener los datos'], 500);
@@ -108,4 +144,34 @@ public function getOverview()
108144
}
109145

110146

147+
public function chanelHangup(Request $request)
148+
{
149+
$channel = $request->input('channel');
150+
151+
$response = Http::post('http://10.57.251.181:3000/channel/hangup', [
152+
'channel' => $channel
153+
]);
154+
155+
if ($response->successful()) {
156+
return response()->json(['message' => 'Canal colgado correctamente']);
157+
}
158+
159+
return response()->json(['error' => 'No se pudo colgar el canal'], 500);
160+
}
161+
162+
public function pausedExtension(Request $request)
163+
{
164+
$extension = $request->input('extension');
165+
166+
$response = Http::post('http://10.57.251.181:3000/channel/hangup', [
167+
'channel' => $extension
168+
]);
169+
170+
if ($response->successful()) {
171+
return response()->json(['message' => 'Extension pausada correctamente']);
172+
}
173+
174+
return response()->json(['error' => 'No se pudo colgar el canal'], 500);
175+
}
176+
111177
}

package-lock.json

Lines changed: 53 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@
5454
"flowbite": "^3.1.2",
5555
"flowbite-react": "^0.11.7",
5656
"globals": "^15.14.0",
57+
"jssip": "^3.10.1",
5758
"laravel-vite-plugin": "^1.0",
5859
"lucide-react": "^0.475.0",
5960
"react": "^19.0.0",
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
// resources/js/components/actionsAgent/deleteCall.js
2+
export default async function hangupChannel(channel) {
3+
try {
4+
const response = await fetch('/api/hangup-channel', {
5+
method: 'POST',
6+
headers: {
7+
'Content-Type': 'application/json',
8+
Accept: 'application/json',
9+
},
10+
body: JSON.stringify({ channel }),
11+
});
12+
13+
const data = await response.json();
14+
15+
if (response.ok) {
16+
return { success: true, message: data.message };
17+
} else {
18+
return { success: false, message: data.error || 'Error desconocido' };
19+
}
20+
} catch (error) {
21+
console.error('Error colgando canal:', error);
22+
return { success: false, message: 'Error de red o servidor' };
23+
}
24+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
2+
export default async function pausedExtension(extension) {
3+
try {
4+
const response = await fetch('/api/paused-extension', {
5+
method: 'POST',
6+
headers: {
7+
'Content-Type': 'application/json',
8+
Accept: 'application/json',
9+
},
10+
body: JSON.stringify({ extension }),
11+
});
12+
13+
const data = await response.json();
14+
15+
if (response.ok) {
16+
return { success: true, message: data.message };
17+
} else {
18+
return { success: false, message: data.error || 'Error desconocido' };
19+
}
20+
} catch (error) {
21+
console.error('Error pausando extension:', error);
22+
return { success: false, message: 'Error de red o servidor' };
23+
}
24+
}

0 commit comments

Comments
 (0)