KI-AGENT: Lokalen Asterisk-Teststack ergänzen

This commit is contained in:
2026-05-20 22:18:58 +02:00
parent 4b85ea3d2d
commit 10f03e151d
22 changed files with 654 additions and 0 deletions

View File

@@ -56,6 +56,23 @@ NUXT_PUBLIC_PDF_LICENSE=replace-with-your-pdf-license
# Interner Prometheus Node Exporter für die Admin-Systemstatusseite. # Interner Prometheus Node Exporter für die Admin-Systemstatusseite.
NODE_EXPORTER_URL=http://node-exporter:9100 NODE_EXPORTER_URL=http://node-exporter:9100
# Lokaler Asterisk-Test für SIP/Voice. Aktivieren, wenn das Compose-Profil
# `telephony-dev` genutzt wird.
TELEPHONY_ENABLED=false
ASTERISK_IMAGE=andrius/asterisk:20
TELEPHONY_ASTERISK_HTTP_URL=http://asterisk-dev:8088/ws
TELEPHONY_ASTERISK_WS_URL=ws://localhost:8088/ws
TELEPHONY_SIP_DOMAIN=localhost
TELEPHONY_TEST_EXTENSION=1001
TELEPHONY_TEST_PASSWORD=fedeo-test-1001
TELEPHONY_TEST_EXTENSION_2=1002
TELEPHONY_TEST_PASSWORD_2=fedeo-test-1002
TELEPHONY_ECHO_EXTENSION=600
TELEPHONY_DEV_WS_PORT=8088
TELEPHONY_DEV_SIP_PORT=5060
TELEPHONY_DEV_RTP_MIN_PORT=10000
TELEPHONY_DEV_RTP_MAX_PORT=10020
# Optionaler Erststart-Bootstrap. Wenn gesetzt, werden Admin, Mandant, # Optionaler Erststart-Bootstrap. Wenn gesetzt, werden Admin, Mandant,
# Admin-Rolle und Grunddaten beim Backend-Start idempotent angelegt. # Admin-Rolle und Grunddaten beim Backend-Start idempotent angelegt.
FEDEO_BOOTSTRAP_ADMIN_EMAIL=admin@example.com FEDEO_BOOTSTRAP_ADMIN_EMAIL=admin@example.com

View File

@@ -32,6 +32,7 @@ import wikiRoutes from "./routes/wiki";
import portalContractRoutes from "./routes/portal/contracts"; import portalContractRoutes from "./routes/portal/contracts";
import mcpRoutes from "./routes/mcp"; import mcpRoutes from "./routes/mcp";
import communicationRoutes from "./routes/communication"; import communicationRoutes from "./routes/communication";
import telephonyRoutes from "./routes/telephony";
//Public Links //Public Links
import publiclinksNonAuthenticatedRoutes from "./routes/publiclinks/publiclinks-non-authenticated"; import publiclinksNonAuthenticatedRoutes from "./routes/publiclinks/publiclinks-non-authenticated";
@@ -154,6 +155,7 @@ async function main() {
await subApp.register(portalContractRoutes); await subApp.register(portalContractRoutes);
await subApp.register(mcpRoutes); await subApp.register(mcpRoutes);
await subApp.register(communicationRoutes); await subApp.register(communicationRoutes);
await subApp.register(telephonyRoutes);
},{prefix: "/api"}) },{prefix: "/api"})

View File

