- Embeddable vanilla-JS chat widget (one script tag + tenant public key):
WebSocket, resumable sessions (24h localStorage token), honeypot + per-IP
and per-message rate limits, Bosnian UI (§7)
- Session auth (bcrypt + signed cookies), owner accounts + super-admins,
admin impersonation ('otvori kao salon', §11)
- Owner dashboard (§10, Bosnian): requests with same actions as email,
call/chat history with transcripts, usage bar; settings for profile,
working hours (manual + LLM paste-to-parse), services CRUD + 'Zalijepi
cjenovnik' LLM import with review step, scheduling (Google OAuth free/busy
read-only + calendar mappings + buffers, partner status), telephony
(forwarding MMI codes per operator, ring group, worker SIP creds + QR),
agent voice/price-mode/notes + widget snippet, notifications/SMS templates
- Super-admin panel (§11): tenant CRUD incl. plan/minutes/paid-until,
partner API config (encrypted secrets), number/SIM registry + assignment,
connectivity test (live availability + dry-run push), versioned prompt
template editor with publish/rollback, playground, usage overview, health
- Fixes: WAL + busy_timeout for sqlite tests, no awaits in WS disconnect
path (deadlock), template publish autoflush bug
- 76 tests green (incl. widget WS e2e booking flow); dashboard, widget and
admin verified live in a browser against Postgres
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
54 lines
1.5 KiB
Python
54 lines
1.5 KiB
Python
"""SIP credential provisioning for ring-group workers (§5.3).
|
|
|
|
Workers exist only as SIP endpoints — no product accounts. The dashboard shows
|
|
generated credentials + a QR code for quick softphone setup (Linphone/Zoiper/
|
|
Groundwire all accept manual entry; the QR encodes a standard sip URI plus the
|
|
fields spelled out).
|
|
"""
|
|
|
|
from __future__ import annotations
|
|
|
|
import io
|
|
import re
|
|
import secrets
|
|
|
|
from gogo.config import get_settings
|
|
|
|
|
|
def make_sip_username(tenant_slug: str, worker_name: str, suffix: str | None = None) -> str:
|
|
base = re.sub(r"[^a-z0-9]+", "", worker_name.lower())[:12] or "radnik"
|
|
suffix = suffix or secrets.token_hex(2)
|
|
return f"{tenant_slug[:16]}-{base}-{suffix}"
|
|
|
|
|
|
def make_sip_password() -> str:
|
|
return secrets.token_urlsafe(12)
|
|
|
|
|
|
def sip_domain() -> str:
|
|
"""SIP registrar host — derived from base_url; overridable later if split hosts."""
|
|
from urllib.parse import urlparse
|
|
|
|
return urlparse(get_settings().base_url).hostname or "localhost"
|
|
|
|
|
|
def provisioning_text(sip_username: str, sip_password: str) -> str:
|
|
"""Payload for the QR code: sip URI + explicit fields (readable by humans too)."""
|
|
domain = sip_domain()
|
|
return (
|
|
f"sip:{sip_username}@{domain}\n"
|
|
f"Server/Domain: {domain}\n"
|
|
f"Username: {sip_username}\n"
|
|
f"Password: {sip_password}\n"
|
|
f"Transport: UDP 5060"
|
|
)
|
|
|
|
|
|
def qr_png(payload: str) -> bytes:
|
|
import qrcode
|
|
|
|
img = qrcode.make(payload)
|
|
buf = io.BytesIO()
|
|
img.save(buf, format="PNG")
|
|
return buf.getvalue()
|