diff --git a/CHANGELOG.md b/CHANGELOG.md index 1149229b..4a778222 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -49,6 +49,15 @@ exact tag (`ghcr.io/calnode/calnode:0.1.0`) if you need stability between upgrad and an informal one would be wrong for everyone else. `de` is unchanged and stays formal. The variant is never offered in the language switcher or matched from `Accept-Language`; select it with `?lang=de-x-neutral` or ``. +- **Phone-number intake questions.** A new question type, Phone number, renders a `tel` + input on the booking page and the widget, and stores the answer in international format + (E.164, `+48600100200`) with what the attendee typed kept alongside (`raw_value` on + `GET /v1/bookings/{id}/answers`). Each question can set a default country code, applied + only to numbers typed without one: `600 100 200` becomes `+48600100200`, while + `+44 20 7946 0958` keeps its own country. A number that can't be normalised is refused + with a message naming the question, never stored as typed. Migration `00078` rebuilds + `event_type_questions` to accept the new type (existing questions and answers are kept) + and adds the two columns. ### Fixed diff --git a/docs/ARCHITECTURE.md b/docs/ARCHITECTURE.md index 599c7672..a34a1e39 100644 --- a/docs/ARCHITECTURE.md +++ b/docs/ARCHITECTURE.md @@ -411,6 +411,8 @@ New public and assistant bookings recheck selected external calendars before com Google Meet and Teams event types can opt into `allow_phone_call`. Their booking page and widget then accept an optional `phone` value. A valid number selects a telephone appointment; leaving it empty preserves video. The booking stores its own location type so management pages, calendar retries, and paid confirmation do not generate a video link for a telephone appointment. Event duplication preserves the setting. +Intake questions of type **`phone`** (migration 00078, #260) collect a number that is safe to hand on as is (SMS gateway, CRM, dialler). `validateAnswersCore` stores it in **E.164** (`+48600100200`) via `normalizePhoneAnswer`, keeping what the attendee typed in `booking_answers.raw_value` when it differs (exposed as `raw_value` on `GET /v1/bookings/{id}/answers`). The rules: the input must pass the same lenient `validPhone` as the phone location; an explicit `+` or `00` prefix wins, so `+44` is never rewritten to the default (a `(0)` after it, `+44 (0)20` or `0044 (0)20`, is dropped); otherwise the question's `default_country_code` is prepended after dropping a national trunk `0` (kept for the Italian numbering plan, `+39`/`+378`/`+379`); extensions are refused (no E.164 form); the result must be 8-15 digits. A number that can't be normalised, or a national one on a question without a default code, is **refused** rather than stored as typed: with `err_phone_country_code` when the country code is what's missing (a national number, no default), otherwise `err_invalid_phone`. This is a shape check, not a numbering-plan validator. Because it runs in `validateAnswersCore`, the booking page, the widget, MCP and the assistant all get the same result. Webhooks and the answers endpoint carry the E.164 value; there is deliberately no special top-level `attendee_phone`. Both surfaces with a form render a `tel` input (`book.html`, `embed.js`); the manage page has no intake form. + The `phone_outbound` location type ("we'll call you") is the outbound counterpart: the host calls the attendee. The event type carries no number (`validateLocation` requires none); the booking page and widget show a required `phone` field instead, and `CreateBooking` refuses a missing or invalid number with HTTP 400 rather than falling back to another meeting type. A valid number is stored exactly like the `allow_phone_call` path (`bookings.location_type = "phone"`, `location_value = "tel:"`), so calendar events, emails, webhooks and the manage page treat it as an ordinary telephone appointment. The manage page needs no field of its own: a reschedule keeps the booking's stored number. The shared booking core (`createBookingForSlug`) refuses these event types, because the assistant and MCP cannot collect the number, and the booking page and widget hide the assistant for them. `internal/booking/service.go` (transactions) + `internal/handler/booking_handler.go` diff --git a/frontend/src/lib/api.ts b/frontend/src/lib/api.ts index cd6c8723..71baa197 100644 --- a/frontend/src/lib/api.ts +++ b/frontend/src/lib/api.ts @@ -97,10 +97,13 @@ export type Question = { id: string; event_type_id: string; label: string; - type: 'text' | 'select' | 'checkbox'; + type: 'text' | 'select' | 'checkbox' | 'phone'; options?: string[]; required: boolean; position: number; + /** Phone questions: prepended to a number typed without an international prefix + * ("+48"). The answer is stored in E.164. */ + default_country_code?: string; }; export type Booking = { diff --git a/frontend/src/lib/components/event-types/QuestionsPanel.svelte b/frontend/src/lib/components/event-types/QuestionsPanel.svelte index 8036ff9b..cb9d9280 100644 --- a/frontend/src/lib/components/event-types/QuestionsPanel.svelte +++ b/frontend/src/lib/components/event-types/QuestionsPanel.svelte @@ -18,18 +18,19 @@ { value: 'text', label: $t('eventTypeEditor.questions.types.text') }, { value: 'checkbox', label: $t('eventTypeEditor.questions.types.checkbox') }, { value: 'select', label: $t('eventTypeEditor.questions.types.select') }, + { value: 'phone', label: $t('eventTypeEditor.questions.types.phone') }, ]); let questions: Question[] = $state([]); let qLoading = $state(true); - let qForm = $state({ label: '', type: 'text' as 'text'|'select'|'checkbox', options: '', required: false }); + let qForm = $state({ label: '', type: 'text' as 'text'|'select'|'checkbox'|'phone', options: '', required: false, country: '' }); let qAdding = $state(false); let editingQId = $state(null); let deleteQOpen = $state(false); let pendingQ = $state(null); - let editQForm = $state({ label: '', type: 'text' as 'text'|'select'|'checkbox', options: '', required: false }); + let editQForm = $state({ label: '', type: 'text' as 'text'|'select'|'checkbox'|'phone', options: '', required: false, country: '' }); let qSaving = $state(false); async function loadQuestions() { @@ -67,8 +68,9 @@ type: qForm.type, options: qForm.type === 'select' ? optionsArray(qForm.options) : undefined, required: qForm.required, + default_country_code: qForm.type === 'phone' ? qForm.country.trim() : undefined, }); - qForm = { label: '', type: 'text', options: '', required: false }; + qForm = { label: '', type: 'text', options: '', required: false, country: '' }; await loadQuestions(); } catch (e: any) { toast.error(e.message || tr('eventTypeEditor.questions.error.add')); @@ -79,7 +81,7 @@ function startEditQ(q: Question) { editingQId = q.id; - editQForm = { label: q.label, type: q.type, options: (q.options ?? []).join('\n'), required: q.required }; + editQForm = { label: q.label, type: q.type, options: (q.options ?? []).join('\n'), required: q.required, country: q.default_country_code ?? '' }; } function cancelEditQ() { editingQId = null; } @@ -96,6 +98,8 @@ type: editQForm.type, options: editQForm.type === 'select' ? optionsArray(editQForm.options) : [], required: editQForm.required, + // '' clears it; the server ignores it for any type but phone. + default_country_code: editQForm.type === 'phone' ? editQForm.country.trim() : '', }); editingQId = null; await loadQuestions(); @@ -167,7 +171,7 @@
- { if (v) editQForm.type = v as 'text'|'select'|'checkbox'; }}> + { if (v) editQForm.type = v as 'text'|'select'|'checkbox'|'phone'; }}> {QUESTION_TYPES.find((t) => t.value === editQForm.type)?.label ?? $t('common.select')} @@ -183,6 +187,12 @@ diff --git a/internal/i18n/locales/de-x-neutral.json b/internal/i18n/locales/de-x-neutral.json index 42941bee..2254785d 100644 --- a/internal/i18n/locales/de-x-neutral.json +++ b/internal/i18n/locales/de-x-neutral.json @@ -149,6 +149,8 @@ "err_booking_limit": "Die maximale Anzahl anstehender Buchungen für diesen Termin ist bereits erreicht. Bitte eine bestehende Buchung stornieren oder warten, bis eine vorüber ist.", "err_email_throttled": "Zu viele Buchungen von dieser E-Mail-Adresse in letzter Zeit. Bitte später erneut versuchen.", "err_required_field": "Pflichtfeld %q fehlt", + "err_invalid_phone": "ungültige Telefonnummer für %q: Nummer prüfen und ohne Durchwahl eingeben", + "err_phone_country_code": "ungültige Telefonnummer für %q: mit Ländervorwahl eingeben, z. B. +49 30 1234567", "err_required_checkbox": "%q muss angekreuzt werden", "err_invalid_option": "ungültige Option für %[1]q: %[2]q ist keine zulässige Auswahl", "assistant_unavailable": "Der Buchungsassistent ist derzeit nicht verfügbar. Bitte einen Termin im Kalender unten wählen.", diff --git a/internal/i18n/locales/de.json b/internal/i18n/locales/de.json index c41e28dd..cae6b930 100644 --- a/internal/i18n/locales/de.json +++ b/internal/i18n/locales/de.json @@ -149,6 +149,8 @@ "err_booking_limit": "Sie haben bereits die maximale Anzahl anstehender Buchungen für diesen Termin erreicht. Bitte stornieren Sie eine bestehende Buchung oder warten Sie, bis eine vorüber ist.", "err_email_throttled": "Zu viele Buchungen von dieser E-Mail-Adresse in letzter Zeit. Bitte versuchen Sie es später erneut.", "err_required_field": "Pflichtfeld %q fehlt", + "err_invalid_phone": "ungültige Telefonnummer für %q: bitte die Nummer prüfen und ohne Durchwahl eingeben", + "err_phone_country_code": "ungültige Telefonnummer für %q: bitte mit Ländervorwahl eingeben, z. B. +49 30 1234567", "err_required_checkbox": "%q muss angekreuzt werden", "err_invalid_option": "ungültige Option für %[1]q: %[2]q ist keine zulässige Auswahl", "assistant_unavailable": "Der Buchungsassistent ist derzeit nicht verfügbar. Bitte wählen Sie einen Termin im Kalender unten.", diff --git a/internal/i18n/locales/el.json b/internal/i18n/locales/el.json index e81cfc1f..0161a001 100644 --- a/internal/i18n/locales/el.json +++ b/internal/i18n/locales/el.json @@ -155,6 +155,8 @@ "err_booking_limit": "Έχετε τον μέγιστο επιτρεπτό αριθμό επερχόμενων κρατήσεων για αυτόν τον τύπο ραντεβού. Παρακαλούμε ακυρώστε μια υπάρχουσα κράτηση ή περιμένετε μέχρι κάποια να περάσει πριν ξανακάνετε κράτηση.", "err_email_throttled": "Έχουν γίνει υπερβολικά πολλές κρατήσεις για αυτή τη διεύθυνση email πρόσφατα. Παρακαλούμε δοκιμάστε ξανά.", "err_required_field": "Το υποχρεωτικό πεδίο %q δεν έχει συμπληρωθεί", + "err_invalid_phone": "μη έγκυρος αριθμός τηλεφώνου για το %q: ελέγξτε τον αριθμό και παραλείψτε τυχόν εσωτερικό", + "err_phone_country_code": "μη έγκυρος αριθμός τηλεφώνου για το %q: εισαγάγετέ τον με τον κωδικό χώρας, π.χ. +30 210 1234567", "err_required_checkbox": "%q πρέπει να έχει επιλεγεί", "err_invalid_option": "μη έγκυρη επιλογή για %[1]q: Το %[2]q δεν είναι έγκυρη επιλογή", diff --git a/internal/i18n/locales/en.json b/internal/i18n/locales/en.json index b268bdec..878d96bb 100644 --- a/internal/i18n/locales/en.json +++ b/internal/i18n/locales/en.json @@ -156,6 +156,8 @@ "err_booking_limit": "You already have the maximum number of upcoming bookings for this event. Please cancel an existing booking or wait until one has passed before booking again.", "err_email_throttled": "Too many bookings from this email address recently. Please try again later.", "err_required_field": "required field %q is missing", + "err_invalid_phone": "invalid phone number for %q: check the number and leave out any extension", + "err_phone_country_code": "invalid phone number for %q: enter it with the country code, e.g. +44 20 7946 0958", "err_required_checkbox": "%q must be checked", "err_invalid_option": "invalid option for %[1]q: %[2]q is not an allowed choice", diff --git a/internal/i18n/locales/es.json b/internal/i18n/locales/es.json index 896b898f..f1b356c1 100644 --- a/internal/i18n/locales/es.json +++ b/internal/i18n/locales/es.json @@ -155,6 +155,8 @@ "err_booking_limit": "Ya tienes el número máximo de reservas próximas para este evento. Cancela una reserva existente o espera a que pase alguna antes de volver a reservar.", "err_email_throttled": "Demasiadas reservas desde esta dirección de correo recientemente. Inténtalo de nuevo más tarde.", "err_required_field": "falta el campo obligatorio %q", + "err_invalid_phone": "número de teléfono no válido en %q: revisa el número y omite la extensión", + "err_phone_country_code": "número de teléfono no válido en %q: introdúcelo con el prefijo del país, p. ej. +34 600 100 200", "err_required_checkbox": "Debes marcar %q", "err_invalid_option": "opción no válida para %[1]q: %[2]q no es una opción permitida", diff --git a/internal/i18n/locales/fr-CA.json b/internal/i18n/locales/fr-CA.json index 41143791..937d1293 100644 --- a/internal/i18n/locales/fr-CA.json +++ b/internal/i18n/locales/fr-CA.json @@ -149,6 +149,8 @@ "err_booking_limit": "Vous avez déjà atteint le nombre maximum de réservations à venir pour cet événement. Annulez une réservation existante ou attendez qu'elle soit passée avant d'en créer une nouvelle.", "err_email_throttled": "Trop de réservations récentes depuis cette adresse courriel. Veuillez réessayer plus tard.", "err_required_field": "le champ obligatoire %q est manquant", + "err_invalid_phone": "numéro de téléphone non valide pour %q : vérifiez le numéro et omettez le poste", + "err_phone_country_code": "numéro de téléphone non valide pour %q : entrez-le avec l'indicatif du pays, p. ex. +1 514 555 0123", "err_required_checkbox": "%q doit être coché", "err_invalid_option": "option non valide pour %[1]q : %[2]q n'est pas un choix autorisé", "assistant_unavailable": "L'assistant de réservation n'est pas disponible pour le moment. Choisissez un créneau dans le calendrier ci-dessous.", diff --git a/internal/i18n/locales/fr.json b/internal/i18n/locales/fr.json index 7d79319d..9daeec94 100644 --- a/internal/i18n/locales/fr.json +++ b/internal/i18n/locales/fr.json @@ -149,6 +149,8 @@ "err_booking_limit": "Vous avez déjà atteint le nombre maximum de réservations à venir pour cet événement. Annulez une réservation existante ou attendez qu'elle soit passée avant d'en créer une nouvelle.", "err_email_throttled": "Trop de réservations récentes depuis cette adresse e-mail. Veuillez réessayer plus tard.", "err_required_field": "le champ obligatoire %q est manquant", + "err_invalid_phone": "numéro de téléphone non valide pour %q : vérifiez le numéro et omettez le poste", + "err_phone_country_code": "numéro de téléphone non valide pour %q : saisissez-le avec l'indicatif du pays, p. ex. +33 6 12 34 56 78", "err_required_checkbox": "%q doit être coché", "err_invalid_option": "option non valide pour %[1]q : %[2]q n'est pas un choix autorisé", "assistant_unavailable": "L'assistant de réservation n'est pas disponible pour le moment. Choisissez un créneau dans le calendrier ci-dessous.", diff --git a/internal/i18n/locales/it.json b/internal/i18n/locales/it.json index afeddd0c..aa35a7c7 100644 --- a/internal/i18n/locales/it.json +++ b/internal/i18n/locales/it.json @@ -149,6 +149,8 @@ "err_booking_limit": "Hai già raggiunto il numero massimo di prenotazioni future per questo evento. Annulla una prenotazione esistente o attendi che sia passata prima di crearne un'altra.", "err_email_throttled": "Troppe prenotazioni recenti da questo indirizzo email. Riprova più tardi.", "err_required_field": "manca il campo obbligatorio %q", + "err_invalid_phone": "numero di telefono non valido per %q: controlla il numero e ometti l'interno", + "err_phone_country_code": "numero di telefono non valido per %q: inseriscilo con il prefisso internazionale, ad es. +39 06 1234 5678", "err_required_checkbox": "%q deve essere selezionato", "err_invalid_option": "opzione non valida per %[1]q: %[2]q non è una scelta consentita", "assistant_unavailable": "L'assistente di prenotazione non è disponibile al momento. Scelga un orario dal calendario qui sotto.", diff --git a/internal/i18n/locales/nl.json b/internal/i18n/locales/nl.json index b3e730c3..57f34596 100644 --- a/internal/i18n/locales/nl.json +++ b/internal/i18n/locales/nl.json @@ -149,6 +149,8 @@ "err_booking_limit": "Je hebt al het maximale aantal komende boekingen voor dit evenement bereikt. Annuleer een bestaande boeking of wacht tot die voorbij is voordat je een nieuwe maakt.", "err_email_throttled": "Te veel recente boekingen vanaf dit e-mailadres. Probeer het later opnieuw.", "err_required_field": "verplicht veld %q ontbreekt", + "err_invalid_phone": "ongeldig telefoonnummer voor %q: controleer het nummer en laat een toestelnummer weg", + "err_phone_country_code": "ongeldig telefoonnummer voor %q: vul het in met de landcode, bijv. +31 20 123 4567", "err_required_checkbox": "%q moet aangevinkt zijn", "err_invalid_option": "ongeldige optie voor %[1]q: %[2]q is geen toegestane keuze", "assistant_unavailable": "De boekingsassistent is momenteel niet beschikbaar. Kies een tijd in de agenda hieronder.", diff --git a/internal/i18n/locales/pl.json b/internal/i18n/locales/pl.json index d7e95fcc..302f4ac0 100644 --- a/internal/i18n/locales/pl.json +++ b/internal/i18n/locales/pl.json @@ -150,6 +150,8 @@ "err_booking_limit": "Masz już maksymalną liczbę nadchodzących rezerwacji dla tego wydarzenia. Anuluj istniejącą rezerwację lub poczekaj na jej zakończenie przed kolejną rezerwacją.", "err_email_throttled": "Z tego adresu e-mail dokonywano ostatnio zbyt wielu rezerwacji. Spróbuj ponownie później.", "err_required_field": "wymagane pole %q nie zostało wypełnione", + "err_invalid_phone": "nieprawidłowy numer telefonu w polu %q: sprawdź numer i wpisz go bez numeru wewnętrznego", + "err_phone_country_code": "nieprawidłowy numer telefonu w polu %q: wpisz go z numerem kierunkowym kraju, np. +48 600 100 200", "err_required_checkbox": "pole %q musi zostać zaznaczone", "err_invalid_option": "nieprawidłowa opcja dla %[1]q: %[2]q nie jest dozwolonym wyborem", "assistant_unavailable": "Asystent rezerwacji jest w tej chwili niedostępny — wybierz termin z poniższego kalendarza.", diff --git a/internal/i18n/locales/pt.json b/internal/i18n/locales/pt.json index dc860ede..1870186c 100644 --- a/internal/i18n/locales/pt.json +++ b/internal/i18n/locales/pt.json @@ -149,6 +149,8 @@ "err_booking_limit": "Já atingiu o número máximo de marcações futuras para este evento. Cancele uma marcação existente ou aguarde que passe antes de criar outra.", "err_email_throttled": "Demasiadas marcações recentes a partir deste endereço de e-mail. Tente novamente mais tarde.", "err_required_field": "falta o campo obrigatório %q", + "err_invalid_phone": "número de telefone inválido em %q: verifique o número e omita a extensão", + "err_phone_country_code": "número de telefone inválido em %q: introduza-o com o indicativo do país, p. ex. +351 912 345 678", "err_required_checkbox": "%q tem de ser selecionado", "err_invalid_option": "opção inválida para %[1]q: %[2]q não é uma escolha permitida", "assistant_unavailable": "O assistente de marcações não está disponível de momento. Escolha um horário no calendário abaixo.", diff --git a/internal/i18n/locales/sv.json b/internal/i18n/locales/sv.json index c2927d67..4f27bcda 100644 --- a/internal/i18n/locales/sv.json +++ b/internal/i18n/locales/sv.json @@ -149,6 +149,8 @@ "err_booking_limit": "Du har redan nått det högsta antalet kommande bokningar för det här evenemanget. Avboka en befintlig bokning eller vänta tills den har passerat innan du gör en ny.", "err_email_throttled": "För många bokningar från den här e-postadressen på kort tid. Försök igen senare.", "err_required_field": "obligatoriskt fält %q saknas", + "err_invalid_phone": "ogiltigt telefonnummer för %q: kontrollera numret och utelämna eventuell anknytning", + "err_phone_country_code": "ogiltigt telefonnummer för %q: ange det med landsnummer, t.ex. +46 8 123 456 78", "err_required_checkbox": "%q måste vara ikryssat", "err_invalid_option": "ogiltigt alternativ för %[1]q: %[2]q är inte ett tillåtet val", "assistant_unavailable": "Bokningsassistenten är inte tillgänglig just nu. Välj en tid i kalendern nedan.",