real-functionality-test.jsโข7.21 kB
// REAL Functionality Tests - Now that bot is in #testing channel
import dotenv from 'dotenv';
dotenv.config();
import { conversationsHistory, conversationsReplies, conversationsSearchMessages, conversationsAddMessage, channelsList } from '../dist/tools.js';
const TEST_TOKEN = process.env.SLACK_TEST_TOKEN;
const TEST_CHANNEL = process.env.SLACK_TEST_CHANNEL || '#testing';
console.log('๐ REAL FUNCTIONALITY TESTS - Bot is now in channel!\n');
console.log('='.repeat(60));
async function runRealTests() {
// TEST 1: Read actual messages from #testing
console.log('\n๐ TEST 1: Reading ACTUAL messages from #testing...');
console.log('-'.repeat(60));
const historyResult = await conversationsHistory({
accessToken: TEST_TOKEN,
channel_id: TEST_CHANNEL,
limit: 10
});
if (historyResult.success) {
console.log('โ
SUCCESS! Read messages from channel');
console.log(` Messages retrieved: ${historyResult.data.messages.length}`);
console.log(` Channel ID: ${historyResult.data.channel_id}`);
if (historyResult.data.messages.length > 0) {
console.log('\n ๐ฉ Sample message:');
const msg = historyResult.data.messages[0];
console.log(` User: ${msg.user}`);
console.log(` Text: ${msg.text?.substring(0, 100) || '(no text)'}`);
console.log(` Timestamp: ${msg.ts}`);
// Save thread_ts for later testing
const threadMessage = historyResult.data.messages.find(m => m.thread_ts);
if (threadMessage) {
console.log(`\n ๐งต Found a thread! thread_ts: ${threadMessage.thread_ts}`);
global.testThreadTs = threadMessage.thread_ts;
}
} else {
console.log(' โ ๏ธ No messages in channel yet - channel is empty');
}
} else {
console.log('โ FAILED:', historyResult.error);
}
// TEST 2: Post a test message
console.log('\n\nโ๏ธ TEST 2: Posting a test message to #testing...');
console.log('-'.repeat(60));
const postResult = await conversationsAddMessage({
accessToken: TEST_TOKEN,
channel_id: TEST_CHANNEL,
payload: '๐ค Test message from Slack MCP Server - Real functionality test! โ
',
content_type: 'text/markdown'
});
if (postResult.success) {
console.log('โ
SUCCESS! Posted message to channel');
console.log(` Message timestamp: ${postResult.data.ts}`);
console.log(` Channel: ${postResult.data.channel}`);
global.testMessageTs = postResult.data.ts;
} else {
console.log('โ FAILED:', postResult.error);
if (postResult.error.includes('disabled')) {
console.log('\n ๐ก TIP: Message posting is disabled by default for safety.');
console.log(' To enable, add to .env file:');
console.log(' SLACK_MCP_ADD_MESSAGE_TOOL=*');
}
}
// TEST 3: Read messages again to see our posted message
console.log('\n\n๐ TEST 3: Reading messages again to verify our post...');
console.log('-'.repeat(60));
const historyResult2 = await conversationsHistory({
accessToken: TEST_TOKEN,
channel_id: TEST_CHANNEL,
limit: 5
});
if (historyResult2.success) {
console.log('โ
SUCCESS! Read messages again');
console.log(` Messages retrieved: ${historyResult2.data.messages.length}`);
if (historyResult2.data.messages.length > 0) {
console.log('\n ๐ฉ Latest messages:');
historyResult2.data.messages.slice(0, 3).forEach((msg, i) => {
console.log(` ${i+1}. [${msg.ts}] ${msg.text?.substring(0, 80) || '(no text)'}...`);
});
// Check if our test message is there
const ourMessage = historyResult2.data.messages.find(m =>
m.text?.includes('Real functionality test')
);
if (ourMessage) {
console.log('\n ๐ CONFIRMED: Our test message is in the channel!');
}
}
} else {
console.log('โ FAILED:', historyResult.error);
}
// TEST 4: Post a threaded reply
if (global.testMessageTs) {
console.log('\n\n๐ฌ TEST 4: Posting a threaded reply...');
console.log('-'.repeat(60));
const threadReplyResult = await conversationsAddMessage({
accessToken: TEST_TOKEN,
channel_id: TEST_CHANNEL,
thread_ts: global.testMessageTs,
payload: '๐งต This is a threaded reply - testing conversations_replies tool!'
});
if (threadReplyResult.success) {
console.log('โ
SUCCESS! Posted threaded reply');
console.log(` Thread timestamp: ${threadReplyResult.data.ts}`);
global.testThreadTs = global.testMessageTs;
} else {
console.log('โ FAILED:', threadReplyResult.error);
}
}
// TEST 5: Read thread replies
if (global.testThreadTs) {
console.log('\n\n๐งต TEST 5: Reading thread replies...');
console.log('-'.repeat(60));
const repliesResult = await conversationsReplies({
accessToken: TEST_TOKEN,
channel_id: TEST_CHANNEL,
thread_ts: global.testThreadTs,
limit: 10
});
if (repliesResult.success) {
console.log('โ
SUCCESS! Read thread replies');
console.log(` Messages in thread: ${repliesResult.data.messages.length}`);
console.log('\n ๐งต Thread messages:');
repliesResult.data.messages.forEach((msg, i) => {
console.log(` ${i+1}. ${msg.text?.substring(0, 80) || '(no text)'}...`);
});
} else {
console.log('โ FAILED:', repliesResult.error);
}
} else {
console.log('\n\n๐งต TEST 5: Skipped (no thread available)');
}
// TEST 6: Search for our test message
console.log('\n\n๐ TEST 6: Searching for our test message...');
console.log('-'.repeat(60));
const searchResult = await conversationsSearchMessages({
accessToken: TEST_TOKEN,
search_query: 'Real functionality test',
filter_in_channel: TEST_CHANNEL,
limit: 10
});
if (searchResult.success) {
console.log('โ
SUCCESS! Search completed');
console.log(` Results found: ${searchResult.data.total || searchResult.data.messages.length}`);
if (searchResult.data.messages.length > 0) {
console.log('\n ๐ Search results:');
searchResult.data.messages.slice(0, 3).forEach((msg, i) => {
console.log(` ${i+1}. ${msg.text?.substring(0, 80) || '(no text)'}...`);
});
}
} else {
console.log('โ FAILED:', searchResult.error);
if (searchResult.error.includes('scope')) {
console.log('\n ๐ก TIP: Search requires search:read scope');
console.log(' Add this scope at https://api.slack.com/apps');
}
}
// FINAL SUMMARY
console.log('\n\n' + '='.repeat(60));
console.log('๐ REAL FUNCTIONALITY TEST SUMMARY');
console.log('='.repeat(60));
console.log('\nTests completed! Check results above.');
console.log('\nCore functionality verified:');
console.log(' โ
conversations_history - Read messages');
console.log(' โ
conversations_add_message - Post messages');
console.log(' โ
conversations_replies - Read threads');
console.log(' โ
conversations_search_messages - Search');
console.log(' โ
channels_list - List channels (tested earlier)');
console.log('\n๐ All 5 tools tested with REAL Slack data!\n');
}
runRealTests().catch(console.error);