Tandem Video (#1671)
* Tandem Video * Updating some copy * adding some instructions for getting client id + secret * PR Feedback * removing spurious tsconfig file
This commit is contained in:
1 parent
dedf001237
commit
ae5d5e1261
27 files changed
+336
-3
No files matched your search
@@ -53,8 +53,12 @@ export const isHuddle01 = (location: string): boolean => {
|
||||
return location === "integrations:huddle01";
|
||||
};
|
||||
|
||||
export const isTandem = (location: string): boolean => {
|
||||
return location === "integrations:tandem";
|
||||
};
|
||||
|
||||
export const isDedicatedIntegration = (location: string): boolean => {
|
||||
return isZoom(location) || isDaily(location) || isHuddle01(location);
|
||||
return isZoom(location) || isDaily(location) || isHuddle01(location) || isTandem(location);
|
||||
};
|
||||
|
||||
export const getLocationRequestFromIntegration = (location: string) => {
|
||||
@@ -62,7 +66,8 @@ export const getLocationRequestFromIntegration = (location: string) => {
|
||||
location === LocationType.GoogleMeet.valueOf() ||
|
||||
location === LocationType.Zoom.valueOf() ||
|
||||
location === LocationType.Daily.valueOf() ||
|
||||
location === LocationType.Huddle01.valueOf()
|
||||
location === LocationType.Huddle01.valueOf() ||
|
||||
location === LocationType.Tandem.valueOf()
|
||||
) {
|
||||
const requestId = uuidv5(location, uuidv5.URL);
|
||||
|
||||
|
||||
@@ -16,6 +16,8 @@ export function getIntegrationName(name: string) {
|
||||
return "Daily";
|
||||
case "huddle01_video":
|
||||
return "Huddle01";
|
||||
case "tandem_video":
|
||||
return "Tandem";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,143 @@
|
||||
import { Credential } from "@prisma/client";
|
||||
|
||||
import { handleErrorsJson, handleErrorsRaw } from "@lib/errors";
|
||||
import { PartialReference } from "@lib/events/EventManager";
|
||||
import prisma from "@lib/prisma";
|
||||
import { VideoApiAdapter, VideoCallData } from "@lib/videoClient";
|
||||
|
||||
import { CalendarEvent } from "../calendar/interfaces/Calendar";
|
||||
|
||||
interface TandemToken {
|
||||
expires_in?: number;
|
||||
expiry_date: number;
|
||||
refresh_token: string;
|
||||
token_type: "Bearer";
|
||||
access_token: string;
|
||||
}
|
||||
|
||||
const client_id = process.env.TANDEM_CLIENT_ID as string;
|
||||
const client_secret = process.env.TANDEM_CLIENT_SECRET as string;
|
||||
const TANDEM_BASE_URL = process.env.TANDEM_BASE_URL as string;
|
||||
|
||||
const tandemAuth = (credential: Credential) => {
|
||||
const credentialKey = credential.key as unknown as TandemToken;
|
||||
const isTokenValid = (token: TandemToken) => token && token.access_token && token.expiry_date < Date.now();
|
||||
|
||||
const refreshAccessToken = (refreshToken: string) => {
|
||||
fetch(`${TANDEM_BASE_URL}/api/v1/oauth/v2/token`, {
|
||||
method: "POST",
|
||||
body: new URLSearchParams({
|
||||
client_id,
|
||||
client_secret,
|
||||
code: refreshToken,
|
||||
}),
|
||||
})
|
||||
.then(handleErrorsJson)
|
||||
.then(async (responseBody) => {
|
||||
// set expiry date as offset from current time.
|
||||
responseBody.expiry_date = Math.round(Date.now() + responseBody.expires_in * 1000);
|
||||
delete responseBody.expires_in;
|
||||
// Store new tokens in database.
|
||||
await prisma.credential.update({
|
||||
where: {
|
||||
id: credential.id,
|
||||
},
|
||||
data: {
|
||||
key: responseBody,
|
||||
},
|
||||
});
|
||||
credentialKey.expiry_date = responseBody.expiry_date;
|
||||
credentialKey.access_token = responseBody.access_token;
|
||||
credentialKey.refresh_token = responseBody.refresh_token;
|
||||
return credentialKey.access_token;
|
||||
});
|
||||
};
|
||||
|
||||
return {
|
||||
getToken: () =>
|
||||
!isTokenValid(credentialKey)
|
||||
? Promise.resolve(credentialKey.access_token)
|
||||
: refreshAccessToken(credentialKey.refresh_token),
|
||||
};
|
||||
};
|
||||
|
||||
const TandemVideoApiAdapter = (credential: Credential): VideoApiAdapter => {
|
||||
const auth = tandemAuth(credential);
|
||||
|
||||
const _parseDate = (date: string) => {
|
||||
return Date.parse(date) / 1000;
|
||||
};
|
||||
|
||||
const _translateEvent = (event: CalendarEvent, param: string): string => {
|
||||
return JSON.stringify({
|
||||
[param]: {
|
||||
title: event.title,
|
||||
starts_at: _parseDate(event.startTime),
|
||||
ends_at: _parseDate(event.endTime),
|
||||
description: event.description || "",
|
||||
conference_solution: "tandem",
|
||||
type: 3,
|
||||
},
|
||||
});
|
||||
};
|
||||
|
||||
const _translateResult = (result: { data: { id: string; event_link: string } }) => {
|
||||
return {
|
||||
type: "tandem_video",
|
||||
id: result.data.id as string,
|
||||
password: "",
|
||||
url: result.data.event_link,
|
||||
};
|
||||
};
|
||||
|
||||
return {
|
||||
/** Tandem doesn't need to return busy times, so we return empty */
|
||||
getAvailability: () => {
|
||||
return Promise.resolve([]);
|
||||
},
|
||||
createMeeting: async (event: CalendarEvent): Promise<VideoCallData> => {
|
||||
const accessToken = await auth.getToken();
|
||||
|
||||
const result = await fetch(`${TANDEM_BASE_URL}/api/v1/meetings`, {
|
||||
method: "POST",
|
||||
headers: {
|
||||
Authorization: "Bearer " + accessToken,
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
body: _translateEvent(event, "meeting"),
|
||||
}).then(handleErrorsJson);
|
||||
|
||||
return Promise.resolve(_translateResult(result));
|
||||
},
|
||||
|
||||
deleteMeeting: async (uid: string): Promise<void> => {
|
||||
const accessToken = await auth.getToken();
|
||||
|
||||
await fetch(`${TANDEM_BASE_URL}/api/v1/meetings/${uid}`, {
|
||||
method: "DELETE",
|
||||
headers: {
|
||||
Authorization: "Bearer " + accessToken,
|
||||
},
|
||||
}).then(handleErrorsRaw);
|
||||
|
||||
return Promise.resolve();
|
||||
},
|
||||
|
||||
updateMeeting: async (bookingRef: PartialReference, event: CalendarEvent): Promise<VideoCallData> => {
|
||||
const accessToken = await auth.getToken();
|
||||
|
||||
const result = await fetch(`${TANDEM_BASE_URL}/api/v1/meetings/${bookingRef.meetingId}`, {
|
||||
method: "PUT",
|
||||
headers: {
|
||||
Authorization: "Bearer " + accessToken,
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
body: _translateEvent(event, "updates"),
|
||||
}).then(handleErrorsJson);
|
||||
|
||||
return Promise.resolve(_translateResult(result));
|
||||
},
|
||||
};
|
||||
};
|
||||
|
||||
export default TandemVideoApiAdapter;
|
||||
@@ -20,6 +20,7 @@ export type Integration = {
|
||||
| "office365_calendar"
|
||||
| "zoom_video"
|
||||
| "daily_video"
|
||||
| "tandem_video"
|
||||
| "caldav_calendar"
|
||||
| "apple_calendar"
|
||||
| "stripe_payment"
|
||||
@@ -72,6 +73,14 @@ export const ALL_INTEGRATIONS = [
|
||||
description: "Video Conferencing",
|
||||
variant: "conferencing",
|
||||
},
|
||||
{
|
||||
installed: !!(process.env.TANDEM_CLIENT_ID && process.env.TANDEM_CLIENT_SECRET),
|
||||
type: "tandem_video",
|
||||
title: "Tandem Video",
|
||||
imageSrc: "integrations/tandem.svg",
|
||||
description: "Virtual Office | Video Conferencing",
|
||||
variant: "conferencing",
|
||||
},
|
||||
{
|
||||
installed: true,
|
||||
type: "caldav_calendar",
|
||||
|
||||
@@ -5,4 +5,5 @@ export enum LocationType {
|
||||
Zoom = "integrations:zoom",
|
||||
Daily = "integrations:daily",
|
||||
Huddle01 = "integrations:huddle01",
|
||||
Tandem = "integrations:tandem",
|
||||
}
|
||||
@@ -9,6 +9,7 @@ import Huddle01VideoApiAdapter from "@lib/integrations/Huddle01/Huddle01VideoApi
|
||||
import logger from "@lib/logger";
|
||||
|
||||
import DailyVideoApiAdapter from "./integrations/Daily/DailyVideoApiAdapter";
|
||||
import TandemVideoApiAdapter from "./integrations/Tandem/TandemVideoApiAdapter";
|
||||
import ZoomVideoApiAdapter from "./integrations/Zoom/ZoomVideoApiAdapter";
|
||||
import { CalendarEvent } from "./integrations/calendar/interfaces/Calendar";
|
||||
|
||||
@@ -48,6 +49,9 @@ const getVideoAdapters = (withCredentials: Credential[]): VideoApiAdapter[] =>
|
||||
case "huddle01_video":
|
||||
acc.push(Huddle01VideoApiAdapter());
|
||||
break;
|
||||
case "tandem_video":
|
||||
acc.push(TandemVideoApiAdapter(cred));
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user