75 lines
2.1 KiB
JavaScript
Executable File
75 lines
2.1 KiB
JavaScript
Executable File
const express = require("express");
|
|
|
|
const app = express();
|
|
app.use(express.json());
|
|
|
|
app.post("/kakao/skill", (req, res) => {
|
|
console.log("==== KAKAO REQUEST START ====");
|
|
console.log(JSON.stringify(req.body, null, 2));
|
|
console.log("==== KAKAO REQUEST END ====");
|
|
|
|
const utterance = (req.body?.userRequest?.utterance || "").trim();
|
|
const blockName =
|
|
req.body?.userRequest?.block?.name ||
|
|
req.body?.contexts?.[0]?.name ||
|
|
"";
|
|
|
|
let response;
|
|
|
|
if (blockName === "지역입력") {
|
|
response = {
|
|
version: "2.0",
|
|
template: {
|
|
outputs: [
|
|
{
|
|
simpleText: {
|
|
text: "여자에요? (예: 네/아니요)"
|
|
}
|
|
}
|
|
]
|
|
}
|
|
};
|
|
} else if (blockName === "성별확인") {
|
|
const genderAnswer = utterance;
|
|
const isFemale = genderAnswer === "네";
|
|
|
|
response = {
|
|
version: "2.0",
|
|
template: {
|
|
outputs: [
|
|
{
|
|
simpleText: {
|
|
text: isFemale
|
|
? "오늘 날씨 알려줄게요. 내일부터 아침 6시 30분에 잔망스럽게 보내드릴게요 💛"
|
|
: "오늘 날씨를 안내합니다. 내일부터 아침 6시 30분에 차가운 말투로 보내드리겠습니다."
|
|
}
|
|
}
|
|
]
|
|
}
|
|
};
|
|
} else {
|
|
response = {
|
|
version: "2.0",
|
|
template: {
|
|
outputs: [
|
|
{
|
|
simpleText: {
|
|
text: "지역을 입력해주세요. 예: 서울 강남 / 충북 청주"
|
|
}
|
|
}
|
|
]
|
|
}
|
|
};
|
|
}
|
|
|
|
return res.json(response);
|
|
});
|
|
|
|
app.get("/health", (req, res) => {
|
|
return res.status(200).send("ok");
|
|
});
|
|
|
|
const PORT = 3000;
|
|
app.listen(PORT, () => {
|
|
console.log(`weather-api listening on port ${PORT}`);
|
|
}); |