import { WiilClient } from 'wiil-js';
import { AppointmentStatus, PreferredContactMethod } from 'wiil-core-js';
async function setupSalonBooking() {
const client = new WiilClient({ apiKey: process.env.WIIL_API_KEY! });
const customer = await client.customers.create({
phone_number: '+15551234567',
firstname: 'Jane',
lastname: 'Doe',
preferred_language: 'en',
preferred_contact_method: PreferredContactMethod.EMAIL,
isValidatedNames: false,
});
const category = await client.serviceCategories.create({
organizationId: 'org_salon',
name: 'Hair Services',
description: 'All hair-related services',
displayOrder: 1,
isActive: true,
});
const haircut = await client.businessServices.create({
organizationId: 'org_salon',
name: 'Haircut & Style',
description: 'Professional haircut with styling',
duration: 60,
bufferBefore: 0,
bufferAfter: 0,
basePrice: 50.00,
isBookable: true,
isActive: true,
requiredResources: [],
lateCancelFeePercent: 50,
noShowFeePercent: 100,
});
const stylist = await client.servicePersons.create({
name: 'Sarah Johnson',
description: 'Senior stylist',
isActive: true,
bookableOnline: true,
bookableByStaff: true,
});
await client.serviceProviders.create({
serviceId: haircut.id,
providerId: stylist.id,
active: true,
});
const tomorrow = new Date();
tomorrow.setDate(tomorrow.getDate() + 1);
const localDate = tomorrow.toISOString().split('T')[0];
const slotResponse = await client.serviceAppointments.getAvailableSlots({
serviceId: haircut.id,
localDate: localDate,
providerId: stylist.id,
maxResults: 10,
});
if (slotResponse.slots.length === 0) {
console.log('No available slots found');
return;
}
const slot = slotResponse.slots[0];
const duration = Math.round((slot.endTimeUtcSec - slot.startTimeUtcSec) / 60);
const appointment = await client.serviceAppointments.create({
businessServiceId: haircut.id,
customerId: customer.id,
startTime: slot.startTimeUtcSec,
endTime: slot.endTimeUtcSec,
duration: duration,
totalPrice: 50.00,
depositPaid: 0,
});
const confirmed = await client.serviceAppointments.updateStatus(
appointment.id,
AppointmentStatus.CONFIRMED
);
console.log(`Appointment Status: ${confirmed.status}`);
return { customer, category, service: haircut, stylist, appointment: confirmed };
}
setupSalonBooking().catch(console.error);