Skip to content
This repository has been archived by the owner on Aug 30, 2022. It is now read-only.

Commit

Permalink
Add 60 seconds delay to meetbot spawn
Browse files Browse the repository at this point in the history
Signed-off-by: Vipul Gupta (@vipulgupta2048) <vipul@balena.io>
  • Loading branch information
vipulgupta2048 committed Jan 28, 2022
1 parent a2fc21e commit 31ca311
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 28 deletions.
1 change: 1 addition & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@
**/dist/

tests/
img/
*.png
*.log
7 changes: 5 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,10 @@ Meetbot helps you out by:
1. Validating audio input of attendees minus the awkward silence.
2. Recording chat transcript.
3. Recording voice caption transcript.
4. Auto-recording meetings.
5. Saving it all to Google Docs for easy sharing!
4. Chat commands to resend transcripts for folks joining late.
5. Auto-record meetings.
6. Auto-join meetings using Google Calendar API.
7. Saving it all to Google Docs for easy sharing!

And, many more features.

Expand All @@ -37,6 +39,7 @@ By default, meetbot will join meetings as an unauthenticated user and won't be a
| GOOGLE_TOTP_SECRET | If the Google account has 2FA security, then the TOTP secret that is configured for 2FA goes here | NA |
| HTTP_PORT | (Optional) Port on which the meetbot server starts running. For balena devices, the server needs to run on port 80 | 80 |
| MAX_BOTS | (Optional) Maximum number of meetbots to run parallely on the server | 5 |
| GOOGLE_CALENDAR_NAME | (Optional) The Google calendar ID that meetbot parses to auto-join events in that calendar | 5 |
| GREETING_MESSAGE | (Optional) Greeting message which is posted when meetbot joins the Google Meet | "Hello folks, it's your favorite bot, hubot!!" |

Read more about [variables](https://www.balena.io/docs/learn/manage/variables/) in balenaCloud Dashboard.
Expand Down
2 changes: 0 additions & 2 deletions src/google/google-calendar.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import * as fs from 'fs';
import { Auth, google, calendar_v3 } from 'googleapis';
// import { GaxiosResponse } from 'gaxios';
import { getNewToken } from './token-generator';

// The file token.json stores the user's access and refresh tokens, and is
Expand Down Expand Up @@ -54,7 +53,6 @@ export class GoogleCalendar {
calendarId: `${calendarName}`,
timeMin: new Date().toISOString(),
maxResults: 15,
// maxResults: 100,
singleEvents: true,
orderBy: 'startTime',
});
Expand Down
41 changes: 22 additions & 19 deletions src/meetbot-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,13 +137,12 @@ export async function scheduleBotsForMeetings() {
let meetingSchedule: DataPacket[] = await calendar.listEvents(
process.env.GOOGLE_CALENDAR_NAME,
);
console.log(meetingSchedule);
console.log(`
Start Meeting Scheduler${
meetingSchedule.length
? `: Tracking ${meetingSchedule.length}+ meetings`
: `: (No meetings found)`
}

console.log(`Start Meeting Scheduler${
meetingSchedule.length
? `: Tracking ${meetingSchedule.length}+ meetings`
: `: (No meetings found)`
}
`);

// Check for events on the calendar and refresh schedule
Expand All @@ -157,27 +156,31 @@ export async function scheduleBotsForMeetings() {
if (meetingSchedule.length) {
setInterval(async () => {
for (const meeting of meetingSchedule) {
if (new Date(meeting.startTime).getTime() <= new Date().getTime()) {
// Add 60 seconds to delay meetbot spawn
if (
new Date(meeting.startTime).getTime() + 60000 <=
new Date().getTime()
) {
const activeBots = await listBots();
const botURLs = activeBots.map((bot) => bot.url);
console.log(botURLs);
if (activeBots.length) {
for (const bot of activeBots) {
if (bot.url !== meeting.meetUrl) {
console.log(
`Spawning meetbot for ${meeting.name} at ${meeting.meetUrl}`,
);
await spawnBot(meeting.meetUrl);
}
if (botURLs.includes(meeting.meetUrl)) {
continue;
} else {
console.log(
`Spawning meetbot for ${meeting.name} at ${meeting.meetUrl}`,
);
await spawnBot(meeting.meetUrl);
}
} else {
console.log(
`Spawning meetbot for ${meeting.name} at ${meeting.meetUrl}`,
`No active meetbots found. Spawning one for ${meeting.name} at ${meeting.meetUrl}`,
);
await spawnBot(meeting.meetUrl);
}
} else {
// The meeting schedule is ordered by startTime
// So if the meeting is very far we can stop checking at the first event
return;
// Do Nothing
}
}
}, SCHEDULE_PARSING_INTERVAL);
Expand Down
6 changes: 1 addition & 5 deletions src/meetbot/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,6 @@ export interface Bot {
const login = process.env.GOOGLE_EMAIL;
const password = process.env.GOOGLE_PASSWORD;
const totpSecret = process.env.GOOGLE_TOTP_SECRET;
const LEAVE_TIMER = parseInt(
process.env.LEAVE_TIMER || `${450000}`, // Value needs to be in milliseconds
10,
);

class MeetBot implements Bot {
public page: Page | null = null;
Expand Down Expand Up @@ -188,7 +184,7 @@ class MeetBot implements Bot {
await this.page.waitForTimeout(500);

// names of participants in list
const participants = await this.page.$$('span.ZjFb7c');
const participants = await this.page.$$('span.zWGUib');
this.emit('participants', { participants: participants.length });

if (participants.length === 1) {
Expand Down

0 comments on commit 31ca311

Please sign in to comment.