check-bot-access.jsā¢2.64 kB
// Check what the bot can actually access
import dotenv from 'dotenv';
dotenv.config();
import { WebClient } from '@slack/web-api';
const TEST_TOKEN = process.env.SLACK_TEST_TOKEN;
const client = new WebClient(TEST_TOKEN);
console.log('š Checking Bot Access and Permissions\n');
console.log('='.repeat(60));
async function checkAccess() {
try {
// Check auth
console.log('\n1. Checking authentication...');
const authTest = await client.auth.test();
console.log('ā
Token is valid!');
console.log(` Bot User ID: ${authTest.user_id}`);
console.log(` Bot Name: ${authTest.user}`);
console.log(` Team: ${authTest.team}`);
// Get bot info
console.log('\n2. Getting bot information...');
const botInfo = await client.bots.info({ bot: authTest.user_id });
console.log(` Bot Name: ${botInfo.bot.name}`);
console.log(` App ID: ${botInfo.bot.app_id}`);
// List conversations the bot is in
console.log('\n3. Checking channels bot is a member of...');
const conversations = await client.users.conversations({
types: 'public_channel,private_channel',
limit: 100
});
if (conversations.channels.length > 0) {
console.log(`ā
Bot is a member of ${conversations.channels.length} channels:`);
conversations.channels.forEach(ch => {
console.log(` - #${ch.name} (${ch.id})`);
});
} else {
console.log('ā ļø Bot is NOT a member of any channels!');
console.log('\n To add bot to #testing:');
console.log(' 1. Go to #testing in Slack');
console.log(' 2. Click channel name ā Integrations tab');
console.log(' 3. Click "Add apps"');
console.log(` 4. Search for "${authTest.user}" and add it`);
}
// Try to find #testing channel
console.log('\n4. Looking for #testing channel...');
const allChannels = await client.conversations.list({
types: 'public_channel,private_channel',
limit: 200
});
const testingChannel = allChannels.channels.find(ch => ch.name === 'testing');
if (testingChannel) {
console.log(`ā
Found #testing channel: ${testingChannel.id}`);
console.log(` Members: ${testingChannel.num_members}`);
console.log(` Is member: ${testingChannel.is_member ? 'YES ā
' : 'NO ā'}`);
if (!testingChannel.is_member) {
console.log('\n ā ļø Bot sees the channel but is NOT a member!');
console.log(` Add the bot "${authTest.user}" to #testing channel.`);
}
}
} catch (error) {
console.error('ā Error:', error.data?.error || error.message);
}
}
checkAccess();