-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5fcd7f6
commit fef8000
Showing
5 changed files
with
75 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import { AllMiddlewareArgs, SlackCommandMiddlewareArgs } from "@slack/bolt"; | ||
import { OAuth2Client } from "google-auth-library"; | ||
|
||
import { filterEventsForChannels, getEvents, parseEvents } from "../../utils/googleCalendar"; | ||
import { getAllSlackChannels } from "../../utils/channels"; | ||
import { logCommandUsed } from "../../utils/logging"; | ||
import { postEphemeralMessage } from "../../utils/slack"; | ||
import { EventReminderType, remindUpcomingEvent } from "../../utils/eventReminders"; | ||
import { SlackLogger } from "../../classes/SlackLogger"; | ||
|
||
export async function meetingReminderCommandHandler( | ||
{ command, ack, client }: SlackCommandMiddlewareArgs & AllMiddlewareArgs, | ||
googleAuth: OAuth2Client, | ||
): Promise<void> { | ||
ack(); | ||
logCommandUsed(command); | ||
|
||
try { | ||
const slackChannels = await getAllSlackChannels(client); | ||
const fetchedEvents = await getEvents(googleAuth); | ||
const events = parseEvents(fetchedEvents, slackChannels); | ||
const eventsInChannel = filterEventsForChannels(events, [command.channel_name]); | ||
|
||
if (eventsInChannel.length === 0) { | ||
await postEphemeralMessage(client, command.channel_id, command.user_id, "No upcoming events in this channel."); | ||
} else { | ||
const soonestEvent = eventsInChannel.sort((a, b) => a.start.getTime() - b.start.getTime())[0]; | ||
|
||
const commandText = command.text.trim().toLowerCase(); | ||
|
||
await remindUpcomingEvent( | ||
soonestEvent, | ||
client, | ||
commandText == "ping" ? EventReminderType.MANUAL_PING : EventReminderType.MANUAL, | ||
); | ||
await postEphemeralMessage( | ||
client, | ||
command.channel_id, | ||
command.user_id, | ||
"Manual reminder sent for next event in channel.", | ||
); | ||
} | ||
} catch (error) { | ||
SlackLogger.getInstance().error("Failed to send manual meeting reminder", error); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters