import { WebClient } from "@slack/web-api"

const options = {}
const web = new WebClient(process.env.SLACK_TOKEN, options)

const SLACK_TOKEN = process.env.SLACK_TOKEN
const SLACK_CHANNEL_ID = process.env.SLACK_CHANNEL_ID

if (!SLACK_TOKEN) {
    throw new Error("Missing SLACK_TOKEN")
}

if (!SLACK_CHANNEL_ID) {
    throw new Error("Missing SLACK_CHANNEL_ID")
}


export const sendSlackMessage = async (message, channel = null) => {
    return new Promise(async (resolve, reject) => {
        const channelId = channel || SLACK_CHANNEL_ID
        try {
            const resp = await web.chat.postMessage({
                text: message,
                channel: channelId,
            })
            return resolve(true)
        } catch (error) {
            return resolve(true)
        }
    })
}
// module.exports = sendSlackMessage;
