Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(google-calendar): event color option for create/update event action #4572

Merged
merged 3 commits into from Apr 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/pieces/community/google-calendar/package.json
@@ -1,4 +1,4 @@
{
"name": "@activepieces/piece-google-calendar",
"version": "0.5.3"
"version": "0.5.4"
}
2 changes: 1 addition & 1 deletion packages/pieces/community/google-calendar/src/index.ts
Expand Up @@ -9,7 +9,7 @@ import { createEvent } from './lib/actions/create-event';
import { createQuickCalendarEvent } from './lib/actions/create-quick-event';
import { deleteEventAction } from './lib/actions/delete-event.action';
import { getEvents } from './lib/actions/get-events';
import { updateEventAction } from './lib/actions/update-event.ation';
import { updateEventAction } from './lib/actions/update-event.action';
import { googleCalendarCommon } from './lib/common';
import { calendarEventChanged } from './lib/triggers/calendar-event';

Expand Down
Expand Up @@ -39,6 +39,7 @@ export const createEvent = createAction({
description: 'Description of the event. You can use HTML tags here.',
required: false,
}),
colorId: googleCalendarCommon.colorId,
attendees: Property.Array({
displayName: 'Attendees',
description: 'Emails of the attendees (guests)',
Expand All @@ -65,7 +66,10 @@ export const createEvent = createAction({
options: {
options: [
{ label: 'Yes, to everyone', value: 'all' },
{ label: 'To non-Google Calendar guests only', value: 'externalOnly' },
{
label: 'To non-Google Calendar guests only',
value: 'externalOnly',
},
{ label: 'To no one', value: 'none' },
],
},
Expand All @@ -81,12 +85,12 @@ export const createEvent = createAction({
end_date_time,
location,
description,
colorId,
guests_can_modify: guestsCanModify,
guests_can_invite_others: guestsCanInviteOthers,
guests_can_see_other_guests: guestsCanSeeOtherGuests,
} = configValue.propsValue;


const start = {
dateTime: dayjs(start_date_time).format('YYYY-MM-DDTHH:mm:ss.sssZ'),
};
Expand All @@ -100,34 +104,34 @@ export const createEvent = createAction({
/*const attachment = {
fileUrl: configValue.propsValue.attachment,
};*/

const attendeesArray = configValue.propsValue.attendees as string[];

const sendNotifications = configValue.propsValue.send_notifications;

const attendeesObject = [];
if (attendeesArray) {
for (const attendee of attendeesArray) {
attendeesObject.push({ email: attendee});
attendeesObject.push({ email: attendee });
}
}

console.log

const authClient = new OAuth2Client();
authClient.setCredentials(configValue.auth);

const calendar = google.calendar({ version: 'v3', auth: authClient });

const response = await calendar.events.insert({
calendarId,
sendUpdates: sendNotifications,
requestBody: {
summary,
start,
end,
colorId,
//attachments: configValue.propsValue.attachment ? [attachment] : [],
location: location ?? "",
description: description ?? "",
location: location ?? '',
description: description ?? '',
attendees: attendeesObject,
guestsCanInviteOthers,
guestsCanModify,
Expand Down
@@ -0,0 +1,129 @@
import { Property, createAction } from '@activepieces/pieces-framework';
import { google, calendar_v3 } from 'googleapis';
import { OAuth2Client } from 'googleapis-common';
import { googleCalendarAuth } from '../../index';
import { googleCalendarCommon } from '../common';
import dayjs from 'dayjs';

export const updateEventAction = createAction({
displayName: 'Update Event',
auth: googleCalendarAuth,
name: 'update_event',
description: 'Updates an event in Google Calendar.',
props: {
calendar_id: googleCalendarCommon.calendarDropdown('writer'),
eventId: Property.ShortText({
displayName: 'Event ID',
required: true,
}),
title: Property.ShortText({
displayName: 'Title of the event',
required: false,
}),
start_date_time: Property.DateTime({
displayName: 'Start date time of the event',
required: false,
}),
end_date_time: Property.DateTime({
displayName: 'End date time of the event',
required: false,
}),
location: Property.ShortText({
displayName: 'Location',
required: false,
}),
description: Property.LongText({
displayName: 'Description',
description: 'Description of the event. You can use HTML tags here.',
required: false,
}),
colorId: googleCalendarCommon.colorId,
attendees: Property.Array({
displayName: 'Attendees',
description: 'Emails of the attendees (guests)',
required: false,
}),
guests_can_modify: Property.Checkbox({
displayName: 'Guests can modify',
defaultValue: false,
required: false,
}),
guests_can_invite_others: Property.Checkbox({
displayName: 'Guests can invite others',
defaultValue: false,
required: false,
}),
guests_can_see_other_guests: Property.Checkbox({
displayName: 'Guests can see other guests',
defaultValue: false,
required: false,
}),
},
async run(context) {
const {
calendar_id,
eventId,
title,
start_date_time,
end_date_time,
location,
description,
colorId,
guests_can_invite_others,
guests_can_modify,
guests_can_see_other_guests,
} = context.propsValue;

const attendees = context.propsValue.attendees as string[];

const authClient = new OAuth2Client();
authClient.setCredentials(context.auth);
const calendar = google.calendar({ version: 'v3', auth: authClient });

// Note that each patch request consumes three quota units;
// prefer using a get followed by an update
const currentEvent = await calendar.events.get({
calendarId: calendar_id,
eventId: eventId,
});

let attendeeFormattedList: calendar_v3.Schema$EventAttendee[] = [];
if (Array.isArray(attendees) && attendees.length > 0) {
attendeeFormattedList = attendees.map((email) => ({ email }));
} else if (
currentEvent.data.attendees &&
Array.isArray(currentEvent.data.attendees)
) {
attendeeFormattedList = currentEvent.data.attendees;
}

const response = await calendar.events.update({
calendarId: calendar_id,
eventId: eventId,
requestBody: {
summary: title ?? currentEvent.data.summary,
attendees: attendeeFormattedList,
description: description ?? currentEvent.data.description,
colorId: colorId,
location: location ?? currentEvent.data.location,
start: start_date_time
? {
dateTime: dayjs(start_date_time).format(
'YYYY-MM-DDTHH:mm:ss.sssZ'
),
}
: currentEvent.data.start,
end: end_date_time
? {
dateTime: dayjs(end_date_time).format('YYYY-MM-DDTHH:mm:ss.sssZ'),
}
: currentEvent.data.end,
guestsCanInviteOthers: guests_can_invite_others,
guestsCanModify: guests_can_modify,
guestsCanSeeOtherGuests: guests_can_see_other_guests,
},
});

return response.data;
},
});

This file was deleted.