讓 Bot 傳送訊息到 Private Channel
const { WebClient } = require("@slack/web-api");
const options = {};
const web = new WebClient(
"Bot User OAuth Token",
options
);
const sendSlackMessage = async (message, channel = null) => {
const channelId = "Channel Id";
return new Promise(async (resolve, reject) => {
try {
const resp = await web.chat.postMessage({
text: message,
channel: channelId,
});
return resolve(true);
} catch (error) {
return resolve(true);
}
});
};
const sendMessage = async (message) => {
const resp = await sendSlackMessage(message);
console.log(resp); // true
};
sendMessage("Test App 123");