Skip to content

Commit

Permalink
feat: cal booking
Browse files Browse the repository at this point in the history
  • Loading branch information
okradze committed Dec 13, 2023
1 parent ecbf59f commit 81832d9
Showing 1 changed file with 29 additions and 30 deletions.
59 changes: 29 additions & 30 deletions apps/server/tools/cal/cal_booking_tool.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class CalBookingSchema(BaseModel):
description=(
"Your task involves managing a JSON string representing an action query.\n"
"Generate a JSON output including:\n"
"Time format entries for 'start' and 'end' fields, where 'end' can be left empty (Use format: 'YYYY-MM-DDTHH:MM:SS.000Z').\n"
"Time format entries for 'start' field (Use format: 'YYYY-MM-DDTHH:MM:SS.000Z').\n"
"Optional fields such as 'name', 'email', 'location', 'timeZone', 'title', 'notes', 'description', and 'duration' (represented as '30min').\n"
"If 'timeZone' is unspecified, default it to 'America/New York'.\n"
"Format the time relative to the current time; if the specified time is in the past, automatically format provided time for tomorrow \n"
Expand All @@ -39,7 +39,7 @@ class CalBookingTool(BaseTool):
description = (
"Your task involves managing a JSON string representing an action query.\n"
"Generate a JSON output including:\n"
"Time format entries for 'start' and 'end' fields, where 'end' can be left empty (Use format: 'YYYY-MM-DDTHH:MM:SS.000Z').\n"
"Time format entries for 'start' field (Use format: 'YYYY-MM-DDTHH:MM:SS.000Z').\n"
"Optional fields such as 'name', 'email', 'location', 'timeZone', 'title', 'notes', 'description', and 'duration' (represented as '30min').\n"
"If 'timeZone' is unspecified, default it to 'America/New York'.\n"
"Format the time relative to the current time; if the specified time is in the past, automatically format provided time for tomorrow \n"
Expand Down Expand Up @@ -97,39 +97,38 @@ def _run(
except Exception as e:
raise ToolException(str(e))

end = action.get("end")

if not end:
length_in_minutes = event_type.get("length")

end = (
datetime.strptime(start, "%Y-%m-%dT%H:%M:%S.000Z")
+ timedelta(minutes=length_in_minutes)
).strftime("%Y-%m-%dT%H:%M:%S.000Z")
length_in_minutes = event_type.get("length")

end = (
datetime.strptime(start, "%Y-%m-%dT%H:%M:%S.000Z")
+ timedelta(minutes=length_in_minutes)
).strftime("%Y-%m-%dT%H:%M:%S.000Z")

data = {
"eventTypeId": event_type.get("id"),
"start": start,
"end": end,
"metadata": {}, # TODO(low): research what we can pass here
"responses": {
"name": action.get("name", self.account.name),
"email": action.get("email", ""),
"notes": action.get("notes", ""),
"phone": action.get("phone", ""),
"location": action.get("location", ""),
},
"timeZone": action.get("timeZone", "Asia/Tbilisi"),
"language": action.get("language", "en"),
"title": action.get("title", ""),
"description": action.get("description", ""),
"hasHashedBookingLink": False,
"hashedLink": None,
}

try:
response = requests.post(
f"{base_url}/bookings",
params={"apiKey": cal_api_key},
json={
"eventTypeId": event_type.get("id"),
"start": start,
"end": end,
"metadata": {}, # TODO(low): research what we can pass here
"responses": {
"name": action.get("name", self.account.name),
"email": action.get("email", ""),
"notes": action.get("notes", ""),
"phone": action.get("phone", ""),
"location": action.get("location", ""),
},
"timeZone": action.get("timeZone", "Asia/Tbilisi"),
"language": action.get("language", "en"),
"title": action.get("title", ""),
"description": action.get("description", ""),
"hasHashedBookingLink": False,
"hashedLink": None,
},
json=data,
)
except Exception as e:
raise ToolException(str(e))
Expand Down

0 comments on commit 81832d9

Please sign in to comment.