Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 `<calnode-booking lang="de-x-neutral">`.
- **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

Expand Down
2 changes: 2 additions & 0 deletions docs/ARCHITECTURE.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:<number>"`), 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`
Expand Down
5 changes: 4 additions & 1 deletion frontend/src/lib/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down
30 changes: 24 additions & 6 deletions frontend/src/lib/components/event-types/QuestionsPanel.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -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<string | null>(null);
let deleteQOpen = $state(false);
let pendingQ = $state<Question | null>(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() {
Expand Down Expand Up @@ -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'));
Expand All @@ -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; }
Expand All @@ -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();
Expand Down Expand Up @@ -167,7 +171,7 @@
</div>
<div class="space-y-1.5">
<Label for="eq-type-{q.id}" class="text-xs text-muted-foreground">{$t('eventTypeEditor.questions.table.type')}</Label>
<Select.Root type="single" value={editQForm.type} onValueChange={(v) => { if (v) editQForm.type = v as 'text'|'select'|'checkbox'; }}>
<Select.Root type="single" value={editQForm.type} onValueChange={(v) => { if (v) editQForm.type = v as 'text'|'select'|'checkbox'|'phone'; }}>
<Select.Trigger id="eq-type-{q.id}" class="w-full">
{QUESTION_TYPES.find((t) => t.value === editQForm.type)?.label ?? $t('common.select')}
</Select.Trigger>
Expand All @@ -183,6 +187,12 @@
<Label for="eq-options-{q.id}" class="text-xs text-muted-foreground">{$t('eventTypeEditor.questions.options')}</Label>
<Textarea id="eq-options-{q.id}" bind:value={editQForm.options} rows={3} />
</div>
{:else if editQForm.type === 'phone'}
<div class="col-span-2 space-y-1.5">
<Label for="eq-country-{q.id}" class="text-xs text-muted-foreground">{$t('eventTypeEditor.questions.countryCode')}</Label>
<Input id="eq-country-{q.id}" bind:value={editQForm.country} placeholder="+48" class="w-28" />
<p class="text-xs text-muted-foreground">{$t('eventTypeEditor.questions.countryCodeHint')}</p>
</div>
{/if}
<div class="col-span-2 flex items-center gap-2">
<Checkbox id="eq-required-{q.id}" bind:checked={editQForm.required} />
Expand All @@ -206,6 +216,8 @@
<div class="font-medium">{q.label}</div>
{#if q.type === 'select' && q.options?.length}
<div class="mt-0.5 text-xs text-muted-foreground">{q.options.join(', ')}</div>
{:else if q.type === 'phone' && q.default_country_code}
<div class="mt-0.5 text-xs text-muted-foreground">{q.default_country_code}</div>
{/if}
</td>
<td class="px-4 py-3">
Expand Down Expand Up @@ -258,7 +270,7 @@
</div>
<div class="space-y-1.5">
<Label for="q-type">{$t('eventTypeEditor.questions.table.type')}</Label>
<Select.Root type="single" value={qForm.type} onValueChange={(v) => { if (v) qForm.type = v as 'text'|'select'|'checkbox'; }}>
<Select.Root type="single" value={qForm.type} onValueChange={(v) => { if (v) qForm.type = v as 'text'|'select'|'checkbox'|'phone'; }}>
<Select.Trigger id="q-type" class="w-full">
{QUESTION_TYPES.find((t) => t.value === qForm.type)?.label ?? $t('common.select')}
</Select.Trigger>
Expand All @@ -274,6 +286,12 @@
<Label for="q-options">{$t('eventTypeEditor.questions.options')}</Label>
<Textarea id="q-options" bind:value={qForm.options} rows={3} placeholder={$t('eventTypeEditor.questions.optionsPlaceholder')} />
</div>
{:else if qForm.type === 'phone'}
<div class="col-span-2 space-y-1.5">
<Label for="q-country">{$t('eventTypeEditor.questions.countryCode')}</Label>
<Input id="q-country" bind:value={qForm.country} placeholder="+48" class="w-28" />
<p class="text-xs text-muted-foreground">{$t('eventTypeEditor.questions.countryCodeHint')}</p>
</div>
{/if}
<div class="col-span-2 flex items-center gap-2">
<Checkbox id="q-required" bind:checked={qForm.required} />
Expand Down
5 changes: 4 additions & 1 deletion frontend/src/lib/i18n/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -1856,11 +1856,14 @@
"types": {
"text": "Text",
"checkbox": "Checkbox (yes/no)",
"select": "Dropdown"
"select": "Dropdown",
"phone": "Phone number"
},
"label": "Label",
"options": "Options (one per line)",
"optionsPlaceholder": "Option A\nOption B\nOption C",
"countryCode": "Default country code (optional)",
"countryCodeHint": "Added to numbers typed without one, e.g. 600 100 200 becomes +48600100200. A number starting with + or 00 keeps its own country. Without a default, attendees must include the country code. Answers are stored in international format (E.164).",
"labelPlaceholder": "e.g. What's the meeting about?",
"add": "Add question",
"adding": "Adding…",
Expand Down
5 changes: 4 additions & 1 deletion frontend/src/lib/i18n/fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -1856,11 +1856,14 @@
"types": {
"text": "Texte",
"checkbox": "Case à cocher (oui/non)",
"select": "Liste déroulante"
"select": "Liste déroulante",
"phone": "Numéro de téléphone"
},
"label": "Libellé",
"options": "Options (une par ligne)",
"optionsPlaceholder": "Option A\nOption B\nOption C",
"countryCode": "Indicatif pays par défaut (facultatif)",
"countryCodeHint": "Ajouté aux numéros saisis sans indicatif, p. ex. 06 12 34 56 78 devient +33612345678. Un numéro commençant par + ou 00 garde son propre pays. Sans valeur par défaut, les participants doivent saisir l'indicatif. Les réponses sont enregistrées au format international (E.164).",
"labelPlaceholder": "ex. Quel est l'objet de la réunion ?",
"add": "Ajouter une question",
"adding": "Ajout…",
Expand Down
3 changes: 3 additions & 0 deletions internal/booking/booking.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,9 @@ type Attendee struct {
type Answer struct {
QuestionID string
Value string
// RawValue is what the attendee typed when Value is a normalised form of it (a phone
// question's E.164 number, #260); empty otherwise, and stored as NULL.
RawValue string
}

// CreateParams is the input to Service.Create.
Expand Down
6 changes: 3 additions & 3 deletions internal/booking/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -203,9 +203,9 @@ func (s *Service) Create(ctx context.Context, p CreateParams) (*Booking, error)

for _, ans := range p.Answers {
_, err = tx.ExecContext(ctx, `
INSERT INTO booking_answers (id, booking_id, question_id, value)
VALUES (?, ?, ?, ?)`,
uid.New(), bookingID, ans.QuestionID, ans.Value)
INSERT INTO booking_answers (id, booking_id, question_id, value, raw_value)
VALUES (?, ?, ?, ?, NULLIF(?, ''))`,
uid.New(), bookingID, ans.QuestionID, ans.Value, ans.RawValue)
if err != nil {
return nil, fmt.Errorf("booking: insert answer: %w", err)
}
Expand Down
46 changes: 46 additions & 0 deletions internal/db/migrations/00078_phone_question_type.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
-- +goose NO TRANSACTION
-- A 'phone' intake-question type (discussion #260): a tel input whose answer is stored
-- normalised to E.164 (+48600100200), so it is safe to hand to an SMS gateway, a CRM or
-- a dialler, with the attendee's own input kept alongside in booking_answers.raw_value.
--
-- event_type_questions.default_country_code (e.g. '+48') is applied only to a number
-- written without an international prefix; one typed as +44... or 0044... keeps its own
-- country. NULL means no default: such a number must then carry its prefix, and a
-- national-format one is refused rather than stored unnormalised.
--
-- Widening the type CHECK is the 00042/00073 table rebuild: NO TRANSACTION +
-- foreign_keys=OFF, because booking_answers.question_id references this table with
-- ON DELETE CASCADE (00014), so a DROP TABLE with foreign keys enabled would delete every
-- intake answer, and PRAGMA foreign_keys is a no-op inside a transaction. The table has
-- had the same columns since 00001 and no indexes.

-- +goose Up
PRAGMA foreign_keys=OFF;

CREATE TABLE event_type_questions_new (
id TEXT PRIMARY KEY,
event_type_id TEXT NOT NULL REFERENCES event_types(id) ON DELETE CASCADE,
label TEXT NOT NULL,
type TEXT NOT NULL CHECK (type IN ('text', 'select', 'checkbox', 'phone')),
options TEXT, -- JSON array; used for type='select'
required INTEGER NOT NULL DEFAULT 0,
position INTEGER NOT NULL DEFAULT 0,
default_country_code TEXT -- '+48' etc.; type='phone' only
);
INSERT INTO event_type_questions_new (id, event_type_id, label, type, options, required, position)
SELECT id, event_type_id, label, type, options, required, position FROM event_type_questions;
DROP TABLE event_type_questions;
ALTER TABLE event_type_questions_new RENAME TO event_type_questions;

PRAGMA foreign_keys=ON;

-- What the attendee typed, for a phone answer whose value was normalised. NULL otherwise.
ALTER TABLE booking_answers ADD COLUMN raw_value TEXT;

-- +goose Down
-- The widened CHECK stays (as in 00042, 00071 and 00073). An older binary does not know
-- 'phone', so those questions become free-text ones; their stored answers are already
-- plain E.164 strings and read fine as text.
UPDATE event_type_questions SET type = 'text', default_country_code = NULL WHERE type = 'phone';
ALTER TABLE booking_answers DROP COLUMN raw_value;
ALTER TABLE event_type_questions DROP COLUMN default_country_code;
Loading
Loading