chore(slack): remove dead invite path, archive checkSlackJoins poller
Some checks failed
Test / vitest (push) Successful in 12m6s
Test / playwright (push) Failing after 9m39s
Test / visual (push) Failing after 9m28s
Test / Notify on failure (push) Successful in 2s

Wave-based onboarding makes the auto-invite + polling path obsolete.

- Removes SlackService.inviteUserToSlack — admins now send invites
  through Slack's UI and flip the flag in our admin endpoint.
- Removes the slack_invite_failed admin alert + its detector. The
  alert no longer has a meaningful trigger (we don't attempt invites).
- Archives server/utils/checkSlackJoins.js (and its test) under
  _archive/ in case the polling pattern is needed again post-pilot.
- Deletes the Nitro plugin that scheduled checkSlackJoins on boot
  + hourly. Nothing in nitro.config / nuxt.config / package.json
  registered it elsewhere.
- Drops the slack_invite_failed branch from adminAlerts.test; the
  enum slug stays in adminAlertDismissal so historical dismissal
  rows continue to validate.

notifyNewMember (vetting-channel notification) and findUserByEmail
(used by the auto-flag helper) are retained.
This commit is contained in:
Jennie Robinson Faber 2026-04-29 12:34:21 +01:00
parent 7b326f879d
commit d15458b30a
10 changed files with 247 additions and 197 deletions

View file

@ -17,7 +17,6 @@ export const ALERT_THRESHOLDS = {
// Single source of truth for alert presentation. Used by detectors AND the
// dismissed-list endpoint (which has no access to a detector run's output).
export const ALERT_METADATA = {
slack_invite_failed: { title: 'Slack invites failed', severity: 'critical' },
no_slack_handle_week: { title: 'Active members without a Slack handle', severity: 'attention' },
stuck_pending_payment: { title: 'Members stuck in pending payment', severity: 'attention' },
member_suspended: { title: 'Suspended members', severity: 'attention' },
@ -62,18 +61,6 @@ function memberItem(member, sublabel) {
}
}
export async function detectSlackInviteFailed() {
await connectDB()
const members = await Member
.find({ slackInviteStatus: 'failed' })
.select('name email')
.lean()
return {
...alertShell('slack_invite_failed'),
items: members.map((m) => memberItem(m))
}
}
export async function detectNoSlackHandleAfterWeek() {
await connectDB()
const cutoff = daysAgo(ALERT_THRESHOLDS.NO_SLACK_DAYS)
@ -257,7 +244,6 @@ export async function detectPendingTagSuggestions() {
}
const DETECTORS = [
detectSlackInviteFailed,
detectNoSlackHandleAfterWeek,
detectStuckPendingPayment,
detectSuspendedMembers,

View file

@ -1,59 +0,0 @@
// server/utils/checkSlackJoins.js
import Member from '../models/member.js'
import { connectDB } from './mongoose.js'
import { WebClient } from '@slack/web-api'
const BATCH_SIZE = 15
const BATCH_DELAY_MS = 1000
/**
* Check members with pending Slack invites to see if they've joined the workspace.
* Processes in batches of 15 with 1-second delays (Slack Tier 2 rate limit).
*/
export async function checkSlackJoins(slackBotToken) {
await connectDB()
const client = new WebClient(slackBotToken)
const members = await Member.find({
slackInviteStatus: { $in: ['sent', 'accepted'] }
}).select('_id email slackInviteStatus')
if (members.length === 0) return { checked: 0, joined: 0 }
let joined = 0
for (let i = 0; i < members.length; i += BATCH_SIZE) {
const batch = members.slice(i, i + BATCH_SIZE)
for (const member of batch) {
try {
const response = await client.users.lookupByEmail({ email: member.email })
const userId = response.user?.id
if (userId) {
await Member.findByIdAndUpdate(member._id, {
slackInviteStatus: 'joined',
slackUserId: userId
})
joined++
console.log(`[check-slack-joins] ${member.email} joined Slack (${userId})`)
}
} catch (err) {
// users_not_found is expected for members who haven't joined yet
if (err.data?.error === 'users_not_found') continue
console.error(`[check-slack-joins] Error checking ${member.email}:`, err.message || err)
// Continue processing remaining members
}
}
// Delay between batches (skip after last batch)
if (i + BATCH_SIZE < members.length) {
await new Promise((resolve) => setTimeout(resolve, BATCH_DELAY_MS))
}
}
console.log(`[check-slack-joins] Done: ${joined}/${members.length} members joined`)
return { checked: members.length, joined }
}

View file

@ -9,98 +9,6 @@ export class SlackService {
this.vettingChannelId = vettingChannelId;
}
/**
* Invite user to workspace and channel (using proper admin and conversation scopes)
*/
async inviteUserToSlack(
email: string,
realName: string,
): Promise<{
success: boolean;
userId?: string;
status?: string;
error?: string;
}> {
try {
// First, check if user already exists in workspace
const existingUser = await this.findUserByEmail(email);
if (existingUser) {
// User exists, invite them to the vetting channel
try {
await this.client.conversations.invite({
channel: this.vettingChannelId,
users: existingUser,
});
console.log(
`Successfully invited existing user ${email} to vetting channel`,
);
return {
success: true,
userId: existingUser,
status: "existing_user_added_to_channel",
};
} catch (error: any) {
if (error.data?.error === "already_in_channel") {
return {
success: true,
userId: existingUser,
status: "user_already_in_channel",
};
}
throw error;
}
}
// User doesn't exist, try to invite to workspace using admin API
try {
const inviteResponse = await this.client.admin.users.invite({
email: email,
real_name: realName,
channel_ids: [this.vettingChannelId],
is_restricted: true, // Single-channel guest
is_ultra_restricted: false,
});
if (inviteResponse.ok && inviteResponse.user) {
console.log(
`Successfully invited ${email} to workspace as single-channel guest`,
);
return {
success: true,
userId: inviteResponse.user.id,
status: "new_user_invited_to_workspace",
};
} else {
throw new Error(`Admin invite failed: ${inviteResponse.error}`);
}
} catch (adminError: any) {
console.log(
`Admin API not available or failed: ${
adminError.data?.error || adminError.message
}`,
);
// Fall back to manual process
return {
success: true,
status: "manual_invitation_required",
error: `Admin API unavailable: ${
adminError.data?.error || adminError.message
}`,
};
}
} catch (error: any) {
console.error(`Failed to process invitation for ${email}:`, error);
return {
success: false,
error: error.data?.error || error.message || "Unknown error occurred",
};
}
}
/**
* Find user in workspace by email
*/