in backend-apis/app/routers/p6_field_service_agent.py [0:0]
def schedule_event(data: ScheduleEventRequest) -> ScheduleEventResponse:
"""
# Creates an event using Calendar API with Google Meet
## Request body for schedule-event
**event_summary**: *string*
- Event summary
**attendees**: *list*
- List of attendees
**start_time**: *string*
- Start time
**end_time**: *string*
- End time
## Response body for schedule-event
**conference_call_link**: *string*
- Conference call link
**icon_url**: *string*
- Icon URL
**start_time_iso**: *string*
- Start time ISO
**end_time_iso**: *string*
- End time ISO
## Raises
**HTTPException** - *400* - Error
"""
try:
event_summary = "Cymbal Support: Your Event Has Been Scheduled!"
start_date = datetime.fromisoformat(data.start_time)
end_date = (
datetime.fromisoformat(data.start_time) + timedelta(minutes=60)
).isoformat()
result_dict = utils_workspace.create_calendar_event(
event_summary=event_summary,
attendees=data.attendees,
start_date=start_date.isoformat(),
end_date=end_date,
)
except Exception as e:
print(f"ERROR : Calendar Event Creation Failed : {e}")
raise HTTPException(status_code=400, detail=str(e)) from e
calendar_link = (
"https://calendar.google.com/"
f"calendar/u/0/r/day/{start_date.year}/"
f"{start_date.month}/{start_date.day}"
)
email_response_html = f"""<html><body><p>Dear Customer,</p>
<p>Thank you for contacting the support team.</p>
<p>Your event has been scheduled, and one of our experts
will be at your location on the date and time indicated below.</p>
<p><b>Date: </b>{start_date.strftime('%m/%d/%Y, %H:%M:%S')} UTC</p>
<p>Link to your calendar appointment: \
<a href="{calendar_link}">Calendar</a></p>
<p>Best Regards,<br>You support team</p>"""
for attendee in data.attendees:
try:
utils_workspace.send_email_single_thread(
email_response_html=email_response_html,
destination_email_address=attendee,
email_subject=event_summary,
)
except Exception as e:
raise HTTPException(
status_code=400, detail="Could not send the email. " + str(e)
) from e
return ScheduleEventResponse(
conference_call_link=result_dict["hangoutLink"],
calendar_link=calendar_link,
icon_url=result_dict["conferenceData"]["conferenceSolution"][
"iconUri"
],
start_time_iso=result_dict["start"]["dateTime"],
end_time_iso=result_dict["end"]["dateTime"],
)