Skip to content

Commit

Permalink
Merge pull request #221 from ThatConference/feat/online-create-channel
Browse files Browse the repository at this point in the history
feat: create discord channel on create open space
  • Loading branch information
brettski committed Oct 30, 2023
2 parents 4be2775 + 7a54185 commit 119afbb
Show file tree
Hide file tree
Showing 9 changed files with 275 additions and 3 deletions.
2 changes: 2 additions & 0 deletions .env.sample
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ AUTH0_ISSUER=

# THAT
OG_IMAGE_BASE_URL=
THAT_JOIN_BOT_BASE_URL=''
THAT_REQUEST_SIGNING_KEY=''

# graphCdn
GRAPHCDN_TOKEN=
Expand Down
28 changes: 26 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "that-api-sessions",
"version": "4.4.0",
"version": "4.5.0",
"description": "THAT Conference Sessions Service.",
"main": "index.js",
"engines": {
Expand Down Expand Up @@ -38,6 +38,7 @@
"debug": "^4.3.4",
"dotenv": "^16.3.1",
"express": "^4.18.2",
"fetch-retry": "^5.0.6",
"googleapis": "^128.0.0",
"graphql": "^16.8.1",
"graphql-scalars": "^1.22.4",
Expand Down Expand Up @@ -68,6 +69,7 @@
"eslint-plugin-prettier": "^5.0.1",
"husky": "^8.0.3",
"jest-cli": "^29.7.0",
"mockdate": "^3.0.5",
"nodemon": "^3.0.1",
"prettier-eslint": "^16.1.1",
"prettier-eslint-cli": "^8.0.1"
Expand Down
8 changes: 8 additions & 0 deletions src/envConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,14 @@ const requiredConfig = () => ({
process.env.NOTIFICATION_EMAIL_FROM || 'hello@thatconference.com',
ogImageBaseUrl:
process.env.OG_IMAGE_BASE_URL || configMissing('OG_IMAGE_BASE_URL'),
thatJoinDiscordBot: {
baseUrl:
process.env.THAT_JOIN_BOT_BASE_URL ??
configMissing('THAT_JOIN_BOT_BASE_URL'),
},
thatRequestSigningKey:
process.env.THAT_REQUEST_SIGNING_KEY ||
configMissing('THAT_REQUEST_SIGNING_KEY'),
});

export default requiredConfig();
18 changes: 18 additions & 0 deletions src/events/admin.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import calendarEvent from '../lib/calendarEvent';
import determineSessionChanges from '../lib/determineSessionChanges';
import slackNotifications from '../lib/slackNotifications';
import callOgImage from '../lib/callOgImage';
import { createVoiceChannelForSession } from '../lib/callThatJoinDiscordBot';

const dlog = debug('that:api:sessions:events:admin');
const calEvent = calendarEvent(
Expand Down Expand Up @@ -329,24 +330,41 @@ export default function adminEvents(postmark) {
.catch(e => process.nextTick(() => adminEventEmitter.emit('error', e)));
}

function createDiscordVoiceChannel({ session }) {
dlog('createDiscordVoiceChannel called');
if (session.status === 'ACCEPTED') {
createVoiceChannelForSession({ session })
.then(() => dlog('creteVoiceChannelForSessions done. %o'))
.catch(err =>
process.nextTick(() => adminEventEmitter.emit('error', err)),
);
} else {
dlog('session not accepted, not creating discord channel');
}
}

// ********************
// Intiaialize emitters
adminEventEmitter.on('calendarError', err => {
dlog('calendarError %O', err);
Sentry.setTag('section', 'adminEventEmitter');
Sentry.captureException(new SharedCalendarError(err.message));
});

adminEventEmitter.on('error', err => {
dlog('error %O', err);
Sentry.setTag('section', 'adminEventEmitter');
Sentry.captureException(new Error(err.message));
});

adminEventEmitter.on('sessionCreated', insertSharedCalendar);
adminEventEmitter.on('sessionCreated', setOgImage);
adminEventEmitter.on('sessionCreated', createDiscordVoiceChannel);
adminEventEmitter.on('sessionUpdated', sendFavoritesSessionUpdateEmail);
adminEventEmitter.on('sessionUpdated', updateSharedCalendar);
adminEventEmitter.on('sessionUpdated', sendSessionUpdatedSlack);
adminEventEmitter.on('sessionUpdated', setOgImage);
adminEventEmitter.on('sessionUpdated', createDiscordVoiceChannel);
adminEventEmitter.on('sessionCancelled', sendFavoritesSessionUpdateEmail);
adminEventEmitter.on('sessionCancelled', cancelSharedCalendar);
adminEventEmitter.on('sessionCancelled', sendSessionCancelledSlack);
Expand Down
19 changes: 19 additions & 0 deletions src/events/user.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import envConfig from '../envConfig';
import calendarEvent from '../lib/calendarEvent';
import slackNotifications from '../lib/slackNotifications';
import callOgImage from '../lib/callOgImage';
import { createVoiceChannelForSession } from '../lib/callThatJoinDiscordBot';
import { SharedCalendarError, SendEmailError } from '../lib/errors';

const dlog = debug('that:api:sessions:events:user');
Expand Down Expand Up @@ -326,6 +327,19 @@ function userEvents(postmark) {
.catch(e => process.nextTick(() => userEventEmitter.emit('error', e)));
}

function createDiscordVoiceChannel({ session }) {
dlog('createDiscordVoiceChannel called');
if (session.status === 'ACCEPTED') {
createVoiceChannelForSession({ session })
.then(() => dlog('createVoiceChannelForSession done.'))
.catch(err =>
process.nextTick(() => userEventEmitter.emit('error', err)),
);
} else {
dlog('session not accepted, not creating discord channel');
}
}

function sendOrbitLoveActivityOnCreate({ session, user, event, firestore }) {
dlog('call sendOrbitLove Activity, on create');
const orbitLoveApi = orbitLove.orbitLoveApi({ firestore });
Expand Down Expand Up @@ -377,15 +391,18 @@ function userEvents(postmark) {
}

userEventEmitter.on('emailError', err => {
dlog('emailError %O', err);
Sentry.setTag('section', 'userEventEmitter');
Sentry.captureException(new SendEmailError(err.message));
});

userEventEmitter.on('calendarError', err => {
dlog('calendarError %O', err);
Sentry.setTag('section', 'userEventEmitter');
Sentry.captureException(new SharedCalendarError(err.message));
});
userEventEmitter.on('error', err => {
dlog('error %O', err);
Sentry.setTag('section', 'adminEventEmitter');
Sentry.captureException(new Error(err.message));
});
Expand All @@ -394,10 +411,12 @@ function userEvents(postmark) {
userEventEmitter.on('sessionCreated', insertSharedCalendar);
userEventEmitter.on('sessionCreated', sendSessionCreatedSlack);
userEventEmitter.on('sessionCreated', setOgImage);
userEventEmitter.on('sessionCreated', createDiscordVoiceChannel);
userEventEmitter.on('sessionCreated', sendOrbitLoveActivityOnCreate);
userEventEmitter.on('sessionUpdated', sendSessionUpdatedEmail);
userEventEmitter.on('sessionUpdated', updateSharedCalendar);
userEventEmitter.on('sessionUpdated', setOgImage);
userEventEmitter.on('sessionUpdated', createDiscordVoiceChannel);
userEventEmitter.on('sessionUpdated', sendOrbitLoveActivtyOnUpdate);
userEventEmitter.on('sessionCancelled', cancelSharedCalendar);

Expand Down
62 changes: 62 additions & 0 deletions src/lib/__test__/findDateAtNextHour.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
import { findDateAtNextHour } from '../findDateAtNextHour';
import dayjs from 'dayjs';
import mockDate from 'mockdate';

const tests = [
{
now: '2023-10-11T10:10:10',
for: 8,
expect: dayjs('2023-10-11T10:10:10')
.add(1, 'day')
.hour(8)
.startOf('hour')
.toDate(),
},
{
now: '2023-10-11T10:10:10',
for: 12,
expect: dayjs('2023-10-11T10:10:10').hour(12).startOf('hour').toDate(),
},
{
now: '2023-10-11T10:10:10',
for: 10,
expect: dayjs('2023-10-11T10:10:10')
.add(1, 'day')
.hour(10)
.startOf('hour')
.toDate(),
},
{
now: '2023-10-11T11:00:00',
for: 11,
expect: dayjs('2023-10-11T11:00:00').hour(11).startOf('hour').toDate(),
},
{
now: '2023-10-11T11:00:01',
for: 11,
expect: dayjs('2023-10-11T11:00:00')
.add(1, 'day')
.hour(11)
.startOf('hour')
.toDate(),
},
{
now: '2023-10-11T10:59:59',
for: 11,
expect: dayjs('2023-10-11T10:59:59').hour(11).startOf('hour').toDate(),
},
];

describe('findDateAtNextHour tests', () => {
tests.forEach(testData => {
it(`with ${testData.now}, hour ${testData.for}, returns ${testData.expect}`, () => {
mockDate.set(testData.now);
const result = findDateAtNextHour(testData.for);
expect(result.toString()).toBe(testData.expect.toString());
});
});

afterEach(() => {
mockDate.reset();
});
});
Loading

0 comments on commit 119afbb

Please sign in to comment.