-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils.js
More file actions
62 lines (56 loc) · 1.43 KB
/
utils.js
File metadata and controls
62 lines (56 loc) · 1.43 KB
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
const { CONSTANTS, MESSAGES } = require("./constants");
// 날짜 유틸리티 함수
const getTodayDate = () => {
const today = new Date(
new Date().toLocaleString("en-US", { timeZone: CONSTANTS.TIMEZONE })
);
const yyyy = today.getFullYear();
const mm = String(today.getMonth() + 1).padStart(2, "0");
const dd = String(today.getDate()).padStart(2, "0");
return `${yyyy}-${mm}-${dd}`;
};
// 응답 생성 헬퍼 함수들
const createResponse = (
intentName,
state,
dialogAction,
messages,
slots = null
) => ({
sessionState: {
dialogAction: {
type: dialogAction,
...(dialogAction === CONSTANTS.DIALOG_ACTION.ELICIT_SLOT && {
slotToElicit: CONSTANTS.SLOT_NAMES.MISSING_DATE,
}),
},
intent: {
name: intentName,
state,
...(slots && { slots }),
},
},
messages,
});
const createPlainTextMessage = (content) => ({
contentType: CONSTANTS.MESSAGE_TYPE.PLAIN_TEXT,
content,
});
const createCustomPayloadMessage = (data) => ({
contentType: CONSTANTS.MESSAGE_TYPE.CUSTOM_PAYLOAD,
content: JSON.stringify({ type: "todoList", data }),
});
const createErrorResponse = (intentName, message) =>
createResponse(
intentName,
CONSTANTS.INTENT_STATE.FAILED,
CONSTANTS.DIALOG_ACTION.CLOSE,
[createPlainTextMessage(message)]
);
module.exports = {
getTodayDate,
createResponse,
createPlainTextMessage,
createCustomPayloadMessage,
createErrorResponse,
};