@@ -0,0 +1,93 @@
import { FastifyInstance } from "fastify"
const envFlag = (value: string | undefined, fallback: boolean) => {
if (value === undefined || value === "") return fallback
return ["1", "true", "yes", "on"].includes(value.toLowerCase())
}
const telephonyEnabled = () =>
envFlag(process.env.TELEPHONY_ENABLED, process.env.NODE_ENV !== "production")
const asteriskHttpStatusUrl = () =>
process.env.TELEPHONY_ASTERISK_HTTP_URL || "http://asterisk-dev:8088/ws"
const publicAsteriskWsUrl = () =>
process.env.TELEPHONY_ASTERISK_WS_URL || `ws://localhost:${process.env.TELEPHONY_DEV_WS_PORT || "8088"}/ws`
const sipDomain = () =>
process.env.TELEPHONY_SIP_DOMAIN || "localhost"
const testAccounts = () => [
{
extension: process.env.TELEPHONY_TEST_EXTENSION || "1001",
password: process.env.TELEPHONY_TEST_PASSWORD || "fedeo-test-1001",
displayName: "FEDEO Test 1001",
},
{
extension: process.env.TELEPHONY_TEST_EXTENSION_2 || "1002",
password: process.env.TELEPHONY_TEST_PASSWORD_2 || "fedeo-test-1002",
displayName: "FEDEO Test 1002",
},
]
const fetchWithTimeout = async (url: string, timeoutMs = 2500) => {
const controller = new AbortController()
const timeout = setTimeout(() => controller.abort(), timeoutMs)
try {
return await fetch(url, { signal: controller.signal })
} finally {
clearTimeout(timeout)
}
}
export default async function telephonyRoutes(server: FastifyInstance) {
server.get("/telephony/config", async () => ({
enabled: telephonyEnabled(),
provider: "asterisk",
mode: "local-test",
sipDomain: sipDomain(),
sipWebSocketUrl: publicAsteriskWsUrl(),
echoExtension: process.env.TELEPHONY_ECHO_EXTENSION || "600",
testAccounts: testAccounts(),
}))
server.get("/telephony/status", async () => {
const enabled = telephonyEnabled()
const url = asteriskHttpStatusUrl()
if (!enabled) {
return {
enabled,
provider: "asterisk",
reachable: false,
statusUrl: url,
message: "Telefonie ist nicht aktiviert.",
}
}
try {
const response = await fetchWithTimeout(url)
return {
enabled,
provider: "asterisk",
reachable: true,
statusCode: response.status,
statusUrl: url,
message: response.ok
? "Asterisk ist erreichbar."
: `Asterisk-HTTP ist erreichbar (HTTP ${response.status}).`,
}
} catch (error: any) {
return {
enabled,
provider: "asterisk",
reachable: false,
statusUrl: url,
message: error?.name === "AbortError"
? "Asterisk-Statusabfrage ist abgelaufen."
: (error?.message || "Asterisk ist nicht erreichbar."),
}
}
})
}

View File

