← back to Claude Slack

probe.js

28 lines

'use strict';
// READ-ONLY diagnostic: can the bot authenticate, READ history, and is it a
// member of each configured channel? Surfaces the exact missing scope / missing
// invite so the go-live blockers are unambiguous. Run:
//   node --env-file=.env probe.js
const { cfg, api } = require('./lib');

(async () => {
  if (!cfg.token) { console.log('SLACK_BOT_TOKEN: MISSING'); process.exit(1); }
  let botId = '';
  try { const a = await api.authTest(); botId = a.user_id; console.log(`auth.test: OK — bot @${a.user} (${a.user_id}) team ${a.team}`); }
  catch (e) { console.log('auth.test: FAIL —', e.message); process.exit(1); }

  if (!cfg.channels.length) { console.log('SLACK_CHANNELS: empty'); process.exit(1); }
  for (const ch of cfg.channels) {
    try {
      const r = await api.history(ch.id, undefined, 1);
      console.log(`[${ch.key}] ${ch.id} read history: OK (${(r.messages || []).length} msg sampled, requireMention=${!!ch.requireMention})`);
    } catch (e) {
      let hint = '';
      if (e.slackError === 'missing_scope') hint = `  → ADD SCOPE: ${e.needed} (reinstall app)`;
      else if (e.slackError === 'not_in_channel') hint = `  → INVITE the bot: /invite @bot in that channel`;
      else if (e.slackError === 'channel_not_found') hint = '  → wrong channel id, or private + bot not a member';
      console.log(`[${ch.key}] ${ch.id} read history: FAIL — ${e.slackError || e.message}${hint}`);
    }
  }
})();