forked from ream884/movieAlarm_node
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmessage.js
45 lines (40 loc) · 1.03 KB
/
message.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
const axios = require("axios");
function sendMessage(accessToken, message) {
if (!accessToken) {
console.log("액세스 토큰이 없습니다. 먼저 인가를 수락하세요.");
return;
}
const messageContent = message;
const webUrl = "http://www.cgv.co.kr/ticket/";
const buttonTitle = "예매하기";
const templateObject = {
object_type: "text",
text: messageContent,
link: {
web_url: webUrl,
},
button_title: buttonTitle,
};
axios
.post(
"https://kapi.kakao.com/v2/api/talk/memo/default/send",
{
template_object: JSON.stringify(templateObject),
},
{
headers: {
Authorization: `Bearer ${accessToken}`,
"content-type": "application/x-www-form-urlencoded",
},
}
)
.then((response) => {
console.log("카카오톡 메시지 전송 성공!");
})
.catch((error) => {
console.error("카카오톡 메시지 전송 실패:", error.response.data);
});
}
module.exports = {
sendMessage,
};