diff --git a/src/functions/mirror.ts b/src/functions/mirror.ts index 7217258..02c8979 100644 --- a/src/functions/mirror.ts +++ b/src/functions/mirror.ts @@ -3,6 +3,8 @@ import { blog } from "../util/Logger"; let hcTeam = "T0266FRGM"; let hcChannel_purplebubble = "C068D2P46TH"; let hcChannel_pbip = "C06AXC7B0QN"; +let hcmirrorTest = "C069N64PW4A"; +let pbmirrorTest = "C07ASSJGE2G"; let pbTeam = "T07986PHP2R"; let pbChannel_pb = "C079B7H3AKD"; let pbChannel_pbpb = "C078WH9B44F"; @@ -10,6 +12,8 @@ let pbChannel_pbpb = "C078WH9B44F"; const channels = [ hcChannel_pbip, hcChannel_purplebubble, + hcmirrorTest, + pbmirrorTest, pbChannel_pb, pbChannel_pbpb, ]; @@ -53,6 +57,21 @@ export async function mirror(pbClient, hcClient, message) { let userRealName = profile.real_name!; switch (messageChannel) { + case pbmirrorTest: + blog( + `Message sent #mirrorTest (PB) => #mirrorTest (HC): ${message.text}`, + "info" + ); + + hcClient.chat.postMessage({ + username: userRealName, + icon_url: userpfp, + channel: hcmirrorTest, + text: message.text, + blocks: message.blocks, + }); + + break; case pbChannel_pbpb: blog( `Message sent #pb-pb (PB) => #pbip (HC): ${message.text}`, @@ -98,6 +117,21 @@ export async function mirror(pbClient, hcClient, message) { let userRealName = profile.real_name!; switch (messageChannel) { + case hcmirrorTest: + blog( + `Message sent #mirrorTest (HC) => #mirrorTest (PB): ${message.text}`, + "info" + ); + + pbClient.chat.postMessage({ + username: userRealName, + icon_url: userpfp, + channel: pbmirrorTest, + text: message.text, + blocks: message.blocks, + }); + + break; case hcChannel_purplebubble: blog( `Message sent #purplebubble (HC) => #pb (PB): ${message.text}`, diff --git a/src/index.ts b/src/index.ts index dc68347..b1c79c5 100644 --- a/src/index.ts +++ b/src/index.ts @@ -33,6 +33,9 @@ const HCapp = new SlackApp({ const PBclient: SlackAPIClient = PBapp.client; const HCclient: SlackAPIClient = HCapp.client; +PBapp.anyMessage(async ({ payload, context }) => { + await mirror(PBclient, HCclient, payload); +}); HCapp.anyMessage(async ({ payload, context }) => { await mirror(PBclient, HCclient, payload); }); diff --git a/src/util/Logger.ts b/src/util/Logger.ts index f9e95fe..60ee8c0 100644 --- a/src/util/Logger.ts +++ b/src/util/Logger.ts @@ -6,22 +6,19 @@ import { PBclient } from "../index"; import async from "async"; import Bottleneck from "bottleneck"; import colors from "colors"; +import { ChatPostMessageRequest } from "slack-edge"; // Create a rate limiter with Bottleneck const limiter = new Bottleneck({ minTime: 1000, // 1 second between each request }); -const messageQueue = async.queue(async (task, callback) => { - try { +const messageQueue = async.queue( + async (task: ChatPostMessageRequest, callback) => { await limiter.schedule(() => PBclient.chat.postMessage(task)); - callback(); - } catch (error) { - console.error("Error posting message:", error); - // @ts-ignore - callback(error); - } -}, 1); // Only one worker to ensure order and rate limit + }, + 1 +); // Only one worker to ensure order and rate limit async function slog(logMessage, type) { const message = {