mcp-daily-tasks
Version:
MCP para manejar tareas y resúmenes con integración ClickUp.
30 lines (29 loc) • 1.02 kB
JavaScript
import dotenv from 'dotenv';
import { fetchSlackChannels } from "./fetchSlackChannels.js";
dotenv.config();
const SLACK_TOKEN = process.env.SLACK_TOKEN;
const SLACK_API_URL = 'https://slack.com/api';
export async function postSlackMessage(channelName, text) {
const channels = await fetchSlackChannels();
const channel = channels.find((c) => c.name === channelName);
if (!channel)
throw new Error(`Channel ${channelName} not found`);
const response = await fetch(`${SLACK_API_URL}/chat.postMessage`, {
method: 'POST',
headers: {
'Authorization': `Bearer ${SLACK_TOKEN}`,
'Content-Type': 'application/json',
},
body: JSON.stringify({
channel: channel.id,
text,
}),
});
if (!response.ok) {
throw new Error(`HTTP error! status: ${response.status}`);
}
const data = await response.json();
if (!data.ok)
throw new Error(`Slack API error: ${data.error}`);
return data;
}