From 5fef4bc041d72d726050caa4f2c5764f9ab26a30 Mon Sep 17 00:00:00 2001 From: Chamath Wijesekera Date: Sun, 17 Mar 2024 15:46:23 -0400 Subject: [PATCH] Fix timing and undefined emoji issues (#75) --- src/utils/eventReminders.ts | 12 ++++-------- src/utils/slackEmojis.ts | 2 +- 2 files changed, 5 insertions(+), 9 deletions(-) diff --git a/src/utils/eventReminders.ts b/src/utils/eventReminders.ts index 6e71608..5081155 100644 --- a/src/utils/eventReminders.ts +++ b/src/utils/eventReminders.ts @@ -2,9 +2,9 @@ import { WebClient, ChatPostMessageResponse } from "@slack/web-api"; import moment from "moment-timezone"; import CalendarEvent from "../classes/CalendarEvent"; -import { postMessage, addReactionToMessage, getMessagePermalink, getAllSlackUsers } from "./slack"; +import { postMessage, getMessagePermalink, getAllSlackUsers } from "./slack"; import { getDefaultSlackChannels } from "./channels"; -import { generateEmojiPair } from "./slackEmojis"; +import { generateEmojiPair, seedMessageReactions } from "./slackEmojis"; import SlackChannel from "../classes/SlackChannel"; import SlackUser from "../classes/SlackUser"; import { postMessageToSingleChannelGuestsInChannels } from "./users"; @@ -160,13 +160,9 @@ export async function postReminderToChannel( const timestamp = res.ts; - if (reactEmojis !== undefined) { + if (reactEmojis != undefined && reactEmojis.length > 0) { try { - const [emoji1, emoji2] = reactEmojis; - await addReactionToMessage(client, channel.id, emoji1, timestamp); - // Add small manual delay to ensure sequential reactions - await new Promise((resolve) => setTimeout(resolve, 250)); - await addReactionToMessage(client, channel.id, emoji2, timestamp); + await seedMessageReactions(client, channel.id, reactEmojis, timestamp); } catch (error) { SlackLogger.getInstance().error( `Failed to add reactions \`${reactEmojis}\` to message \`${timestamp}\` in \`${channel.name}\` with error:`, diff --git a/src/utils/slackEmojis.ts b/src/utils/slackEmojis.ts index de664d4..61d5c1c 100644 --- a/src/utils/slackEmojis.ts +++ b/src/utils/slackEmojis.ts @@ -35,7 +35,7 @@ export async function seedMessageReactions( timestamp: string | number, ): Promise { const response = await addReactionToMessage(client, channel, emojis[0], timestamp); - + await new Promise((resolve) => setTimeout(resolve, 500)); if (response.ok) { await addReactionToMessage(client, channel, emojis[1], timestamp); }