어제
const { WebClient, LogLevel } = require("@slack/web-api");
const client = new WebClient(process.env.SLACK_BOT_API, {
logLevel: LogLevel.DEBUG,
});
const channelId = process.env.SLACK_CHANNEL;
exports.slack = async (message) => {
try {
const result = await client.chat.postMessage({
channel: channelId,
text: message,
});
console.log(result);
} catch (error) {
console.error(error);
}
};
이렇게 모듈화 해놓고
await slack.slack("제목");
await slack.slack("내용");
이런식으로 사용했었는데
두 줄로 써야하는 불편함과
await 때문에 렉이 좀 있길래
const { WebClient, LogLevel } = require("@slack/web-api");
const client = new WebClient(process.env.SLACK_BOT_API, {
logLevel: LogLevel.DEBUG,
});
const channelId = process.env.SLACK_CHANNEL;
exports.slack = async (title, message) => {
let text = "";
message !== undefined
? (text = `${title}
${message}`)
: (text = title);
try {
const result = await client.chat.postMessage({
channel: channelId,
text: text,
});
// console.log(result);
} catch (error) {
console.error(error);
}
};
await slack.slack("Diary Delete 200", `id : ${id}`);
이런식으로 바꿔줬다 (await은 혹시 몰라 안빼줌....)
에러응답류는 데이터를 안보내므로 message가 비어있는데
조건문을 안걸면 슬렉상에서 undefined가 걸려있다
그리고 프론트의 다이어리 태그추가하는 부분을 도왔다
'Project > codestates-final-project' 카테고리의 다른 글
10일차 / n : m 연결 고민 미완이라 내일도 할 예정 (0) | 2022.05.03 |
---|---|
9일차 / 요청에 대한 응답 더욱 더 세분화 (0) | 2022.05.01 |
7일차 / Slack Bot (0) | 2022.04.28 |
6일차 / API fix, postman 자동화 (0) | 2022.04.26 |
5일차 / postman자동화(미완), refreshToken (0) | 2022.04.25 |