Skip to content

Speakr is a personal, self-hosted web application designed for transcribing audio recordings

Python

Webhooks Phase 2: account-settings tab with list/edit/test/deliveries/rotate + 16 i18n keys per locale (#275)

Murtaza Nasir5afaaee9f740
diff --git a/static/js/account-webhooks.js b/static/js/account-webhooks.js
new file mode 100644
index 00000000..32720410
--- /dev/null
+++ b/static/js/account-webhooks.js
@@ -0,0 +1,286 @@
+/* Webhooks tab for the Account settings page (#275).
+ *
+ * Self-contained module attached when the Account template loads.
+ * Talks to /api/v1/webhooks; all user-supplied strings are escaped
+ * via escapeHtml() before being written into the DOM.
+ */
+(function () {
+ const list = document.getElementById('webhook-list');
+ const modal = document.getElementById('webhook-modal');
+ const modalTitle = document.getElementById('webhook-modal-title');
+ const idInput = document.getElementById('webhook-id-input');
+ const nameInput = document.getElementById('webhook-name-input');
+ const urlInput = document.getElementById('webhook-url-input');
+ const allowHttpInput = document.getElementById('webhook-allow-http-input');
+ const enabledInput = document.getElementById('webhook-enabled-input');
+ const eventsContainer = document.getElementById('webhook-events-checkboxes');
+ const form = document.getElementById('webhook-form');
+ const createBtn = document.getElementById('webhook-create-btn');
+ const closeBtn = document.getElementById('webhook-modal-close');
+ const cancelBtn = document.getElementById('webhook-modal-cancel');
+ const secretBanner = document.getElementById('webhook-secret-banner');
+ const secretValueEl = document.getElementById('webhook-secret-value');
+ const secretCopyBtn = document.getElementById('webhook-secret-copy');
+ const secretDismissBtn = document.getElementById('webhook-secret-dismiss');
+
+ if (!list) return; // template not on this page
+
+ const csrfToken = () => {
+ const el = document.querySelector('meta[name="csrf-token"]');
+ return el ? el.getAttribute('content') : '';
+ };
+
+ let allEventTypes = [];
+
+ async function fetchJson(url, opts = {}) {
+ const headers = Object.assign(
+ { 'Content-Type': 'application/json', 'X-CSRFToken': csrfToken() },
+ opts.headers || {}
+ );
+ const resp = await fetch(url, Object.assign({}, opts, { headers, credentials: 'same-origin' }));
+ const text = await resp.text();
+ let body = null;
+ try { body = text ? JSON.parse(text) : null; } catch (_) { body = null; }
+ if (!resp.ok) {
+ const err = new Error((body && body.error) || ('HTTP ' + resp.status));
+ err.status = resp.status;
+ throw err;
+ }
+ return body;
+ }
+
+ function escapeHtml(s) {
+ const d = document.createElement('div');
+ d.textContent = s == null ? '' : String(s);
+ return d.innerHTML;
+ }
+
+ function fmt(dt) {
+ if (!dt) return '—';
+ try { return new Date(dt).toLocaleString(); } catch (_) { return String(dt); }
+ }
+
+ function statusBadge(wh) {
+ if (wh.auto_paused) return '<span class="text-xs px-2 py-0.5 rounded bg-amber-500/15 text-amber-600">auto-paused</span>';
+ if (!wh.enabled) return '<span class="text-xs px-2 py-0.5 rounded bg-gray-500/15 text-gray-500">disabled</span>';
+ if (wh.consecutive_failures > 0) return '<span class="text-xs px-2 py-0.5 rounded bg-red-500/15 text-red-500">' + Number(wh.consecutive_failures) + ' consecutive failures</span>';
+ return '<span class="text-xs px-2 py-0.5 rounded bg-emerald-500/15 text-emerald-600">healthy</span>';
+ }
+
+ function deliveryStatusBadge(d) {
+ const cls = {
+ success: 'bg-emerald-500/15 text-emerald-600',
+ pending: 'bg-blue-500/15 text-blue-500',
+ failed: 'bg-amber-500/15 text-amber-600',
+ permanent_failure: 'bg-red-500/15 text-red-500'
+ }[d.status] || 'bg-gray-500/15 text-gray-500';
+ return '<span class="text-xs px-2 py-0.5 rounded ' + cls + '">' + escapeHtml(d.status) + '</span>';
+ }
+
+ function eventChips(events) {
+ if (!events || !events.length) return '<span class="text-xs text-[var(--text-muted)]">no events</span>';
+ return events.map(function (e) {
+ return '<span class="text-xs px-2 py-0.5 rounded bg-[var(--bg-tertiary)] text-[var(--text-secondary)] mr-1 mb-1 inline-block">' + escapeHtml(e) + '</span>';
+ }).join('');
+ }
+
+ function renderWebhookCard(wh) {
+ const id = Number(wh.id);
+ return ''
+ + '<div class="border border-[var(--border-primary)] rounded-lg p-4 bg-[var(--bg-secondary)]" data-webhook-id="' + id + '">'
+ + '<div class="flex items-start justify-between gap-3 flex-wrap">'
+ + '<div class="flex-1 min-w-0">'
+ + '<div class="flex items-center gap-2 flex-wrap">'
+ + '<h3 class="text-sm font-semibold text-[var(--text-primary)]">' + escapeHtml(wh.name) + '</h3>'
+ + statusBadge(wh)
+ + '</div>'
+ + '<p class="mt-1 text-xs font-mono text-[var(--text-muted)] break-all">' + escapeHtml(wh.url) + '</p>'
+ + '<div class="mt-2">' + eventChips(wh.events) + '</div>'
+ + '<p class="mt-2 text-xs text-[var(--text-muted)]">Last delivery: ' + escapeHtml(fmt(wh.last_delivery_at)) + '</p>'
+ + '</div>'
+ + '<div class="flex flex-wrap items-center gap-2 shrink-0">'
+ + '<button data-action="test" class="px-2 py-1 text-xs rounded bg-[var(--bg-tertiary)] hover:bg-[var(--bg-button-hover)] text-[var(--text-secondary)]" title="Send a synthetic webhook.test event"><i class="fas fa-paper-plane mr-1"></i>Test</button>'
+ + '<button data-action="deliveries" class="px-2 py-1 text-xs rounded bg-[var(--bg-tertiary)] hover:bg-[var(--bg-button-hover)] text-[var(--text-secondary)]"><i class="fas fa-list mr-1"></i>Deliveries</button>'
+ + '<button data-action="rotate" class="px-2 py-1 text-xs rounded bg-[var(--bg-tertiary)] hover:bg-[var(--bg-button-hover)] text-[var(--text-secondary)]" title="Rotate HMAC secret"><i class="fas fa-key mr-1"></i>Rotate</button>'
+ + '<button data-action="edit" class="px-2 py-1 text-xs rounded bg-[var(--bg-tertiary)] hover:bg-[var(--bg-button-hover)] text-[var(--text-secondary)]"><i class="fas fa-pen mr-1"></i>Edit</button>'
+ + '<button data-action="delete" class="px-2 py-1 text-xs rounded bg-red-500/10 hover:bg-red-500/20 text-red-500"><i class="fas fa-trash mr-1"></i>Delete</button>'
+ + '</div>'
+ + '</div>'
+ + '<div class="mt-3 hidden" data-deliveries-panel>'
+ + '<div class="border-t border-[var(--border-primary)] pt-3">'
+ + '<h4 class="text-xs font-medium text-[var(--text-muted)] mb-2">Recent deliveries</h4>'
+ + '<div data-deliveries-list class="space-y-1 text-xs"></div>'
+ + '</div>'
+ + '</div>'
+ + '</div>';
+ }
+
+ function showModalFor(webhook) {
+ modalTitle.textContent = webhook ? 'Edit webhook' : 'New webhook';
+ idInput.value = webhook ? webhook.id : '';
+ nameInput.value = webhook ? webhook.name : '';
+ urlInput.value = webhook ? webhook.url : '';
+ allowHttpInput.checked = webhook ? !!webhook.allow_http : false;
+ enabledInput.checked = webhook ? !!webhook.enabled : true;
+ const subscribed = (webhook && webhook.events) || [];
+ const checkboxes = allEventTypes
+ .filter(function (e) { return e !== 'webhook.test'; })
+ .map(function (e) {
+ const checked = subscribed.indexOf(e) !== -1 ? 'checked' : '';
+ return ''
+ + '<label class="inline-flex items-center gap-2 text-sm">'
+ + '<input type="checkbox" value="' + escapeHtml(e) + '" class="rounded border-[var(--border-secondary)]" ' + checked + '>'
+ + '<span class="font-mono text-xs">' + escapeHtml(e) + '</span>'
+ + '</label>';
+ }).join('');
+ eventsContainer.replaceChildren();
+ eventsContainer.insertAdjacentHTML('afterbegin', checkboxes);
+ modal.classList.remove('hidden');
+ }
+
+ function hideModal() { modal.classList.add('hidden'); }
+
+ function showSecretBanner(secret) {
+ secretValueEl.textContent = secret;
+ secretBanner.classList.remove('hidden');
+ try { secretBanner.scrollIntoView({ behavior: 'smooth', block: 'start' }); } catch (_) {}
+ }
+
+ async function loadWebhooks() {
+ try {
+ const body = await fetchJson('/api/v1/webhooks');
+ allEventTypes = body.event_types || [];
+ list.replaceChildren();
+ if (!body.webhooks || body.webhooks.length === 0) {
+ list.insertAdjacentHTML('beforeend', '<p class="text-sm text-[var(--text-muted)]">No webhooks configured. Add one to start receiving event notifications.</p>');
+ return;
+ }
+ body.webhooks.forEach(function (wh) { list.insertAdjacentHTML('beforeend', renderWebhookCard(wh)); });
+ list.querySelectorAll('[data-webhook-id]').forEach(function (card) {
+ const id = card.getAttribute('data-webhook-id');
+ card.querySelectorAll('[data-action]').forEach(function (btn) {
+ btn.addEventListener('click', function () { onCardAction(id, btn.dataset.action, card); });
+ });
+ });
+ } catch (e) {
+ list.replaceChildren();
+ list.insertAdjacentHTML('beforeend', '<p class="text-sm text-red-500">Error loading webhooks: ' + escapeHtml(e.message) + '</p>');
+ }
+ }
+ window.loadWebhooks = loadWebhooks;
+
+ async function onCardAction(id, action, card) {
+ try {
+ if (action === 'edit') {
+ const wh = await fetchJson('/api/v1/webhooks/' + Number(id));
+ showModalFor(wh);
+ } else if (action === 'delete') {
+ if (!confirm('Delete this webhook? Past deliveries will be removed too.')) return;
+ await fetchJson('/api/v1/webhooks/' + Number(id), { method: 'DELETE' });
+ await loadWebhooks();
+ } else if (action === 'test') {
+ await fetchJson('/api/v1/webhooks/' + Number(id) + '/test', { method: 'POST' });
+ alert('Test event queued. Check Deliveries in a few seconds.');
+ } else if (action === 'rotate') {
+ if (!confirm('Rotate the HMAC secret? Any receiver that already has the current secret will start failing until you update it.')) return;
+ const body = await fetchJson('/api/v1/webhooks/' + Number(id) + '/rotate-secret', { method: 'POST' });
+ if (body && body.secret) showSecretBanner(body.secret);
+ await loadWebhooks();
+ } else if (action === 'deliveries') {
+ const panel = card.querySelector('[data-deliveries-panel]');
+ const listEl = card.querySelector('[data-deliveries-list]');
+ if (!panel.classList.contains('hidden')) { panel.classList.add('hidden'); return; }
+ listEl.replaceChildren();
+ listEl.insertAdjacentHTML('beforeend', '<p class="text-xs text-[var(--text-muted)]">Loading...</p>');
+ panel.classList.remove('hidden');
+ const body = await fetchJson('/api/v1/webhooks/' + Number(id) + '/deliveries?limit=25');
+ listEl.replaceChildren();
+ if (!body.deliveries || body.deliveries.length === 0) {
+ listEl.insertAdjacentHTML('beforeend', '<p class="text-xs text-[var(--text-muted)]">No deliveries yet.</p>');
+ return;
+ }
+ body.deliveries.forEach(function (d) {
+ const httpStatus = d.response_status ? '<span class="text-xs text-[var(--text-muted)]">HTTP ' + Number(d.response_status) + '</span>' : '';
+ const errLine = d.error_message ? '<div class="text-xs text-red-500 mt-0.5 break-all">' + escapeHtml(d.error_message) + '</div>' : '';
+ const retryLine = d.next_retry_at ? ' · next retry: ' + escapeHtml(fmt(d.next_retry_at)) : '';
+ const row = ''
+ + '<div class="flex items-center justify-between gap-2 py-1 border-b border-[var(--border-primary)] last:border-0">'
+ + '<div class="flex-1 min-w-0">'
+ + '<div class="flex items-center gap-2 flex-wrap">'
+ + '<span class="font-mono text-xs text-[var(--text-secondary)]">' + escapeHtml(d.event_type) + '</span>'
+ + deliveryStatusBadge(d)
+ + httpStatus
+ + '</div>'
+ + '<div class="text-xs text-[var(--text-muted)] mt-0.5">' + escapeHtml(fmt(d.created_at)) + ' · attempts: ' + Number(d.attempt_count) + retryLine + '</div>'
+ + errLine
+ + '</div>'
+ + '<button class="text-xs text-[var(--text-muted)] hover:text-[var(--text-primary)]" data-replay="' + Number(d.id) + '" title="Replay this delivery"><i class="fas fa-redo"></i></button>'
+ + '</div>';
+ listEl.insertAdjacentHTML('beforeend', row);
+ });
+ listEl.querySelectorAll('[data-replay]').forEach(function (btn) {
+ btn.addEventListener('click', async function () {
+ const did = btn.getAttribute('data-replay');
+ try {
+ await fetchJson('/api/v1/webhooks/' + Number(id) + '/deliveries/' + Number(did) + '/replay', { method: 'POST' });
+ // Close and reopen to refresh
+ panel.classList.add('hidden');
+ onCardAction(id, 'deliveries', card);
+ } catch (e2) {
+ alert('Replay failed: ' + e2.message);
+ }
+ });
+ });
+ }
+ } catch (e) {
+ alert('Error: ' + e.message);
+ }
+ }
+
+ createBtn?.addEventListener('click', function () { showModalFor(null); });
+ closeBtn?.addEventListener('click', hideModal);
+ cancelBtn?.addEventListener('click', hideModal);
+ modal?.addEventListener('click', function (e) { if (e.target === modal) hideModal(); });
+
+ form?.addEventListener('submit', async function (e) {
+ e.preventDefault();
+ const events = Array.from(eventsContainer.querySelectorAll('input[type=checkbox]:checked')).map(function (cb) { return cb.value; });
+ if (events.length === 0) { alert('Pick at least one event to subscribe to.'); return; }
+ const payload = {
+ name: nameInput.value.trim(),
+ url: urlInput.value.trim(),
+ allow_http: !!allowHttpInput.checked,
+ enabled: !!enabledInput.checked,
+ events: events
+ };
+ try {
+ const id = idInput.value;
+ if (id) {
+ await fetchJson('/api/v1/webhooks/' + Number(id), { method: 'PATCH', body: JSON.stringify(payload) });
+ hideModal();
+ await loadWebhooks();
+ } else {
+ const body = await fetchJson('/api/v1/webhooks', { method: 'POST', body: JSON.stringify(payload) });
+ hideModal();
+ if (body && body.secret) showSecretBanner(body.secret);
+ await loadWebhooks();
+ }
+ } catch (e2) {
+ alert('Save failed: ' + e2.message);
+ }
+ });
+
+ secretCopyBtn?.addEventListener('click', async function () {
+ try {
+ await navigator.clipboard.writeText(secretValueEl.textContent || '');
+ secretCopyBtn.textContent = 'Copied!';
+ setTimeout(function () { secretCopyBtn.textContent = 'Copy'; }, 1500);
+ } catch (e) {
+ alert('Could not copy to clipboard: ' + e.message);
+ }
+ });
+ secretDismissBtn?.addEventListener('click', function () {
+ secretBanner.classList.add('hidden');
+ secretValueEl.textContent = '';
+ });
+})();
diff --git a/static/locales/de.json b/static/locales/de.json
index c1249da6..644ab516 100644
--- a/static/locales/de.json
+++ b/static/locales/de.json
@@ -118,7 +118,8 @@
"tagManagement": "Tag-Verwaltung",
"templates": "Vorlagen",
"transcriptTemplates": "Transkript-Vorlagen",
- "preferences": "Einstellungen"
+ "preferences": "Einstellungen",
+ "webhooks": "Webhooks"
},
"admin": {
"title": "Administration",
@@ -1589,5 +1590,22 @@
"recordingMaxDurationReached": "Aufnahme hat die Höchstdauer erreicht und wurde automatisch gestoppt.",
"recordingFinalized": "Aufnahme zur Verarbeitung hochgeladen",
"recordingResumeFound": "Eine laufende Aufnahme aus diesem Browser wurde auf dem Server gefunden. Fortsetzen?"
+ },
+ "webhooks": {
+ "title": "Webhooks",
+ "subtitle": "HTTP-Benachrichtigungen empfangen, wenn sich Aufnahmen ändern. Jeder Endpunkt wird mit HMAC-SHA256 signiert, damit Empfänger die Echtheit prüfen können.",
+ "addNew": "Webhook hinzufügen",
+ "loading": "Lädt...",
+ "modalTitleNew": "Neuer Webhook",
+ "modalTitleEdit": "Webhook bearbeiten",
+ "nameLabel": "Name",
+ "urlLabel": "URL",
+ "allowHttp": "http:// erlauben (nur Intranet-Endpunkte)",
+ "eventsLabel": "Ereignisse",
+ "enabled": "Aktiv",
+ "saveButton": "Webhook speichern",
+ "secretBannerTitle": "Geheimnis jetzt kopieren — es wird nicht erneut angezeigt",
+ "secretBannerHint": "Signieren Sie jede Empfänger-Anfrage: HMAC-SHA256 des Rohkörpers mit diesem Geheimnis. Header: Speakr-Signature: sha256=<hex>",
+ "copy": "Kopieren"
}
}
diff --git a/static/locales/en.json b/static/locales/en.json
index 4009be32..612b11f2 100644
--- a/static/locales/en.json
+++ b/static/locales/en.json
@@ -118,7 +118,8 @@
"speakersManagement": "Speakers Management",
"tagManagement": "Tag Management",
"templates": "Templates",
- "transcriptTemplates": "Transcript Templates"
+ "transcriptTemplates": "Transcript Templates",
+ "webhooks": "Webhooks"
},
"admin": {
"title": "Admin",
@@ -1589,5 +1590,22 @@
"recordingMaxDurationReached": "Recording reached the maximum duration and was stopped automatically.",
"recordingFinalized": "Recording uploaded for processing",
"recordingResumeFound": "An in-progress recording from this browser was detected on the server. Resume?"
+ },
+ "webhooks": {
+ "title": "Webhooks",
+ "subtitle": "Receive HTTP notifications when recordings change. Each endpoint is signed with HMAC-SHA256 so receivers can verify authenticity.",
+ "addNew": "Add webhook",
+ "loading": "Loading...",
+ "modalTitleNew": "New webhook",
+ "modalTitleEdit": "Edit webhook",
+ "nameLabel": "Name",
+ "urlLabel": "URL",
+ "allowHttp": "Allow http:// (intranet endpoints only)",
+ "eventsLabel": "Events",
+ "enabled": "Enabled",
+ "saveButton": "Save webhook",
+ "secretBannerTitle": "Copy this secret now — it will not be shown again",
+ "secretBannerHint": "Sign every receiver request: HMAC-SHA256 of the raw body using this secret. Header: Speakr-Signature: sha256=<hex>",
+ "copy": "Copy"
}
}
diff --git a/static/locales/es.json b/static/locales/es.json
index 44b81f45..43f91d24 100644
--- a/static/locales/es.json
+++ b/static/locales/es.json
@@ -118,7 +118,8 @@
"tagManagement": "Gestión de Etiquetas",
"templates": "Plantillas",
"transcriptTemplates": "Plantillas de Transcripción",
- "preferences": "Preferencias"
+ "preferences": "Preferencias",
+ "webhooks": "Webhooks"
},
"admin": {
"title": "Administración",
@@ -1589,5 +1590,22 @@
"recordingMaxDurationReached": "La grabación alcanzó la duración máxima y se detuvo automáticamente.",
"recordingFinalized": "Grabación subida para procesamiento",
"recordingResumeFound": "Se detectó una grabación en curso de este navegador en el servidor. ¿Reanudar?"
+ },
+ "webhooks": {
+ "title": "Webhooks",
+ "subtitle": "Reciba notificaciones HTTP cuando cambien las grabaciones. Cada endpoint está firmado con HMAC-SHA256 para que los receptores puedan verificar la autenticidad.",
+ "addNew": "Añadir webhook",
+ "loading": "Cargando...",
+ "modalTitleNew": "Nuevo webhook",
+ "modalTitleEdit": "Editar webhook",
+ "nameLabel": "Nombre",
+ "urlLabel": "URL",
+ "allowHttp": "Permitir http:// (solo endpoints de intranet)",
+ "eventsLabel": "Eventos",
+ "enabled": "Habilitado",
+ "saveButton": "Guardar webhook",
+ "secretBannerTitle": "Copie este secreto ahora — no se mostrará otra vez",
+ "secretBannerHint": "Firme cada solicitud del receptor: HMAC-SHA256 del cuerpo crudo usando este secreto. Cabecera: Speakr-Signature: sha256=<hex>",
+ "copy": "Copiar"
}
}
diff --git a/static/locales/fr.json b/static/locales/fr.json
index 39bfe30e..ec83537f 100644
--- a/static/locales/fr.json
+++ b/static/locales/fr.json
@@ -118,7 +118,8 @@
"tagManagement": "Gestion des Étiquettes",
"templates": "Modèles",
"transcriptTemplates": "Modèles de Transcription",
- "preferences": "Préférences"
+ "preferences": "Préférences",
+ "webhooks": "Webhooks"
},
"admin": {
"title": "Administration",
@@ -1589,5 +1590,22 @@
"recordingMaxDurationReached": "L'enregistrement a atteint la durée maximale et s'est arrêté automatiquement.",
"recordingFinalized": "Enregistrement envoyé pour traitement",
"recordingResumeFound": "Un enregistrement en cours dans ce navigateur a été détecté sur le serveur. Reprendre ?"
+ },
+ "webhooks": {
+ "title": "Webhooks",
+ "subtitle": "Recevez des notifications HTTP lorsque les enregistrements changent. Chaque endpoint est signé en HMAC-SHA256 pour que les récepteurs puissent vérifier l'authenticité.",
+ "addNew": "Ajouter un webhook",
+ "loading": "Chargement...",
+ "modalTitleNew": "Nouveau webhook",
+ "modalTitleEdit": "Modifier le webhook",
+ "nameLabel": "Nom",
+ "urlLabel": "URL",
+ "allowHttp": "Autoriser http:// (endpoints intranet uniquement)",
+ "eventsLabel": "Événements",
+ "enabled": "Activé",
+ "saveButton": "Enregistrer le webhook",
+ "secretBannerTitle": "Copiez ce secret maintenant — il ne sera plus affiché",
+ "secretBannerHint": "Signez chaque requête du récepteur : HMAC-SHA256 du corps brut avec ce secret. En-tête : Speakr-Signature: sha256=<hex>",
+ "copy": "Copier"
}
}
diff --git a/static/locales/pt-BR.json b/static/locales/pt-BR.json
index db70c6ea..2845d590 100644
--- a/static/locales/pt-BR.json
+++ b/static/locales/pt-BR.json
@@ -118,7 +118,8 @@
"tagManagement": "Gerenciamento de Etiquetas",
"templates": "Modelos",
"transcriptTemplates": "Modelos de Transcrição",
- "preferences": "Preferências"
+ "preferences": "Preferências",
+ "webhooks": "Webhooks"
},
"admin": {
"title": "Admin",
@@ -1589,5 +1590,22 @@
"recordingMaxDurationReached": "A gravação atingiu a duração máxima e foi parada automaticamente.",
"recordingFinalized": "Gravação enviada para processamento",
"recordingResumeFound": "Uma gravação em andamento deste navegador foi detectada no servidor. Retomar?"
+ },
+ "webhooks": {
+ "title": "Webhooks",
+ "subtitle": "Receba notificações HTTP quando gravações mudarem. Cada endpoint é assinado com HMAC-SHA256 para que receptores possam verificar a autenticidade.",
+ "addNew": "Adicionar webhook",
+ "loading": "Carregando...",
+ "modalTitleNew": "Novo webhook",
+ "modalTitleEdit": "Editar webhook",
+ "nameLabel": "Nome",
+ "urlLabel": "URL",
+ "allowHttp": "Permitir http:// (somente endpoints de intranet)",
+ "eventsLabel": "Eventos",
+ "enabled": "Ativado",
+ "saveButton": "Salvar webhook",
+ "secretBannerTitle": "Copie este segredo agora — não será mostrado de novo",
+ "secretBannerHint": "Assine cada requisição do receptor: HMAC-SHA256 do corpo bruto usando este segredo. Cabeçalho: Speakr-Signature: sha256=<hex>",
+ "copy": "Copiar"
}
}
diff --git a/static/locales/ru.json b/static/locales/ru.json
index 2973e3b7..ecc30cca 100644
--- a/static/locales/ru.json
+++ b/static/locales/ru.json
@@ -118,7 +118,8 @@
"tagManagement": "Управление тегами",
"templates": "Шаблоны",
"transcriptTemplates": "Шаблоны транскриптов",
- "preferences": "Настройки"
+ "preferences": "Настройки",
+ "webhooks": "Вебхуки"
},
"admin": {
"title": "Администратор",
@@ -1589,5 +1590,22 @@
"recordingMaxDurationReached": "Запись достигла максимальной длительности и была остановлена автоматически.",
"recordingFinalized": "Запись отправлена на обработку",
"recordingResumeFound": "На сервере обнаружена незавершённая запись из этого браузера. Возобновить?"
+ },
+ "webhooks": {
+ "title": "Вебхуки",
+ "subtitle": "Получайте HTTP-уведомления при изменении записей. Каждая конечная точка подписывается HMAC-SHA256, чтобы получатели могли проверить подлинность.",
+ "addNew": "Добавить вебхук",
+ "loading": "Загрузка...",
+ "modalTitleNew": "Новый вебхук",
+ "modalTitleEdit": "Редактировать вебхук",
+ "nameLabel": "Имя",
+ "urlLabel": "URL",
+ "allowHttp": "Разрешить http:// (только для интранет-конечных точек)",
+ "eventsLabel": "События",
+ "enabled": "Включено",
+ "saveButton": "Сохранить вебхук",
+ "secretBannerTitle": "Скопируйте этот секрет сейчас — он больше не будет показан",
+ "secretBannerHint": "Подписывайте каждый запрос получателя: HMAC-SHA256 от исходного тела с этим секретом. Заголовок: Speakr-Signature: sha256=<hex>",
+ "copy": "Копировать"
}
}
diff --git a/static/locales/zh.json b/static/locales/zh.json
index 305bafb3..07348abf 100644
--- a/static/locales/zh.json
+++ b/static/locales/zh.json
@@ -118,7 +118,8 @@
"tagManagement": "标签管理",
"templates": "模板",
"transcriptTemplates": "转录模板",
- "preferences": "偏好设置"
+ "preferences": "偏好设置",
+ "webhooks": "Webhook"
},
"admin": {
"title": "管理员",
@@ -1589,5 +1590,22 @@
"recordingMaxDurationReached": "录音已达到最长时长,已自动停止。",
"recordingFinalized": "录音已上传等待处理",
"recordingResumeFound": "在服务器上检测到此浏览器的未完成录音。是否继续?"
+ },
+ "webhooks": {
+ "title": "Webhook",
+ "subtitle": "在录音发生变化时接收 HTTP 通知。每个端点使用 HMAC-SHA256 签名,接收方可以验证真实性。",
+ "addNew": "添加 Webhook",
+ "loading": "加载中...",
+ "modalTitleNew": "新建 Webhook",
+ "modalTitleEdit": "编辑 Webhook",
+ "nameLabel": "名称",
+ "urlLabel": "URL",
+ "allowHttp": "允许 http:// (仅限内网端点)",
+ "eventsLabel": "事件",
+ "enabled": "已启用",
+ "saveButton": "保存 Webhook",
+ "secretBannerTitle": "立即复制此密钥 — 不会再次显示",
+ "secretBannerHint": "用此密钥对每个接收方请求进行签名: 原始正文的 HMAC-SHA256。请求头: Speakr-Signature: sha256=<hex>",
+ "copy": "复制"
}
}
diff --git a/templates/account.html b/templates/account.html
index 9db86475..315687ad 100644
--- a/templates/account.html
+++ b/templates/account.html
@@ -475,6 +475,9 @@
<a href="#" id="tab-tokens" class="inline-flex items-center whitespace-nowrap py-1 px-1.5 sm:py-3 sm:px-3 border-b-2 font-medium text-xs sm:text-sm border-transparent text-[var(--text-muted)] hover:text-[var(--text-secondary)] hover:border-[var(--border-secondary)] rounded-t-md sm:rounded-t-lg hover:bg-[var(--bg-tertiary)]">
<i class="fas fa-key mr-0.5 sm:mr-2 text-xs sm:text-sm"></i><span data-i18n="accountTabs.apiTokens">API Tokens</span>
</a>
+ <a href="#" id="tab-webhooks" class="inline-flex items-center whitespace-nowrap py-1 px-1.5 sm:py-3 sm:px-3 border-b-2 font-medium text-xs sm:text-sm border-transparent text-[var(--text-muted)] hover:text-[var(--text-secondary)] hover:border-[var(--border-secondary)] rounded-t-md sm:rounded-t-lg hover:bg-[var(--bg-tertiary)]">
+ <i class="fas fa-link mr-0.5 sm:mr-2 text-xs sm:text-sm"></i><span data-i18n="accountTabs.webhooks">Webhooks</span>
+ </a>
<a href="#" id="tab-about" class="inline-flex items-center whitespace-nowrap py-1 px-1.5 sm:py-3 sm:px-3 border-b-2 font-medium text-xs sm:text-sm border-transparent text-[var(--text-muted)] hover:text-[var(--text-secondary)] hover:border-[var(--border-secondary)] rounded-t-md sm:rounded-t-lg hover:bg-[var(--bg-tertiary)]">
<i class="fas fa-info-circle mr-0.5 sm:mr-2 text-xs sm:text-sm"></i><span data-i18n="accountTabs.about">About</span>
</a>
@@ -1588,6 +1591,78 @@ curl "https://your-speakr-instance.com/api/recordings?token=YOUR_TOKEN_HERE"</co
</div>
</div>
+ <!-- Webhooks Tab Content -->
+ <div id="content-webhooks" class="hidden tab-content pt-6">
+ <div class="space-y-6">
+ <div class="flex items-center justify-between flex-wrap gap-3">
+ <div>
+ <h2 class="text-2xl font-semibold text-[var(--text-primary)]" data-i18n="webhooks.title">Webhooks</h2>
+ <p class="text-sm text-[var(--text-muted)] mt-1" data-i18n="webhooks.subtitle">Receive HTTP notifications when recordings change. Each endpoint is signed with HMAC-SHA256 so receivers can verify authenticity.</p>
+ </div>
+ <button id="webhook-create-btn" class="inline-flex items-center gap-2 px-3 py-2 bg-[var(--bg-button)] text-[var(--text-button)] rounded-md hover:bg-[var(--bg-button-hover)] text-sm">
+ <i class="fas fa-plus"></i><span data-i18n="webhooks.addNew">Add webhook</span>
+ </button>
+ </div>
+
+ <div id="webhook-list" class="space-y-3">
+ <p class="text-sm text-[var(--text-muted)]" data-i18n="webhooks.loading">Loading...</p>
+ </div>
+
+ <!-- Add/edit modal -->
+ <div id="webhook-modal" class="hidden fixed inset-0 z-50 flex items-center justify-center bg-black/60 p-4">
+ <div class="bg-[var(--bg-primary)] border border-[var(--border-primary)] rounded-lg max-w-xl w-full max-h-[90vh] overflow-y-auto">
+ <div class="flex items-center justify-between p-4 border-b border-[var(--border-primary)]">
+ <h3 id="webhook-modal-title" class="text-lg font-medium text-[var(--text-primary)]" data-i18n="webhooks.modalTitleNew">New webhook</h3>
+ <button id="webhook-modal-close" class="text-[var(--text-muted)] hover:text-[var(--text-primary)]" aria-label="Close"><i class="fas fa-times"></i></button>
+ </div>
+ <form id="webhook-form" class="p-4 space-y-4">
+ <input type="hidden" id="webhook-id-input" value="">
+ <div>
+ <label class="block text-sm font-medium text-[var(--text-muted)]" data-i18n="webhooks.nameLabel">Name</label>
+ <input id="webhook-name-input" type="text" required maxlength="100" placeholder="n8n production" class="mt-1 block w-full px-3 py-2 border border-[var(--border-secondary)] rounded-md bg-[var(--bg-input)] text-[var(--text-primary)] focus:outline-none focus:ring-[var(--border-focus)] focus:border-[var(--border-focus)] sm:text-sm">
+ </div>
+ <div>
+ <label class="block text-sm font-medium text-[var(--text-muted)]" data-i18n="webhooks.urlLabel">URL</label>
+ <input id="webhook-url-input" type="url" required maxlength="500" placeholder="https://n8n.example.com/webhook/..." class="mt-1 block w-full px-3 py-2 border border-[var(--border-secondary)] rounded-md bg-[var(--bg-input)] text-[var(--text-primary)] focus:outline-none focus:ring-[var(--border-focus)] focus:border-[var(--border-focus)] sm:text-sm">
+ <label class="mt-2 flex items-center gap-2 text-xs text-[var(--text-muted)]">
+ <input id="webhook-allow-http-input" type="checkbox" class="rounded border-[var(--border-secondary)]">
+ <span data-i18n="webhooks.allowHttp">Allow http:// (intranet endpoints only)</span>
+ </label>
+ </div>
+ <div>
+ <span class="block text-sm font-medium text-[var(--text-muted)]" data-i18n="webhooks.eventsLabel">Events</span>
+ <div id="webhook-events-checkboxes" class="mt-2 grid grid-cols-1 sm:grid-cols-2 gap-2"></div>
+ </div>
+ <label class="flex items-center gap-2 text-sm">
+ <input id="webhook-enabled-input" type="checkbox" checked class="rounded border-[var(--border-secondary)]">
+ <span data-i18n="webhooks.enabled">Enabled</span>
+ </label>
+ <div class="flex items-center justify-end gap-2 pt-2 border-t border-[var(--border-primary)]">
+ <button type="button" id="webhook-modal-cancel" class="px-3 py-2 text-sm text-[var(--text-muted)] hover:text-[var(--text-primary)]" data-i18n="buttons.cancel">Cancel</button>
+ <button type="submit" class="px-3 py-2 bg-[var(--bg-button)] text-[var(--text-button)] rounded-md hover:bg-[var(--bg-button-hover)] text-sm" data-i18n="webhooks.saveButton">Save webhook</button>
+ </div>
+ </form>
+ </div>
+ </div>
+
+ <!-- One-time secret display -->
+ <div id="webhook-secret-banner" class="hidden p-4 bg-[var(--bg-success-light)] border border-[var(--border-success)] rounded-lg">
+ <div class="flex items-start gap-3">
+ <i class="fas fa-key text-[var(--text-success-strong)] mt-1"></i>
+ <div class="flex-1 min-w-0">
+ <p class="text-sm font-medium text-[var(--text-success-strong)]" data-i18n="webhooks.secretBannerTitle">Copy this secret now — it will not be shown again</p>
+ <p class="text-xs text-[var(--text-muted)] mt-1" data-i18n="webhooks.secretBannerHint">Sign every receiver request: HMAC-SHA256 of the raw body using this secret. Header: Speakr-Signature: sha256=&lt;hex&gt;</p>
+ <div class="mt-2 flex items-center gap-2">
+ <code id="webhook-secret-value" class="flex-1 px-2 py-1 bg-[var(--bg-tertiary)] text-[var(--text-primary)] rounded text-xs font-mono break-all"></code>
+ <button id="webhook-secret-copy" class="px-3 py-1 text-xs bg-[var(--bg-button)] text-[var(--text-button)] rounded hover:bg-[var(--bg-button-hover)]" data-i18n="webhooks.copy">Copy</button>
+ <button id="webhook-secret-dismiss" class="px-3 py-1 text-xs text-[var(--text-muted)] hover:text-[var(--text-primary)]" data-i18n="buttons.close">Close</button>
+ </div>
+ </div>
+ </div>
+ </div>
+ </div>
+ </div>
+
<div id="content-about" class="hidden tab-content pt-6">
<div class="space-y-8">
<!-- Header Section -->
@@ -3029,6 +3104,7 @@ curl "https://your-speakr-instance.com/api/recordings?token=YOUR_TOKEN_HERE"</co
const tabTags = document.getElementById('tab-tags');
const tabTemplates = document.getElementById('tab-templates');
const tabTokens = document.getElementById('tab-tokens');
+ const tabWebhooks = document.getElementById('tab-webhooks');
const tabAbout = document.getElementById('tab-about');
const tabPreferences = document.getElementById('tab-preferences');
const contentAccount = document.getElementById('content-account');
@@ -3040,6 +3116,7 @@ curl "https://your-speakr-instance.com/api/recordings?token=YOUR_TOKEN_HERE"</co
const contentTags = document.getElementById('content-tags');
const contentTemplates = document.getElementById('content-templates');
const contentTokens = document.getElementById('content-tokens');
+ const contentWebhooks = document.getElementById('content-webhooks');
const contentAbout = document.getElementById('content-about');
const sharesContainer = document.getElementById('shares-container');
@@ -3057,6 +3134,7 @@ curl "https://your-speakr-instance.com/api/recordings?token=YOUR_TOKEN_HERE"</co
{ tab: tabTags, content: contentTags, name: 'tags' },
{ tab: tabTemplates, content: contentTemplates, name: 'templates' },
{ tab: tabTokens, content: contentTokens, name: 'tokens' },
+ { tab: tabWebhooks, content: contentWebhooks, name: 'webhooks' },
{ tab: tabAbout, content: contentAbout, name: 'about' }
];
@@ -3088,6 +3166,8 @@ curl "https://your-speakr-instance.com/api/recordings?token=YOUR_TOKEN_HERE"</co
loadTemplates();
} else if (targetName === 'tokens') {
loadTokensTab();
+ } else if (targetName === 'webhooks') {
+ loadWebhooks();
} else if (targetName === 'about') {
loadSystemInfo();
}
@@ -3182,6 +3262,13 @@ curl "https://your-speakr-instance.com/api/recordings?token=YOUR_TOKEN_HERE"</co
showTokensTab();
});
+ if (tabWebhooks) {
+ tabWebhooks.addEventListener('click', (e) => {
+ e.preventDefault();
+ switchToTab('webhooks');
+ });
+ }
+
tabAbout.addEventListener('click', (e) => {
e.preventDefault();
showAboutTab();
@@ -7508,5 +7595,8 @@ curl "https://your-speakr-instance.com/api/recordings?token=YOUR_TOKEN_HERE"</co
});
</script>
+ <!-- Webhooks tab logic (#275) -->
+ <script src="{{ url_for('static', filename='js/account-webhooks.js') }}"></script>
+
</body>
</html>