// Test message posting - both channel and thread
import dotenv from 'dotenv';
dotenv.config();
import { conversationsHistory, conversationsAddMessage, conversationsReplies } from '../dist/tools.js';
const TEST_TOKEN = process.env.SLACK_TEST_TOKEN;
const TEST_CHANNEL = process.env.SLACK_TEST_CHANNEL || '#testing';
console.log('βοΈ TESTING MESSAGE POSTING');
console.log('='.repeat(60));
async function testPosting() {
// TEST 1: Post a message to the channel
console.log('\nπ TEST 1: Posting message to channel...');
console.log('-'.repeat(60));
const channelPostResult = await conversationsAddMessage({
accessToken: TEST_TOKEN,
channel_id: TEST_CHANNEL,
payload: 'π€ Test message from Slack MCP Server!\n\nThis proves the server can POST to channels. β
',
content_type: 'text/markdown'
});
if (channelPostResult.success) {
console.log('β
SUCCESS! Posted message to channel');
console.log(` Channel: ${channelPostResult.data.channel}`);
console.log(` Message timestamp: ${channelPostResult.data.ts}`);
console.log(` Message text: ${channelPostResult.data.message.text}`);
// Save timestamp for thread test
global.testMessageTs = channelPostResult.data.ts;
console.log('\n π VERIFIED: Can post to channels!');
} else {
console.log('β FAILED:', channelPostResult.error);
return;
}
// Wait a moment
await new Promise(resolve => setTimeout(resolve, 1000));
// TEST 2: Post a threaded reply
if (global.testMessageTs) {
console.log('\n\n㪠TEST 2: Posting threaded reply...');
console.log('-'.repeat(60));
const threadPostResult = await conversationsAddMessage({
accessToken: TEST_TOKEN,
channel_id: TEST_CHANNEL,
thread_ts: global.testMessageTs,
payload: 'π§΅ This is a threaded reply!\n\nThis proves the server can POST to threads. β
'
});
if (threadPostResult.success) {
console.log('β
SUCCESS! Posted threaded reply');
console.log(` Thread timestamp: ${threadPostResult.data.ts}`);
console.log(` Parent message: ${global.testMessageTs}`);
console.log(` Reply text: ${threadPostResult.data.message.text}`);
console.log('\n π VERIFIED: Can post to threads!');
} else {
console.log('β FAILED:', threadPostResult.error);
}
}
// Wait a moment
await new Promise(resolve => setTimeout(resolve, 1000));
// TEST 3: Verify messages are actually there by reading them back
console.log('\n\nπ TEST 3: Reading back messages to verify...');
console.log('-'.repeat(60));
const readResult = await conversationsHistory({
accessToken: TEST_TOKEN,
channel_id: TEST_CHANNEL,
limit: 5
});
if (readResult.success) {
console.log('β
Read messages from channel');
console.log(` Total messages: ${readResult.data.messages.length}`);
// Find our test message
const ourMessage = readResult.data.messages.find(m =>
m.text?.includes('Test message from Slack MCP Server')
);
if (ourMessage) {
console.log('\n β
CONFIRMED: Our channel message is there!');
console.log(` Timestamp: ${ourMessage.ts}`);
console.log(` Text: ${ourMessage.text?.substring(0, 50)}...`);
}
}
// TEST 4: Read the thread to verify threaded reply
if (global.testMessageTs) {
console.log('\n\nπ§΅ TEST 4: Reading thread to verify reply...');
console.log('-'.repeat(60));
const threadReadResult = await conversationsReplies({
accessToken: TEST_TOKEN,
channel_id: TEST_CHANNEL,
thread_ts: global.testMessageTs,
limit: 10
});
if (threadReadResult.success) {
console.log('β
Read thread messages');
console.log(` Messages in thread: ${threadReadResult.data.messages.length}`);
console.log('\n Thread contents:');
threadReadResult.data.messages.forEach((msg, i) => {
const preview = msg.text?.substring(0, 60) || '(no text)';
console.log(` ${i+1}. ${preview}...`);
});
// Find our threaded reply
const ourReply = threadReadResult.data.messages.find(m =>
m.text?.includes('This is a threaded reply')
);
if (ourReply) {
console.log('\n β
CONFIRMED: Our threaded reply is there!');
}
}
}
// FINAL SUMMARY
console.log('\n\n' + '='.repeat(60));
console.log('π MESSAGE POSTING TEST SUMMARY');
console.log('='.repeat(60));
console.log('\nβ
VERIFIED CAPABILITIES:');
console.log(' 1. β
Post messages to channels');
console.log(' 2. β
Post threaded replies');
console.log(' 3. β
Messages are actually posted (verified by reading back)');
console.log('\nπ conversations_add_message tool is FULLY FUNCTIONAL!\n');
}
testPosting().catch(console.error);