Skip to navigation

Appointments

View as MarkdownOpen in Claude

Appointments is a task pack that finds open times and books, moves, and cancels the caller’s appointments against your calendar, which you supply as functions. Add it to an Operations or a ServiceAgent with add_to().

Each slot and appointment comes with a label, which is how it’s said (“Tuesday the 3rd at 2 pm”). The pack never reads or writes a date itself, so the time zone, the calendar, and the language stay yours. Only a slot the pack found open can be booked, and every booking, move, and cancellation is read back for the caller’s yes.

from signalwire.operations import Appointment, Appointments, Slot

Parameters

All parameters are keyword-only. Every function may be async.

openings
Callable[[CallContext, str, str | None], list[Slot]]Required

openings(call, when, kind) returns the Slots open near when, the caller’s words (“Tuesday afternoon”). kind is one of kinds, or None. May raise Refuse or Need.

book
Callable[[CallContext, Slot, str | None, str | None], Any]Required

book(call, slot, kind, note) books the slot once the caller says yes. Raise WriteFailed when the calendar refuses.

booked
Callable[[CallContext], list[Appointment]] | NoneDefaults to None

booked(call) returns the caller’s Appointments. Needed for move and cancel.

move
Callable[[CallContext, Appointment, Slot], Any] | NoneDefaults to None

move(call, appointment, slot) moves one. Raises ValueError without booked.

cancel
Callable[[CallContext, Appointment], Any] | NoneDefaults to None

cancel(call, appointment) cancels one. Raises ValueError without booked.

kinds
Sequence[str] | NoneDefaults to None

What an appointment can be for, as the caller would say it (“cleaning”). None gives no choice.

before_identity
boolDefaults to False

True to find openings and book before the caller is identified, for new customers. The caller’s own appointments always need an identified account.

wording
Mapping[str, str] | NoneDefaults to None

Replacements keyed like APPOINTMENTS_WORDING. See wording.

tools
Mapping[str, str] | NoneDefaults to None

New names for the generated tools, by key. An unknown key raises ValueError.

KeyDefault tool name
openingsfind_openings
bookedmy_appointments
bookbook_appointment
movemove_appointment
cancelcancel_appointment
state_key
strDefaults to appointments

Where in call.state the pack keeps the slots it found.

Properties

tools
Mapping[str, str]

The generated tools’ names, by key.

Methods

add_to(target) registers the pack’s lookups and operations on an Operations or a ServiceAgent, and returns target.

Slot and Appointment

Frozen dataclasses your calendar functions return and receive.

Slot.id
strRequired

The calendar’s id for an open time.

Slot.label
strRequired

How the time is said, in the calendar’s own time zone and words.

Appointment.id
strRequired

The calendar’s id for one of the caller’s appointments.

Appointment.label
strRequired

How the appointment is said: “your cleaning on Tuesday the 3rd at 2 pm”.

Example

from signalwire.operations import Appointments, ServiceAgent, Slot
OPEN = {"s1": "Tuesday at 2 pm", "s2": "Wednesday at 10 am"}
agent = ServiceAgent("dentist", role="You answer the phone for a dental practice.")
Appointments(
openings=lambda call, when, kind: [Slot(i, label) for i, label in OPEN.items()],
book=lambda call, slot, kind, note: OPEN.pop(slot.id),
kinds=["cleaning", "check-up"],
before_identity=True,
).add_to(agent)

FrontDeskAgent and PersonalAssistantAgent take an Appointments pack as appointments=.