From 204515e9538c2da4d0bb2cea6254cb4e64ce03d2 Mon Sep 17 00:00:00 2001 From: Jani Haiko Date: Mon, 9 Sep 2024 19:18:29 +0300 Subject: [PATCH] Clear truncate timeout if the message is deleted --- resources/manifest.yml | 9 +++++++-- src/BotEvents.ts | 16 ++++++++++++++-- 2 files changed, 21 insertions(+), 4 deletions(-) diff --git a/resources/manifest.yml b/resources/manifest.yml index bc1f0c0..b99a063 100644 --- a/resources/manifest.yml +++ b/resources/manifest.yml @@ -30,17 +30,22 @@ features: oauth_config: scopes: bot: - - channels:join - - channels:manage - chat:write - chat:write.public - commands + - metadata.message:read - reactions:write + - channels:join + - channels:manage settings: event_subscriptions: request_url: https://lounasbotti-disec.fly.dev/slack/events bot_events: - app_home_opened + - message_metadata_deleted + metadata_subscriptions: + - app_id: A02EYG04A83 + event_type: lounasbotti_message interactivity: is_enabled: true request_url: https://lounasbotti-disec.fly.dev/slack/events diff --git a/src/BotEvents.ts b/src/BotEvents.ts index d663c1f..a948aff 100644 --- a/src/BotEvents.ts +++ b/src/BotEvents.ts @@ -79,6 +79,16 @@ const initEvents = (app: bolt.App, settings: Settings): void => { }); }); + // No need to try truncating if the message is already deleted + app.event("message_metadata_deleted", async args => { + const tt = truncateTimeouts.find(tt => tt.ts === args.payload.message_ts); + if (tt) { + console.debug(`Message ${args.payload.message_ts} removed? Clearing timeout...`); + clearTimeout(tt.timeout); + truncateTimeouts.splice(truncateTimeouts.indexOf(tt), 1); + } + }); + // Fetch additional if (settings.additionalRestaurants?.length) { app.action({type: "block_actions", action_id: RegExp(`fetchAdditionalRestaurant-(?:${settings.additionalRestaurants.join("|")})`)}, async args => { @@ -255,7 +265,8 @@ const initEvents = (app: bolt.App, settings: Settings): void => { blocks: cachedData.blocks, text: "Lounaslistat", unfurl_links: false, - unfurl_media: false + unfurl_media: false, + metadata: { event_type: "lounasbotti_message", event_payload: {} } }); handleMainTriggerResponse(response, app, settings, channel, cachedData.data, isTomorrowRequest); @@ -266,7 +277,8 @@ const initEvents = (app: bolt.App, settings: Settings): void => { blocks: cachedData.blocks, text: "Lounaslistat", unfurl_links: false, - unfurl_media: false + unfurl_media: false, + metadata: { event_type: "lounasbotti_message", event_payload: {} } }); handleMainTriggerResponse(response, app, settings, response.channel ?? args.payload.channel, cachedData.data, isTomorrowRequest);