Implementation of an AI voice bot for scheduling appointments. The appointment bot autonomously answers incoming calls, confirms a convenient time, checks available slots, and confirms the appointment—without administrator intervention. Suitable for use in clinics, beauty salons, auto repair shops, and government agencies. ### Dialogue Scenario
Бот: Добрый день! Вы позвонили в клинику «Здоровье». Хотите записаться на приём?
Клиент: Да, к терапевту
Бот: К какому врачу вы хотите попасть — к Ивановой или к Петрову?
Клиент: Всё равно, кто ближе по времени
Бот: Ближайшее время — завтра в 14:30 у Петрова. Подходит?
Клиент: Да
Бот: Назовите вашу фамилию для записи
Клиент: Сидоров
Бот: Сидоров, запись подтверждена на завтра в 14:30 к врачу Петрову.
Напомним вам за 2 часа. Спасибо!
```### Implementation with Google Calendar / Calendly API```python
from google.oauth2.credentials import Credentials
from googleapiclient.discovery import build
from datetime import datetime, timedelta
def get_available_slots(
calendar_id: str,
specialist_id: str,
days_ahead: int = 7,
slot_duration_min: int = 30
) -> list[dict]:
"""Получаем свободные слоты из Google Calendar"""
service = build('calendar', 'v3', credentials=get_credentials())
now = datetime.utcnow()
end_time = now + timedelta(days=days_ahead)
# Запрашиваем занятые слоты
freebusy = service.freebusy().query(body={
"timeMin": now.isoformat() + "Z",
"timeMax": end_time.isoformat() + "Z",
"items": [{"id": calendar_id}]
}).execute()
busy_slots = freebusy["calendars"][calendar_id]["busy"]
return calculate_free_slots(busy_slots, now, end_time, slot_duration_min)
async def book_appointment(
calendar_id: str,
start_time: datetime,
client_name: str,
service_type: str
) -> str:
"""Создаём запись в календаре"""
service = build('calendar', 'v3', credentials=get_credentials())
event = {
"summary": f"{service_type} — {client_name}",
"start": {"dateTime": start_time.isoformat(), "timeZone": "Europe/Moscow"},
"end": {"dateTime": (start_time + timedelta(minutes=30)).isoformat(),
"timeZone": "Europe/Moscow"},
"reminders": {"useDefault": True}
}
created = service.events().insert(calendarId=calendar_id, body=event).execute()
return created["id"]
```### Handling time ambiguity```python
def parse_time_expression(text: str) -> datetime | None:
"""Парсим выражения типа 'завтра в 3', 'в пятницу утром'"""
import dateparser
return dateparser.parse(
text,
languages=["ru"],
settings={
"PREFER_DATES_FROM": "future",
"TIMEZONE": "Europe/Moscow"
}
)
```### SMS confirmation via SMS.ru```python
import requests
def send_appointment_sms(phone: str, appointment: dict):
text = (f"Запись подтверждена: {appointment['specialist']}, "
f"{appointment['date']} в {appointment['time']}. "
f"Отмена: {CALLBACK_NUMBER}")
requests.get("https://sms.ru/sms/send",
params={"api_id": SMS_API_KEY, "to": phone, "msg": text})
```Timeframe: A bot with a single entry type takes 2–3 weeks. A multi-specialist system with analytics takes 1–1.5 months.