Skip to content

Commit

Permalink
Merge pull request activepieces#6307 from volubileai/outlook
Browse files Browse the repository at this point in the history
feat(microsoft-outlook-calendar): create/delete/list events
  • Loading branch information
abuaboud authored Dec 13, 2024
2 parents a447bcf + ef61743 commit 301294b
Show file tree
Hide file tree
Showing 12 changed files with 408 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
{
"extends": [
"../../../../.eslintrc.base.json"
],
"ignorePatterns": [
"!**/*"
],
"overrides": [
{
"files": [
"*.ts",
"*.tsx",
"*.js",
"*.jsx"
],
"rules": {}
},
{
"files": [
"*.ts",
"*.tsx"
],
"rules": {}
},
{
"files": [
"*.js",
"*.jsx"
],
"rules": {}
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# pieces-microsoft-outlook-calendar

This library was generated with [Nx](https://nx.dev).

## Building

Run `nx build pieces-microsoft-outlook-calendar` to build the library.
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"name": "@activepieces/piece-microsoft-outlook-calendar",
"version": "0.0.1"
}
45 changes: 45 additions & 0 deletions packages/pieces/community/microsoft-outlook-calendar/project.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
{
"name": "pieces-microsoft-outlook-calendar",
"$schema": "../../../../node_modules/nx/schemas/project-schema.json",
"sourceRoot": "packages/pieces/community/microsoft-outlook-calendar/src",
"projectType": "library",
"release": {
"version": {
"generatorOptions": {
"packageRoot": "dist/{projectRoot}",
"currentVersionResolver": "git-tag"
}
}
},
"tags": [],
"targets": {
"build": {
"executor": "@nx/js:tsc",
"outputs": [
"{options.outputPath}"
],
"options": {
"outputPath": "dist/packages/pieces/community/microsoft-outlook-calendar",
"tsConfig": "packages/pieces/community/microsoft-outlook-calendar/tsconfig.lib.json",
"packageJson": "packages/pieces/community/microsoft-outlook-calendar/package.json",
"main": "packages/pieces/community/microsoft-outlook-calendar/src/index.ts",
"assets": [
"packages/pieces/community/microsoft-outlook-calendar/*.md"
],
"buildableProjectDepsInPackageJsonType": "dependencies",
"updateBuildableProjectDepsInPackageJson": true
}
},
"nx-release-publish": {
"options": {
"packageRoot": "dist/{projectRoot}"
}
},
"lint": {
"executor": "@nx/eslint:lint",
"outputs": [
"{options.outputFile}"
]
}
}
}
46 changes: 46 additions & 0 deletions packages/pieces/community/microsoft-outlook-calendar/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import {
createPiece,
OAuth2PropertyValue,
PieceAuth,
} from '@activepieces/pieces-framework';
import { createEventAction } from './lib/actions/create-event';
import { listEventsAction } from './lib/actions/list-events';
import { createCustomApiCallAction } from '@activepieces/pieces-common';
import { outlookCalendarCommon } from './lib/common/common';
import { deleteEventAction } from './lib/actions/delete-event';
import { PieceCategory } from '@activepieces/shared';

export const outlookCalendarAuth = PieceAuth.OAuth2({
description: 'Authentication for Microsoft Outlook',
authUrl: 'https://login.microsoftonline.com/common/oauth2/v2.0/authorize',
tokenUrl: 'https://login.microsoftonline.com/common/oauth2/v2.0/token',
required: true,
scope: ['User.Read', 'Calendars.ReadWrite'],
});

export const microsoftOutlookCalendar = createPiece({
displayName: "Microsoft Outlook Calendar",
description: 'Calendar software by Microsoft',
auth: outlookCalendarAuth,
minimumSupportedRelease: '0.30.0',
logoUrl: "https://cdn.activepieces.com/pieces/microsoft-outlook.png",
categories: [PieceCategory.PRODUCTIVITY],
authors: ['antonyvigouret'],
actions: [
createEventAction,
deleteEventAction,
listEventsAction,
createCustomApiCallAction({
auth: outlookCalendarAuth,
baseUrl() {
return outlookCalendarCommon.baseUrl;
},
authMapping: async (auth) => {
return {
Authorization: `Bearer ${(auth as OAuth2PropertyValue).access_token}`,
};
},
}),
],
triggers: [],
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
import { createAction, Property } from '@activepieces/pieces-framework';
import {
AuthenticationType,
httpClient,
HttpMethod,
HttpRequest,
} from '@activepieces/pieces-common';
import { outlookCalendarAuth } from '../..';
import { outlookCalendarCommon } from '../common/common';
import dayjs from 'dayjs';

export const createEventAction = createAction({
auth: outlookCalendarAuth,
name: 'create_event',
description: 'Create a new event in a calendar',
displayName: 'Create a new event in a calendar',
props: {
calendarId: outlookCalendarCommon.calendarDropdown,
title: Property.ShortText({
displayName: 'Title of the event',
required: true,
}),
start: Property.DateTime({
displayName: 'Start date time of the event',
required: true,
}),
end: Property.DateTime({
displayName: 'End date time of the event',
description: "By default it'll be 30 min post start time",
required: false,
}),
timezone: outlookCalendarCommon.timezoneDropdown,
location: Property.ShortText({
displayName: 'Location',
required: false,
}),
},
async run({ propsValue, auth }) {
const startDateTime = dayjs(propsValue.start).format('YYYY-MM-DDTHH:mm:ss');
const endTime = propsValue.end
? propsValue.end
: dayjs(startDateTime).add(30, 'm');
const endDateTime = dayjs(endTime).format('YYYY-MM-DDTHH:mm:ss');

const request: HttpRequest = {
method: HttpMethod.POST,
url: `${outlookCalendarCommon.baseUrl}/calendars/${propsValue.calendarId}/events`,
body: {
subject: propsValue.title,
body: {},
start: {
dateTime: startDateTime,
timeZone: propsValue.timezone,
},
end: {
dateTime: endDateTime,
timeZone: propsValue.timezone,
},
location: {
displayName: propsValue.location,
},
},
authentication: {
type: AuthenticationType.BEARER_TOKEN,
token: auth['access_token'],
},
};

const response = await httpClient.sendRequest(request);

return response.body;
},
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import { createAction, Property } from '@activepieces/pieces-framework';
import {
AuthenticationType,
httpClient,
HttpMethod,
HttpRequest,
} from '@activepieces/pieces-common';
import { outlookCalendarAuth } from '../..';
import { outlookCalendarCommon } from '../common/common';

export const deleteEventAction = createAction({
auth: outlookCalendarAuth,
name: 'delete_event',
description: 'Delete an event in a calendar',
displayName: 'Delete an event in a calendar',
props: {
calendarId: outlookCalendarCommon.calendarDropdown,
eventId: Property.ShortText({
displayName: 'Event ID',
required: true,
}),
},
async run({ propsValue, auth }) {
const request: HttpRequest = {
method: HttpMethod.DELETE,
url: `${outlookCalendarCommon.baseUrl}/calendars/${propsValue.calendarId}/events/${propsValue.eventId}`,
body: {},
authentication: {
type: AuthenticationType.BEARER_TOKEN,
token: auth['access_token'],
},
};

const response = await httpClient.sendRequest(request);

return response.body;
},
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import { createAction, Property } from '@activepieces/pieces-framework';
import {
AuthenticationType,
httpClient,
HttpMethod,
HttpRequest,
} from '@activepieces/pieces-common';
import { outlookCalendarAuth } from '../..';
import { outlookCalendarCommon } from '../common/common';

export const listEventsAction = createAction({
auth: outlookCalendarAuth,
name: 'list_events',
description: 'List events in a calendar',
displayName: 'List events in a calendar',
props: {
calendarId: outlookCalendarCommon.calendarDropdown,
filter: Property.LongText({
displayName: 'Filter',
required: false,
description:
'Search query filter, see: https://learn.microsoft.com/en-us/graph/filter-query-parameter',
}),
},
async run({ propsValue, auth }) {
const queryParams: Record<string, string> = {};

if (propsValue.filter) queryParams['$filter'] = propsValue.filter;

const request: HttpRequest = {
method: HttpMethod.GET,
url: `${outlookCalendarCommon.baseUrl}/calendars/${propsValue.calendarId}/events`,
queryParams,
body: {},
authentication: {
type: AuthenticationType.BEARER_TOKEN,
token: auth['access_token'],
},
};

const response = await httpClient.sendRequest(request);

return response.body;
},
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
import { OAuth2PropertyValue, Property } from '@activepieces/pieces-framework';
import {
AuthenticationType,
httpClient,
HttpMethod,
} from '@activepieces/pieces-common';

export const outlookCalendarCommon = {
baseUrl: 'https://graph.microsoft.com/v1.0/me',
calendarDropdown: Property.Dropdown({
displayName: 'Calendar',
required: true,
options: async ({ auth }) => {
if (!auth) {
return {
disabled: true,
options: [],
placeholder: 'Please authenticate first',
};
}
const authProp: OAuth2PropertyValue = auth as OAuth2PropertyValue;
const calendars: { id: string; name: string }[] = (
await httpClient.sendRequest<{ value: { id: string; name: string }[] }>(
{
method: HttpMethod.GET,
url: `${outlookCalendarCommon.baseUrl}/calendars`,
authentication: {
type: AuthenticationType.BEARER_TOKEN,
token: authProp['access_token'],
},
}
)
).body.value;
return {
disabled: false,
options: calendars.map((calendar: { id: string; name: string }) => {
return {
label: calendar.name,
value: calendar.id,
};
}),
};
},
refreshers: [],
}),
timezoneDropdown: Property.Dropdown({
displayName: 'Timezone',
required: true,
options: async ({ auth }) => {
if (!auth) {
return {
disabled: true,
options: [],
placeholder: 'Please authenticate first',
};
}
const authProp: OAuth2PropertyValue = auth as OAuth2PropertyValue;
const timezones: { displayName: string; alias: string }[] = (
await httpClient.sendRequest<{
value: { displayName: string; alias: string }[];
}>({
method: HttpMethod.GET,
url: `${outlookCalendarCommon.baseUrl}/outlook/supportedTimeZones`,
authentication: {
type: AuthenticationType.BEARER_TOKEN,
token: authProp['access_token'],
},
})
).body.value;
return {
disabled: false,
options: timezones.map(
(timezone: { displayName: string; alias: string }) => {
return {
label: timezone.displayName,
value: timezone.alias,
};
}
),
};
},
refreshers: [],
}),
};
Loading

0 comments on commit 301294b

Please sign in to comment.