From 6aa975eb69d068c3a938aa87b89e6a585b71abd3 Mon Sep 17 00:00:00 2001 From: Ryan Hoofard <42755382+rhoofard@users.noreply.github.com> Date: Wed, 21 Jun 2023 09:14:54 -0700 Subject: [PATCH] feat: added auto-join functionality, #205 (#375) * added auto-join functionality, updated manifest * fix: ran linter --------- Co-authored-by: rhoofard --- features/join.js | 21 +++++++++++++++++++++ slack_app_manifest.yml | 2 ++ 2 files changed, 23 insertions(+) create mode 100644 features/join.js diff --git a/features/join.js b/features/join.js new file mode 100644 index 00000000..c73345a2 --- /dev/null +++ b/features/join.js @@ -0,0 +1,21 @@ +const { SlackError } = require("../service/errors"); +const { + handleSlackError, + handleGenericError, +} = require("../service/messageutils"); + +module.exports = function (app) { + app.event("channel_created", joinPublicChannel); +}; + +async function joinPublicChannel({ event, client }) { + try { + client.conversations.join({ channel: event.channel.id }); + } catch (e) { + if (e instanceof SlackError) { + return handleSlackError(client, event, e); + } else { + return handleGenericError(client, event, e); + } + } +} diff --git a/slack_app_manifest.yml b/slack_app_manifest.yml index e4ff36fc..80083da9 100644 --- a/slack_app_manifest.yml +++ b/slack_app_manifest.yml @@ -19,6 +19,7 @@ oauth_config: - app_mentions:read - channels:history - channels:read + - channels:join - chat:write - groups:history - groups:read @@ -36,6 +37,7 @@ settings: event_subscriptions: bot_events: - app_mention + - channel_created - message.channels - message.groups - message.im