Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save dimitrispaxinos/9244d6a74f255d20d650d5cf0d671164 to your computer and use it in GitHub Desktop.
Save dimitrispaxinos/9244d6a74f255d20d650d5cf0d671164 to your computer and use it in GitHub Desktop.
const localLogger = new LocalLogger();
function onOpen(e) {
localLogger.init();
}
function doPost(e) {
// Read JSON content from the request
const requestBody = JSON.parse(e.postData.contents);
// Read Parameters
const parameters = requestBody.message.functionCall.parameters;
const startTime = parameters.startTime;
const endTime = parameters.endTime;
const guestEmail = parameters.guestEmail;
const guestName = parameters.guestName;
const notes = parameters.notes;
// Log all Parameters
localLogger.log('Input Parameters: ' + startTime + '| ' + endTime + '| ' + guestEmail + '| ' + guestName + '| ' + notes);
// Book Appointment
var response = createCalendarEvent(startTime, endTime, guestEmail, guestName, notes);
// Return Success Response
return ContentService.createTextOutput(JSON.stringify({ status: 'success', message: response })).setMimeType(ContentService.MimeType.JSON);
}
function createCalendarEvent(sTime, eTime, emailRecipient, name, meetingNotes = null) {
var calendarId = 'primary'; // You can also specify a specific calendar ID
var title = 'Discovery Meeting: Apptiva <> ' + name;
var startTime = new Date(sTime);
var endTime = new Date(eTime);
var event = {
summary: title,
start: {
dateTime: startTime.toISOString()
},
end: {
dateTime: endTime.toISOString()
},
attendees: [{ email: emailRecipient }],
description: !meetingNotes ? '' : 'Meeting Notes:' + meetingNotes,
location: 'Google Meet',
reminders: {
useDefault: false,
overrides: [
{ method: 'email', minutes: 24 * 60 },
{ method: 'popup', minutes: 10 }
]
},
// Adding conferencing details for Google Meet
conferenceData: {
createRequest: {
requestId:
// A unique identifier for the request
Math.random().toString(36).substring(2, 15) + Math.random().toString(36).substring(2, 15)
}
}
};
// Create the event with conference data (Google Meet)
var createdEvent = Calendar.Events.insert(event, calendarId, {
conferenceDataVersion: 1, // To indicate that we are using conferencing features
sendUpdates: 'all' // This will send emails to all guests
});
return createdEvent;
}
function testCal() {
createCalendarEvent('2024-05-15T10:30:00', '2024-05-15T11:00:00', '[email protected]', 'Test Name', 'Voice Bot for booking discovery calls');
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment