-
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.
Implement
/meeting-reminder
command (#67)
- Loading branch information
1 parent
6a95a1f
commit 78fe2ab
Showing
9 changed files
with
146 additions
and
36 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
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,54 @@ | ||
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"; | ||
|
||
/** | ||
* Handler for the /meeting_reminder command | ||
* @param obj The arguments for the middleware | ||
* @param obj.ack The Bolt app's `ack()` function | ||
* @param obj.command The command payload | ||
* @param obj.client The Bolt app client | ||
* @param googleAuth The OAuth2Client for Google Calendar | ||
*/ | ||
export default 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
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