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