@@ -57,6 +57,15 @@ services:
- WEB_PUSH_PRIVATE_KEY=${WEB_PUSH_PRIVATE_KEY:-} - WEB_PUSH_PRIVATE_KEY=${WEB_PUSH_PRIVATE_KEY:-}
- WEB_PUSH_SUBJECT=${WEB_PUSH_SUBJECT:-mailto:admin@example.com} - WEB_PUSH_SUBJECT=${WEB_PUSH_SUBJECT:-mailto:admin@example.com}
- NODE_EXPORTER_URL=${NODE_EXPORTER_URL:-http://node-exporter:9100} - NODE_EXPORTER_URL=${NODE_EXPORTER_URL:-http://node-exporter:9100}
- TELEPHONY_ENABLED=${TELEPHONY_ENABLED:-false}
- TELEPHONY_ASTERISK_HTTP_URL=${TELEPHONY_ASTERISK_HTTP_URL:-http://asterisk-dev:8088/ws}
- TELEPHONY_ASTERISK_WS_URL=${TELEPHONY_ASTERISK_WS_URL:-ws://localhost:8088/ws}
- TELEPHONY_SIP_DOMAIN=${TELEPHONY_SIP_DOMAIN:-localhost}
- TELEPHONY_TEST_EXTENSION=${TELEPHONY_TEST_EXTENSION:-1001}
- TELEPHONY_TEST_PASSWORD=${TELEPHONY_TEST_PASSWORD:-fedeo-test-1001}
- TELEPHONY_TEST_EXTENSION_2=${TELEPHONY_TEST_EXTENSION_2:-1002}
- TELEPHONY_TEST_PASSWORD_2=${TELEPHONY_TEST_PASSWORD_2:-fedeo-test-1002}
- TELEPHONY_ECHO_EXTENSION=${TELEPHONY_ECHO_EXTENSION:-600}
networks: networks:
- traefik - traefik
labels: labels:
@@ -92,6 +101,20 @@ services:
networks: networks:
- traefik - traefik
asterisk-dev:
image: ${ASTERISK_IMAGE:-andrius/asterisk:20}
restart: unless-stopped
profiles:
- telephony-dev
volumes:
- ./telephony/asterisk:/etc/asterisk:ro
ports:
- "${TELEPHONY_DEV_WS_PORT:-8088}:8088"
- "${TELEPHONY_DEV_SIP_PORT:-5060}:5060/udp"
- "${TELEPHONY_DEV_RTP_MIN_PORT:-10000}-${TELEPHONY_DEV_RTP_MAX_PORT:-10020}:10000-10020/udp"
networks:
- traefik
matrix-db: matrix-db:
image: postgres:16-alpine image: postgres:16-alpine
restart: unless-stopped restart: unless-stopped

View File

@@ -80,6 +80,11 @@ const links = computed(() => {
to: "/communication/chat", to: "/communication/chat",
icon: "i-heroicons-chat-bubble-left-right" icon: "i-heroicons-chat-bubble-left-right"
}, },
{
label: "Telefonie",
to: "/communication/phone",
icon: "i-heroicons-phone"
},
featureEnabled("helpdesk") ? { featureEnabled("helpdesk") ? {
label: "Helpdesk", label: "Helpdesk",
to: "/helpdesk", to: "/helpdesk",

View File

@@ -0,0 +1,316 @@
<script setup>
const toast = useToast()
const { $api } = useNuxtApp()
const loading = ref(false)
const statusLoading = ref(false)
const websocketTesting = ref(false)
const config = ref(null)
const status = ref(null)
const websocketResult = ref(null)
const lastUpdated = ref(null)
const statusColor = computed(() => {
if (!status.value?.enabled) return "warning"
return status.value?.reachable ? "success" : "error"
})
const statusIcon = computed(() => {
if (!status.value?.enabled) return "i-heroicons-pause-circle"
return status.value?.reachable ? "i-heroicons-signal" : "i-heroicons-signal-slash"
})
const websocketColor = computed(() => {
if (!websocketResult.value) return "neutral"
return websocketResult.value.ok ? "success" : "error"
})
const loadTelephony = async () => {
loading.value = true
try {
const [configRes, statusRes] = await Promise.all([
$api("/api/telephony/config"),
$api("/api/telephony/status")
])
config.value = configRes
status.value = statusRes
lastUpdated.value = new Date()
} catch (error) {
toast.add({
title: "Telefonie-Status konnte nicht geladen werden",
color: "error"
})
} finally {
loading.value = false
}
}
const refreshStatus = async () => {
statusLoading.value = true
try {
status.value = await $api("/api/telephony/status")
lastUpdated.value = new Date()
} catch (error) {
toast.add({
title: "Asterisk-Status konnte nicht geprüft werden",
color: "error"
})
} finally {
statusLoading.value = false
}
}
const testWebSocket = async () => {
if (!config.value?.sipWebSocketUrl || websocketTesting.value) return
websocketTesting.value = true
websocketResult.value = null
await new Promise((resolve) => {
let settled = false
const socket = new WebSocket(config.value.sipWebSocketUrl, "sip")
const timer = window.setTimeout(() => {
if (settled) return
settled = true
socket.close()
websocketResult.value = {
ok: false,
message: "WebSocket-Verbindung ist abgelaufen."
}
resolve()
}, 3000)
socket.onopen = () => {
if (settled) return
settled = true
window.clearTimeout(timer)
websocketResult.value = {
ok: true,
message: "SIP-WebSocket ist aus dem Browser erreichbar."
}
socket.close()
resolve()
}
socket.onerror = () => {
if (settled) return
settled = true
window.clearTimeout(timer)
websocketResult.value = {
ok: false,
message: "SIP-WebSocket konnte nicht geöffnet werden."
}
resolve()
}
})
websocketTesting.value = false
}
onMounted(loadTelephony)
</script>
<template>
<div class="min-h-screen bg-gray-50 px-4 py-6 sm:px-6 lg:px-8">
<div class="mx-auto flex max-w-7xl flex-col gap-6">
<div class="flex flex-col gap-4 border-b border-gray-200 pb-5 lg:flex-row lg:items-end lg:justify-between">
<div>
<p class="text-sm font-medium text-primary-600">
Kommunikation
</p>
<h1 class="mt-1 text-2xl font-semibold text-gray-950">
Telefonie
</h1>
<p class="mt-2 max-w-3xl text-sm text-gray-600">
Lokaler Asterisk-Test für SIP, WebRTC und spätere Voice-Integration in FEDEO.
</p>
</div>
<div class="flex flex-wrap gap-2">
<UButton
icon="i-heroicons-arrow-path"
variant="soft"
:loading="loading"
@click="loadTelephony"
>
Aktualisieren
</UButton>
<UButton
to="/communication/chat"
icon="i-heroicons-chat-bubble-left-right"
variant="outline"
>
Zum Chat
</UButton>
</div>
</div>
<div class="grid gap-4 lg:grid-cols-[1.1fr_0.9fr]">
<UCard>
<template #header>
<div class="flex items-center justify-between gap-3">
<div>
<h2 class="text-base font-semibold text-gray-950">
Asterisk-Status
</h2>
<p class="mt-1 text-sm text-gray-500">
Backend-Abfrage gegen den lokalen Telefonie-Stack.
</p>
</div>
<UButton
icon="i-heroicons-signal"
variant="ghost"
:loading="statusLoading"
@click="refreshStatus"
/>
</div>
</template>
<div class="grid gap-4 sm:grid-cols-3">
<div class="rounded-lg border border-gray-200 bg-white p-4">
<div class="flex items-center gap-2">
<UIcon :name="statusIcon" :class="status?.reachable ? 'text-green-600' : 'text-amber-600'" />
<span class="text-sm font-medium text-gray-700">Status</span>
</div>
<p class="mt-3 text-lg font-semibold text-gray-950">
{{ status?.enabled ? (status?.reachable ? "Erreichbar" : "Nicht erreichbar") : "Deaktiviert" }}
</p>
</div>
<div class="rounded-lg border border-gray-200 bg-white p-4">
<div class="flex items-center gap-2">
<UIcon name="i-heroicons-server-stack" class="text-gray-500" />
<span class="text-sm font-medium text-gray-700">Provider</span>
</div>
<p class="mt-3 text-lg font-semibold text-gray-950">
{{ config?.provider || "asterisk" }}
</p>
</div>
<div class="rounded-lg border border-gray-200 bg-white p-4">
<div class="flex items-center gap-2">
<UIcon name="i-heroicons-phone-arrow-up-right" class="text-gray-500" />
<span class="text-sm font-medium text-gray-700">Echo-Test</span>
</div>
<p class="mt-3 text-lg font-semibold text-gray-950">
{{ config?.echoExtension || "600" }}
</p>
</div>
</div>
<UAlert
class="mt-4"
:color="statusColor"
:icon="statusIcon"
:title="status?.message || 'Telefonie wird geladen'"
:description="status?.statusUrl || 'Noch keine Status-URL geladen.'"
/>
</UCard>
<UCard>
<template #header>
<div>
<h2 class="text-base font-semibold text-gray-950">
Lokalen Stack starten
</h2>
<p class="mt-1 text-sm text-gray-500">
Asterisk läuft getrennt vom normalen Stack im Compose-Profil.
</p>
</div>
</template>
<div class="rounded-lg bg-gray-950 p-4 font-mono text-sm text-gray-100">
docker compose --profile telephony-dev up -d asterisk-dev
</div>
<div class="mt-4 grid gap-3 text-sm text-gray-600">
<div class="flex items-center justify-between gap-4">
<span>SIP-Domain</span>
<span class="font-mono text-gray-950">{{ config?.sipDomain || "localhost" }}</span>
</div>
<div class="flex items-center justify-between gap-4">
<span>WebSocket</span>
<span class="break-all text-right font-mono text-gray-950">{{ config?.sipWebSocketUrl || "-" }}</span>
</div>
</div>
</UCard>
</div>
<div class="grid gap-4 lg:grid-cols-[0.9fr_1.1fr]">
<UCard>
<template #header>
<div>
<h2 class="text-base font-semibold text-gray-950">
Browser-Test
</h2>
<p class="mt-1 text-sm text-gray-500">
Prüft, ob FEDEO den SIP-WebSocket im Browser öffnen kann.
</p>
</div>
</template>
<div class="flex flex-col gap-3">
<UButton
icon="i-heroicons-bolt"
:loading="websocketTesting"
:disabled="!config?.sipWebSocketUrl"
@click="testWebSocket"
>
WebSocket prüfen
</UButton>
<UAlert
v-if="websocketResult"
:color="websocketColor"
:icon="websocketResult.ok ? 'i-heroicons-check-circle' : 'i-heroicons-x-circle'"
:title="websocketResult.message"
/>
</div>
</UCard>
<UCard>
<template #header>
<div>
<h2 class="text-base font-semibold text-gray-950">
Test-Nebenstellen
</h2>
<p class="mt-1 text-sm text-gray-500">
Für den ersten lokalen Call-Test zwischen zwei Browser-Sessions.
</p>
</div>
</template>
<div class="grid gap-3 sm:grid-cols-2">
<div
v-for="account in config?.testAccounts || []"
:key="account.extension"
class="rounded-lg border border-gray-200 bg-white p-4"
>
<div class="flex items-center gap-2">
<UIcon name="i-heroicons-user-circle" class="text-primary-600" />
<h3 class="font-semibold text-gray-950">
{{ account.displayName }}
</h3>
</div>
<dl class="mt-4 grid gap-2 text-sm">
<div class="flex items-center justify-between gap-3">
<dt class="text-gray-500">Nebenstelle</dt>
<dd class="font-mono text-gray-950">{{ account.extension }}</dd>
</div>
<div class="flex items-center justify-between gap-3">
<dt class="text-gray-500">Passwort</dt>
<dd class="font-mono text-gray-950">{{ account.password }}</dd>
</div>
</dl>
</div>
</div>
</UCard>
</div>
<p v-if="lastUpdated" class="text-xs text-gray-500">
Zuletzt geprüft: {{ lastUpdated.toLocaleString("de-DE") }}
</p>
</div>
</div>
</template>

View File

@@ -0,0 +1 @@
[general]

View File

@@ -0,0 +1 @@
[general]

View File

@@ -0,0 +1,15 @@
[directories]
astetcdir => /etc/asterisk
astmoddir => /usr/lib/asterisk/modules
astvarlibdir => /var/lib/asterisk
astdbdir => /var/lib/asterisk
astkeydir => /var/lib/asterisk
astdatadir => /var/lib/asterisk
astagidir => /var/lib/asterisk/agi-bin
astspooldir => /var/spool/asterisk
astrundir => /var/run/asterisk
astlogdir => /var/log/asterisk
astsbindir => /usr/sbin
[options]
documentation_language => en_US

View File

@@ -0,0 +1,2 @@
[general]
cc_max_requests=0

View File

@@ -0,0 +1,2 @@
[general]
enable=no

View File

@@ -0,0 +1,2 @@
[general]
enable=no

View File

@@ -0,0 +1,15 @@
[general]
static=yes
writeprotect=no
clearglobalvars=no
[fedeo-local]
exten => 1001,1,Dial(PJSIP/1001,30)
same => n,Hangup()
exten => 1002,1,Dial(PJSIP/1002,30)
same => n,Hangup()
exten => 600,1,Answer()
same => n,Echo()
same => n,Hangup()

View File

@@ -0,0 +1 @@
[general]

View File

@@ -0,0 +1,6 @@
[general]
enabled=yes
bindaddr=0.0.0.0
bindport=8088
prefix=
tlsenable=no

View File

@@ -0,0 +1,6 @@
[general]
dateformat=%F %T
[logfiles]
console => notice,warning,error,verbose
messages => notice,warning,error

View File

@@ -0,0 +1,2 @@
[general]
enabled=no

View File

@@ -0,0 +1,74 @@
[modules]
autoload=yes
; Für den lokalen FEDEO-Test laden wir Asterisk bewusst schlank.
; Diese optionalen Module erzeugen ohne zusätzliche Konfiguration nur Lograuschen.
noload => app_agent_pool.so
noload => app_alarmreceiver.so
noload => app_amd.so
noload => app_confbridge.so
noload => app_followme.so
noload => app_minivm.so
noload => app_page.so
noload => app_queue.so
noload => app_stasis.so
noload => app_voicemail.so
noload => cdr_csv.so
noload => cdr_adaptive_odbc.so
noload => cdr_custom.so
noload => cdr_manager.so
noload => cdr_odbc.so
noload => cdr_pgsql.so
noload => cdr_sqlite3_custom.so
noload => cel_custom.so
noload => cel_manager.so
noload => cel_odbc.so
noload => cel_pgsql.so
noload => cel_sqlite3_custom.so
noload => chan_websocket.so
noload => chan_console.so
noload => chan_iax2.so
noload => chan_unistim.so
noload => format_ogg_vorbis.so
noload => func_odbc.so
noload => pbx_ael.so
noload => pbx_dundi.so
noload => res_calendar.so
noload => res_clialiases.so
noload => res_config_ldap.so
noload => res_config_odbc.so
noload => res_config_pgsql.so
noload => res_config_sqlite3.so
noload => res_fax.so
noload => res_fax_spandsp.so
noload => res_geolocation.so
noload => res_hep.so
noload => res_hep_pjsip.so
noload => res_hep_rtcp.so
noload => res_http_media_cache.so
noload => res_musiconhold.so
noload => res_odbc.so
noload => res_odbc_transaction.so
noload => res_parking.so
noload => res_ari.so
noload => res_ari_applications.so
noload => res_ari_asterisk.so
noload => res_ari_bridges.so
noload => res_ari_channels.so
noload => res_ari_device_states.so
noload => res_ari_endpoints.so
noload => res_ari_events.so
noload => res_ari_model.so
noload => res_ari_playbacks.so
noload => res_ari_recordings.so
noload => res_ari_sounds.so
noload => res_phoneprov.so
noload => res_pjsip_geolocation.so
noload => res_pjsip_config_wizard.so
noload => res_pjsip_notify.so
noload => res_pjsip_phoneprov_provider.so
noload => res_prometheus.so
noload => res_smdi.so
noload => res_statsd.so
noload => res_stun_monitor.so
noload => res_websocket_client.so

View File

@@ -0,0 +1 @@
[startup]

View File

@@ -0,0 +1,64 @@
[global]
type=global
user_agent=FEDEO Local Asterisk
[transport-udp]
type=transport
protocol=udp
bind=0.0.0.0:5060
[transport-ws]
type=transport
protocol=ws
bind=0.0.0.0
[fedeo-webrtc](!)
type=endpoint
context=fedeo-local
disallow=all
allow=opus,ulaw,alaw
webrtc=yes
ice_support=yes
use_avpf=yes
media_encryption=dtls
dtls_auto_generate_cert=yes
dtls_verify=fingerprint
dtls_setup=actpass
rtcp_mux=yes
direct_media=no
force_rport=yes
rewrite_contact=yes
rtp_symmetric=yes
transport=transport-ws
[1001](fedeo-webrtc)
auth=1001-auth
aors=1001-aor
callerid=FEDEO Test 1001 <1001>
[1001-auth]
type=auth
auth_type=userpass
username=1001
password=fedeo-test-1001
[1001-aor]
type=aor
max_contacts=5
remove_existing=yes
[1002](fedeo-webrtc)
auth=1002-auth
aors=1002-aor
callerid=FEDEO Test 1002 <1002>
[1002-auth]
type=auth
auth_type=userpass
username=1002
password=fedeo-test-1002
[1002-aor]
type=aor
max_contacts=5
remove_existing=yes

View File

@@ -0,0 +1,5 @@
[general]
rtpstart=10000
rtpend=10020
icesupport=yes
strictrtp=no

View File

@@ -0,0 +1 @@
[general]