Merge branch 'feature/line-bot-refactor' into 'main'
Feature/line bot refactor minor 기능 구현 (UX) 및 코드 수정 See merge request !23
Showing
7 changed files
with
263 additions
and
247 deletions
1 | -const setKeywordsFlexMessage = require("../message/setKeywordsFlexMessage") | 1 | +const setKeywordsFlexMessage = require("../message/setKeywordsFlexMessage"); |
2 | 2 | ||
3 | const db = require("../../apis/database"); | 3 | const db = require("../../apis/database"); |
4 | 4 | ||
5 | const checkKeywords = (client, event) => { | 5 | const checkKeywords = (client, event) => { |
6 | - db.getKeywordsByUserId(event.source.userId).then((keywords) => { | 6 | + db.getKeywordsByUserId(event.source.userId).then((keywords) => { |
7 | - flexMessage = setKeywordsFlexMessage(keywords); | 7 | + flexMessage = setKeywordsFlexMessage(keywords); |
8 | - client.replyMessage(event.replyToken, flexMessage) | 8 | + client.pushMessage(event.source.userId, flexMessage); |
9 | - }) | 9 | + }); |
10 | }; | 10 | }; |
11 | 11 | ||
12 | -module.exports = { checkKeywords }; | ||
... | \ No newline at end of file | ... | \ No newline at end of file |
12 | +module.exports = { checkKeywords }; | ... | ... |
1 | const { marketMultiSearch } = require("../search/marketSearch"); | 1 | const { marketMultiSearch } = require("../search/marketSearch"); |
2 | const setCarouselMessage = require("../message/setCarouselMessage"); | 2 | const setCarouselMessage = require("../message/setCarouselMessage"); |
3 | + | ||
3 | // Database APIs | 4 | // Database APIs |
4 | const db = require("../../apis/database"); | 5 | const db = require("../../apis/database"); |
5 | -// API List | ||
6 | -// database.addKeyword = async function(keyword, userId) | ||
7 | -// database.deleteKeyword = async function(userId, keyword) | ||
8 | -// database.getKeywordsByUserId = async function(userId) | ||
9 | -// database.getUsersByKeyword = async function(keyword) | ||
10 | -// database.getAllUsers = async function() | ||
11 | -// database.getAllKeywords = async function() | ||
12 | 6 | ||
13 | const multiCheckMamul = (client) => { | 7 | const multiCheckMamul = (client) => { |
14 | db.getAllKeywords().then((keywords) => { | 8 | db.getAllKeywords().then((keywords) => { |
15 | for (let i = 0, pending = Promise.resolve(); i < keywords.length; i++) { | 9 | for (let i = 0, pending = Promise.resolve(); i < keywords.length; i++) { |
16 | pending = db.getUsersByKeyword(keywords[i]).then((userIds) => { | 10 | pending = db.getUsersByKeyword(keywords[i]).then((userIds) => { |
17 | marketMultiSearch(keywords[i]).then((res) => { | 11 | marketMultiSearch(keywords[i]).then((res) => { |
18 | - client.multicast(userIds, [setCarouselMessage(res)]); | 12 | + client.multicast(userIds, [setCarouselMessage(res, keywords[i])]); |
19 | }); | 13 | }); |
20 | }); | 14 | }); |
21 | } | 15 | } |
... | @@ -24,11 +18,11 @@ const multiCheckMamul = (client) => { | ... | @@ -24,11 +18,11 @@ const multiCheckMamul = (client) => { |
24 | 18 | ||
25 | const checkMamul = (client, userId) => { | 19 | const checkMamul = (client, userId) => { |
26 | db.getKeywordsByUserId(userId).then((keywords) => { | 20 | db.getKeywordsByUserId(userId).then((keywords) => { |
27 | - for (let i = 0, pending = Promise.resolve(); i< keywords.length; i++) { | 21 | + for (let i = 0, pending = Promise.resolve(); i < keywords.length; i++) { |
28 | pending = marketMultiSearch(keywords[i]).then((res) => { | 22 | pending = marketMultiSearch(keywords[i]).then((res) => { |
29 | - client.pushMessage(userId, setCarouselMessage(res)); | 23 | + client.pushMessage(userId, setCarouselMessage(res, keywords[i])); |
30 | }); | 24 | }); |
31 | - }; | 25 | + } |
32 | }); | 26 | }); |
33 | }; | 27 | }; |
34 | 28 | ... | ... |
1 | // Line chatbot + Message generate functions | 1 | // Line chatbot + Message generate functions |
2 | const line = require("@line/bot-sdk"); | 2 | const line = require("@line/bot-sdk"); |
3 | -const setFlexMessage = require("./message/setFlexMessage"); | ||
4 | const setCarouselMessage = require("./message/setCarouselMessage"); | 3 | const setCarouselMessage = require("./message/setCarouselMessage"); |
5 | -const setKeywordsFlexMessage = require("./message/setKeywordsFlexMessage") | ||
6 | 4 | ||
7 | // Market Search | 5 | // Market Search |
8 | -const { daangnSingleSearch } = require("./search/daangnSearch"); | ||
9 | -const { daangnMultiSearch } = require("./search/daangnSearch"); | ||
10 | -const { joongnaSingleSearch } = require("./search/joongnaSearch"); | ||
11 | -const { joongnaMultiSearch } = require("./search/joongnaSearch"); | ||
12 | -const { bunjangSingleSearch } = require("./search/bunjangSearch"); | ||
13 | -const { bunjangMultiSearch } = require("./search/bunjangSearch"); | ||
14 | const { marketMultiSearch } = require("./search/marketSearch"); | 6 | const { marketMultiSearch } = require("./search/marketSearch"); |
15 | 7 | ||
16 | -// File search - Will be deleted (Unused) | 8 | +// File search |
17 | const fs = require("fs"); | 9 | const fs = require("fs"); |
18 | 10 | ||
19 | // Cron for Mamul Notification | 11 | // Cron for Mamul Notification |
20 | const schedule = require("node-schedule"); | 12 | const schedule = require("node-schedule"); |
21 | const job = schedule.scheduleJob("0 */1 * * *", () => { | 13 | const job = schedule.scheduleJob("0 */1 * * *", () => { |
22 | - multiCheckMamul(client); | 14 | + multiCheckMamul(client); |
23 | }); | 15 | }); |
24 | 16 | ||
25 | // Database APIs | 17 | // Database APIs |
26 | const db = require("../apis/database"); | 18 | const db = require("../apis/database"); |
27 | -// API List | ||
28 | -// database.addKeyword = async function(keyword, userId) | ||
29 | -// database.deleteKeyword = async function(userId, keyword) | ||
30 | -// database.getKeywordsByUserId = async function(userId) | ||
31 | -// database.getUsersByKeyword = async function(keyword) | ||
32 | -// database.getAllUsers = async function() | ||
33 | -// database.getAllKeywords = async function() | ||
34 | 19 | ||
35 | // Import credentials for Line chatbot | 20 | // Import credentials for Line chatbot |
36 | require("dotenv").config({ path: __dirname + "/../config/.env" }); | 21 | require("dotenv").config({ path: __dirname + "/../config/.env" }); |
... | @@ -41,8 +26,7 @@ const config = { | ... | @@ -41,8 +26,7 @@ const config = { |
41 | 26 | ||
42 | // Cron for Mamul Notification | 27 | // Cron for Mamul Notification |
43 | const { multiCheckMamul, checkMamul } = require("./check/checkMamul"); | 28 | const { multiCheckMamul, checkMamul } = require("./check/checkMamul"); |
44 | -const { checkKeywords } = require("./check/checkKeywords") | 29 | +const { checkKeywords } = require("./check/checkKeywords"); |
45 | - | ||
46 | 30 | ||
47 | // Line chat bot client & event | 31 | // Line chat bot client & event |
48 | const client = new line.Client(config); | 32 | const client = new line.Client(config); |
... | @@ -74,25 +58,21 @@ function handleEvent(event) { | ... | @@ -74,25 +58,21 @@ function handleEvent(event) { |
74 | ); | 58 | ); |
75 | } | 59 | } |
76 | } else if (event.postback.data == "checkItems") { | 60 | } else if (event.postback.data == "checkItems") { |
77 | - return Promise.resolve( | 61 | + return Promise.resolve(checkMamul(client, event.source.userId)); |
78 | - checkMamul(client, event.source.userId), | ||
79 | - ); | ||
80 | } else if (event.postback.data == "deleteKeyword") { | 62 | } else if (event.postback.data == "deleteKeyword") { |
81 | - var foundDelete = waitDeleteMamulList.indexOf(event.source.userId); | 63 | + var foundDelete = waitDeleteMamulList.indexOf(event.source.userId); |
82 | - if (foundDelete == -1) { | 64 | + if (foundDelete == -1) { |
83 | - waitDeleteMamulList.push(event.source.userId); | 65 | + waitDeleteMamulList.push(event.source.userId); |
84 | - console.log(`waitDeleteMamulList Changed : ${waitDeleteMamulList}`); | 66 | + console.log(`waitDeleteMamulList Changed : ${waitDeleteMamulList}`); |
85 | - return Promise.resolve( | ||
86 | - client.replyMessage(event.replyToken, { | ||
87 | - type: "text", | ||
88 | - text: "삭제할 매물 키워드를 알려주세요!", | ||
89 | - }) | ||
90 | - ); | ||
91 | - } | ||
92 | - } else if (event.postback.data == "checkKeywords") { | ||
93 | return Promise.resolve( | 67 | return Promise.resolve( |
94 | - checkKeywords(client, event) | 68 | + client.replyMessage(event.replyToken, { |
95 | - ) | 69 | + type: "text", |
70 | + text: "삭제할 매물 키워드를 알려주세요!", | ||
71 | + }) | ||
72 | + ); | ||
73 | + } | ||
74 | + } else if (event.postback.data == "checkKeywords") { | ||
75 | + return Promise.resolve(checkKeywords(client, event)); | ||
96 | } | 76 | } |
97 | } | 77 | } |
98 | return Promise.resolve(null); | 78 | return Promise.resolve(null); |
... | @@ -110,22 +90,29 @@ function handleEvent(event) { | ... | @@ -110,22 +90,29 @@ function handleEvent(event) { |
110 | text: `매물이 등록되었습니다!\n등록된 매물: ${event.message.text}`, | 90 | text: `매물이 등록되었습니다!\n등록된 매물: ${event.message.text}`, |
111 | }), | 91 | }), |
112 | marketMultiSearch(event.message.text).then((res) => { | 92 | marketMultiSearch(event.message.text).then((res) => { |
113 | - client.pushMessage(event.source.userId, setCarouselMessage(res)); | 93 | + client.pushMessage( |
94 | + event.source.userId, | ||
95 | + setCarouselMessage(res, event.message.text) | ||
96 | + ); | ||
114 | }) | 97 | }) |
115 | ); | 98 | ); |
116 | } | 99 | } |
117 | 100 | ||
118 | var foundDelete = waitDeleteMamulList.indexOf(event.source.userId); | 101 | var foundDelete = waitDeleteMamulList.indexOf(event.source.userId); |
119 | if (foundDelete != -1) { | 102 | if (foundDelete != -1) { |
120 | - waitDeleteMamulList.splice(foundDelete, 1); | 103 | + waitDeleteMamulList.splice(foundDelete, 1); |
121 | - console.log(waitDeleteMamulList[foundDelete]); | 104 | + console.log(waitDeleteMamulList[foundDelete]); |
122 | - return Promise.resolve( | 105 | + return Promise.resolve( |
123 | - db.deleteKeyword(event.source.userId, event.message.text), | 106 | + db.deleteKeyword(event.source.userId, event.message.text), |
124 | - client.replyMessage(event.replyToken, { | 107 | + client |
125 | - type: "text", | 108 | + .replyMessage(event.replyToken, { |
126 | - text: `매물이 삭제되었습니다!\n삭제된 매물: ${event.message.text}`, | 109 | + type: "text", |
127 | - }) | 110 | + text: `매물이 삭제되었습니다!\n삭제된 매물: ${event.message.text}`, |
128 | - ) | 111 | + }) |
112 | + .then(() => { | ||
113 | + checkKeywords(client, event); | ||
114 | + }) | ||
115 | + ); | ||
129 | } | 116 | } |
130 | } | 117 | } |
131 | } | 118 | } |
... | @@ -181,83 +168,82 @@ module.exports = { handleEvent, config }; | ... | @@ -181,83 +168,82 @@ module.exports = { handleEvent, config }; |
181 | 168 | ||
182 | /*리치메뉴 설정*/ | 169 | /*리치메뉴 설정*/ |
183 | // let richMenu = { | 170 | // let richMenu = { |
184 | -// size: { | 171 | +// size: { |
185 | -// width: 2006, | 172 | +// width: 2006, |
186 | -// height: 827, | 173 | +// height: 827, |
174 | +// }, | ||
175 | +// selected: false, | ||
176 | +// name: "Real richMenu", | ||
177 | +// chatBarText: "메뉴 열기", | ||
178 | +// areas: [ | ||
179 | +// { | ||
180 | +// bounds: { | ||
181 | +// x: 0, | ||
182 | +// y: 0, | ||
183 | +// width: 1003, | ||
184 | +// height: 413, | ||
185 | +// }, | ||
186 | +// action: { | ||
187 | +// type: "postback", | ||
188 | +// label: "newKeyword", | ||
189 | +// data: "newKeyword", | ||
190 | +// displayText: "키워드 추가", | ||
191 | +// inputOption: "openKeyboard", | ||
192 | +// fillInText: "", | ||
193 | +// }, | ||
187 | // }, | 194 | // }, |
188 | -// selected: false, | 195 | +// { |
189 | -// name: "Real richMenu", | 196 | +// bounds: { |
190 | -// chatBarText: "메뉴 열기", | 197 | +// x: 1003, |
191 | -// areas: [ | 198 | +// y: 0, |
192 | -// { | 199 | +// width: 1003, |
193 | -// bounds: { | 200 | +// height: 413, |
194 | -// x: 0, | 201 | +// }, |
195 | -// y: 0, | 202 | +// action: { |
196 | -// width: 1003, | 203 | +// type: "postback", |
197 | -// height: 413, | 204 | +// label: "deleteKeyword", |
198 | -// }, | 205 | +// data: "deleteKeyword", |
199 | -// action: { | 206 | +// displayText: "키워드 삭제", |
200 | -// type: "postback", | 207 | +// inputOption: "openKeyboard", |
201 | -// label: "newKeyword", | 208 | +// fillInText: "", |
202 | -// data: "newKeyword", | 209 | +// }, |
203 | -// displayText: "키워드 추가", | 210 | +// }, |
204 | -// inputOption: "openKeyboard", | 211 | +// { |
205 | -// fillInText: "", | 212 | +// bounds: { |
206 | -// }, | 213 | +// x: 0, |
207 | -// }, | 214 | +// y: 413, |
208 | -// { | 215 | +// width: 1003, |
209 | -// bounds: { | 216 | +// height: 414, |
210 | -// x: 1003, | 217 | +// }, |
211 | -// y: 0, | 218 | +// action: { |
212 | -// width: 1003, | 219 | +// type: "postback", |
213 | -// height: 413, | 220 | +// label: "checkKeywords", |
214 | -// }, | 221 | +// data: "checkKeywords", |
215 | -// action: { | 222 | +// displayText: "키워드 확인", |
216 | -// type: "postback", | 223 | +// }, |
217 | -// label: "deleteKeyword", | 224 | +// }, |
218 | -// data: "deleteKeyword", | 225 | +// { |
219 | -// displayText: "키워드 삭제", | 226 | +// bounds: { |
220 | -// inputOption: "openKeyboard", | 227 | +// x: 1003, |
221 | -// fillInText: "", | 228 | +// y: 413, |
222 | -// }, | 229 | +// width: 1003, |
223 | -// }, | 230 | +// height: 414, |
224 | -// { | 231 | +// }, |
225 | -// bounds: { | 232 | +// action: { |
226 | -// x: 0, | 233 | +// type: "postback", |
227 | -// y: 413, | 234 | +// label: "checkItems", |
228 | -// width: 1003, | 235 | +// data: "checkItems", |
229 | -// height: 414, | 236 | +// displayText: "매물 즉시 검색", |
230 | -// }, | 237 | +// }, |
231 | -// action: { | 238 | +// }, |
232 | -// type: "postback", | 239 | +// ], |
233 | -// label: "checkKeywords", | ||
234 | -// data: "checkKeywords", | ||
235 | -// displayText: "키워드 확인", | ||
236 | -// }, | ||
237 | -// }, | ||
238 | -// { | ||
239 | -// bounds: { | ||
240 | -// x: 1003, | ||
241 | -// y: 413, | ||
242 | -// width: 1003, | ||
243 | -// height: 414, | ||
244 | -// }, | ||
245 | -// action: { | ||
246 | -// type: "postback", | ||
247 | -// label: "checkItems", | ||
248 | -// data: "checkItems", | ||
249 | -// displayText: "매물 즉시 검색", | ||
250 | -// }, | ||
251 | -// }, | ||
252 | -// ], | ||
253 | // }; | 240 | // }; |
254 | // 등록 | 241 | // 등록 |
255 | // client.createRichMenu(richMenu).then((richMenuId) => { | 242 | // client.createRichMenu(richMenu).then((richMenuId) => { |
256 | -// console.log(richMenuId) | 243 | +// console.log(richMenuId); |
257 | // }); | 244 | // }); |
258 | // client.setRichMenuImage( | 245 | // client.setRichMenuImage( |
259 | -// "richmenu-ab4bba1c3c9235be50e3e8924fabd940", | 246 | +// "richmenu-de8d05638cd98d81e765576986376314", |
260 | -// fs.createReadStream("./static/image/richMenu.png") | 247 | +// fs.createReadStream("./static/image/richMenu.png") |
261 | -// ); | 248 | +// ); |
262 | -// client.setDefaultRichMenu("richmenu-ab4bba1c3c9235be50e3e8924fabd940"); | 249 | +// client.setDefaultRichMenu("richmenu-de8d05638cd98d81e765576986376314"); |
263 | -// | ... | ... |
1 | const setFlexMessage = require("./setFlexMessage"); | 1 | const setFlexMessage = require("./setFlexMessage"); |
2 | 2 | ||
3 | -function setCarouselMessage(mamuls) { | 3 | +function setCarouselMessage(mamuls, keyword) { |
4 | let flexMessages = []; | 4 | let flexMessages = []; |
5 | let flexMessage = {}; | 5 | let flexMessage = {}; |
6 | - if ( | 6 | + if (mamuls[0] == undefined) { |
7 | - mamuls[0] == undefined && | ||
8 | - mamuls[1] == undefined && | ||
9 | - mamuls[2] == undefined | ||
10 | - ) { | ||
11 | let nonMamulMessage = { | 7 | let nonMamulMessage = { |
12 | type: "flex", | 8 | type: "flex", |
13 | - altText: "매물 검색 에러", | 9 | + altText: `${keyword} 매물은 아직 없어요!`, |
14 | contents: setFlexMessage( | 10 | contents: setFlexMessage( |
15 | "-", | 11 | "-", |
16 | "매물이 없습니다!", | 12 | "매물이 없습니다!", |
... | @@ -20,6 +16,20 @@ function setCarouselMessage(mamuls) { | ... | @@ -20,6 +16,20 @@ function setCarouselMessage(mamuls) { |
20 | "-" | 16 | "-" |
21 | ), | 17 | ), |
22 | }; | 18 | }; |
19 | + nonMamulMessage["contents"]["header"] = { | ||
20 | + type: "box", | ||
21 | + layout: "horizontal", | ||
22 | + contents: [ | ||
23 | + { type: "text", text: "매무리 봇", size: "sm", color: "#1DB446" }, | ||
24 | + { | ||
25 | + type: "text", | ||
26 | + text: `키워드: ${keyword}`, | ||
27 | + align: "end", | ||
28 | + color: "#1DB446", | ||
29 | + weight: "bold", | ||
30 | + }, | ||
31 | + ], | ||
32 | + }; | ||
23 | return nonMamulMessage; | 33 | return nonMamulMessage; |
24 | } | 34 | } |
25 | for (i = 0; i < mamuls.length; i++) { | 35 | for (i = 0; i < mamuls.length; i++) { |
... | @@ -51,9 +61,48 @@ function setCarouselMessage(mamuls) { | ... | @@ -51,9 +61,48 @@ function setCarouselMessage(mamuls) { |
51 | 61 | ||
52 | if (mamuls[i]["extraInfo"] == undefined || mamuls[i]["extraInfo"] == "") { | 62 | if (mamuls[i]["extraInfo"] == undefined || mamuls[i]["extraInfo"] == "") { |
53 | mamuls[i]["extraInfo"] = "없음"; | 63 | mamuls[i]["extraInfo"] = "없음"; |
54 | - } else if (mamuls[i]["extraInfo"].length > 150) { | 64 | + } else { |
55 | - mamuls[i]["extraInfo"] = mamuls[i]["extraInfo"].slice(0, 150) + "\n..."; | 65 | + if ( |
66 | + mamuls[i]["platform"] === "joongna" || | ||
67 | + mamuls[i]["platform"] === "중고나라" | ||
68 | + ) { | ||
69 | + let searchDot = mamuls[i]["extraInfo"].indexOf("..."); | ||
70 | + if (searchDot !== -1) { | ||
71 | + mamuls[i]["extraInfo"] = mamuls[i]["extraInfo"].slice(0, searchDot); | ||
72 | + } | ||
73 | + } | ||
74 | + | ||
75 | + console.log(`unparsed extraInfo : \n${mamuls[i]["extraInfo"]}`); | ||
76 | + let searchValue = "\n"; | ||
77 | + let pos = 0; | ||
78 | + let foundPos = 0; | ||
79 | + for (let j = 0; j < 4 && foundPos !== -1; j++) { | ||
80 | + foundPos = mamuls[i]["extraInfo"].indexOf(searchValue, pos); | ||
81 | + pos = foundPos + 1; | ||
82 | + } | ||
83 | + console.log(`pos: ${pos}`); | ||
84 | + if (foundPos !== -1) { | ||
85 | + mamuls[i]["extraInfo"] = | ||
86 | + mamuls[i]["extraInfo"].slice(0, foundPos) + "\n..."; | ||
87 | + console.log(`parsed extraInfo : \n${mamuls[i]["extraInfo"]}`); | ||
88 | + } | ||
89 | + if (mamuls[i]["extraInfo"].length > 40) { | ||
90 | + mamuls[i]["extraInfo"] = | ||
91 | + mamuls[i]["extraInfo"].slice(0, 40) + "\n..."; | ||
92 | + console.log(`parsed extraInfo : \n${mamuls[i]["extraInfo"]}`); | ||
93 | + } | ||
56 | } | 94 | } |
95 | + // } else if (mamuls[i]["extraInfo"].length > 70) { | ||
96 | + // mamuls[i]["extraInfo"] = mamuls[i]["extraInfo"].slice(0, 70) + "\n..."; | ||
97 | + // } else { | ||
98 | + | ||
99 | + // } | ||
100 | + // else if (mamuls[i]["extraInfo"].indexOf("\n") !== -1) { | ||
101 | + // console.log(mamuls[i]["extraInfo"].indexOf("\n", 4)); | ||
102 | + // let slicePoint = mamuls[i]["extraInfo"].indexOf("\n", 4); | ||
103 | + // mamuls[i]["extraInfo"] = | ||
104 | + // mamuls[i]["extraInfo"].slice(0, slicePoint) + "\n..."; | ||
105 | + // } | ||
57 | 106 | ||
58 | flexMessage = setFlexMessage( | 107 | flexMessage = setFlexMessage( |
59 | mamuls[i]["platform"], | 108 | mamuls[i]["platform"], |
... | @@ -69,10 +118,23 @@ function setCarouselMessage(mamuls) { | ... | @@ -69,10 +118,23 @@ function setCarouselMessage(mamuls) { |
69 | continue; | 118 | continue; |
70 | } | 119 | } |
71 | } | 120 | } |
72 | - | 121 | + flexMessages[0]["header"] = { |
122 | + type: "box", | ||
123 | + layout: "horizontal", | ||
124 | + contents: [ | ||
125 | + { type: "text", text: "매무리 봇", size: "sm", color: "#1DB446" }, | ||
126 | + { | ||
127 | + type: "text", | ||
128 | + text: `키워드: ${keyword}`, | ||
129 | + align: "end", | ||
130 | + color: "#1DB446", | ||
131 | + weight: "bold", | ||
132 | + }, | ||
133 | + ], | ||
134 | + }; | ||
73 | let carouselMessage = { | 135 | let carouselMessage = { |
74 | type: "flex", | 136 | type: "flex", |
75 | - altText: "Carousel mamul message", | 137 | + altText: `${keyword} 매무리가 도착했어요!`, |
76 | contents: { | 138 | contents: { |
77 | type: "carousel", | 139 | type: "carousel", |
78 | contents: flexMessages, | 140 | contents: flexMessages, | ... | ... |
... | @@ -44,46 +44,6 @@ function setFlexMessage( | ... | @@ -44,46 +44,6 @@ function setFlexMessage( |
44 | weight: "bold", | 44 | weight: "bold", |
45 | size: "xl", | 45 | size: "xl", |
46 | }, | 46 | }, |
47 | - // { | ||
48 | - // type: "box", | ||
49 | - // layout: "baseline", | ||
50 | - // margin: "md", | ||
51 | - // contents: [ | ||
52 | - // { | ||
53 | - // type: "icon", | ||
54 | - // size: "sm", | ||
55 | - // url: "https://scdn.line-apps.com/n/channel_devcenter/img/fx/review_gold_star_28.png", | ||
56 | - // }, | ||
57 | - // { | ||
58 | - // type: "icon", | ||
59 | - // size: "sm", | ||
60 | - // url: "https://scdn.line-apps.com/n/channel_devcenter/img/fx/review_gold_star_28.png", | ||
61 | - // }, | ||
62 | - // { | ||
63 | - // type: "icon", | ||
64 | - // size: "sm", | ||
65 | - // url: "https://scdn.line-apps.com/n/channel_devcenter/img/fx/review_gold_star_28.png", | ||
66 | - // }, | ||
67 | - // { | ||
68 | - // type: "icon", | ||
69 | - // size: "sm", | ||
70 | - // url: "https://scdn.line-apps.com/n/channel_devcenter/img/fx/review_gold_star_28.png", | ||
71 | - // }, | ||
72 | - // { | ||
73 | - // type: "icon", | ||
74 | - // size: "sm", | ||
75 | - // url: "https://scdn.line-apps.com/n/channel_devcenter/img/fx/review_gray_star_28.png", | ||
76 | - // }, | ||
77 | - // { | ||
78 | - // type: "text", | ||
79 | - // text: "4.0", | ||
80 | - // size: "sm", | ||
81 | - // color: "#999999", | ||
82 | - // margin: "md", | ||
83 | - // flex: 0, | ||
84 | - // }, | ||
85 | - // ], | ||
86 | - // }, | ||
87 | { | 47 | { |
88 | type: "box", | 48 | type: "box", |
89 | layout: "vertical", | 49 | layout: "vertical", | ... | ... |
1 | function setKeywordsFlexMessage(keywords) { | 1 | function setKeywordsFlexMessage(keywords) { |
2 | - let flexMessage = { | 2 | + let flexMessage = { |
3 | - type: "bubble", | 3 | + type: "bubble", |
4 | - body: { | 4 | + body: { |
5 | - type: "box", | 5 | + type: "box", |
6 | - layout: "vertical", | 6 | + layout: "vertical", |
7 | - contents: [ | 7 | + contents: [ |
8 | - { | 8 | + { |
9 | - type: "text", | 9 | + type: "text", |
10 | - text: "매무리 봇", | 10 | + text: "매무리 봇", |
11 | - weight: "bold", | 11 | + weight: "bold", |
12 | - color: "#1DB446", | 12 | + color: "#1DB446", |
13 | - size: "sm", | 13 | + size: "sm", |
14 | - }, | ||
15 | - { | ||
16 | - type: "text", | ||
17 | - text: "등록된 키워드", | ||
18 | - weight: "bold", | ||
19 | - size: "xxl", | ||
20 | - margin: "md" | ||
21 | - }, | ||
22 | - { | ||
23 | - type: "separator", | ||
24 | - margin: "xxl" | ||
25 | - }, | ||
26 | - { | ||
27 | - type: "box", | ||
28 | - layout: "vertical", | ||
29 | - contents: [], | ||
30 | - margin: "md" | ||
31 | - } | ||
32 | - ] | ||
33 | }, | 14 | }, |
34 | - }; | 15 | + { |
16 | + type: "text", | ||
17 | + text: "등록된 키워드", | ||
18 | + weight: "bold", | ||
19 | + size: "xxl", | ||
20 | + margin: "md", | ||
21 | + }, | ||
22 | + { | ||
23 | + type: "separator", | ||
24 | + margin: "xxl", | ||
25 | + }, | ||
26 | + { | ||
27 | + type: "box", | ||
28 | + layout: "vertical", | ||
29 | + contents: [], | ||
30 | + margin: "md", | ||
31 | + }, | ||
32 | + ], | ||
33 | + }, | ||
34 | + }; | ||
35 | 35 | ||
36 | - for (let i = 0; i < keywords.length; i++) { | 36 | + for (let i = 0; i < keywords.length; i++) { |
37 | - const textbox = createKeywordTextBox(keywords[i]); | 37 | + const textbox = createKeywordTextBox(keywords[i]); |
38 | - flexMessage.body.contents[3].contents.push(textbox); | 38 | + flexMessage.body.contents[3].contents.push(textbox); |
39 | - } | 39 | + } |
40 | 40 | ||
41 | - return { | 41 | + return { |
42 | - type: "flex", | 42 | + type: "flex", |
43 | - altText: "키워드 조회 오류", | 43 | + altText: "매무리 키워드 확인", |
44 | - contents: flexMessage | 44 | + contents: flexMessage, |
45 | - } | 45 | + }; |
46 | } | 46 | } |
47 | 47 | ||
48 | function createKeywordTextBox(keyword) { | 48 | function createKeywordTextBox(keyword) { |
49 | - return { | 49 | + return { |
50 | - type: "text", | 50 | + type: "text", |
51 | - text: keyword, | 51 | + text: keyword, |
52 | - size: "lg", | 52 | + size: "lg", |
53 | - align: "center", | 53 | + align: "center", |
54 | - margin: "md" | 54 | + margin: "md", |
55 | - } | 55 | + }; |
56 | } | 56 | } |
57 | 57 | ||
58 | -module.exports = setKeywordsFlexMessage; | ||
... | \ No newline at end of file | ... | \ No newline at end of file |
58 | +module.exports = setKeywordsFlexMessage; | ... | ... |
1 | -const { daangnSingleSearch } = require("./daangnSearch"); | 1 | +const { daangnMultiSearch } = require("./daangnSearch"); |
2 | -const { bunjangSingleSearch } = require("./bunjangSearch"); | 2 | +const { bunjangMultiSearch } = require("./bunjangSearch"); |
3 | -const { joongnaSingleSearch } = require("./joongnaSearch"); | 3 | +const { joongnaMultiSearch } = require("./joongnaSearch"); |
4 | -const setCarouselMessage = require("../message/setCarouselMessage"); | ||
5 | 4 | ||
6 | const marketMultiSearch = (keyword) => { | 5 | const marketMultiSearch = (keyword) => { |
7 | const result = []; | 6 | const result = []; |
8 | return new Promise((resolve, reject) => { | 7 | return new Promise((resolve, reject) => { |
9 | - daangnSingleSearch(keyword).then((res) => { | 8 | + daangnMultiSearch(keyword).then((res) => { |
10 | - result.push(res); | 9 | + console.log(`daangn: ${res}`); |
11 | - bunjangSingleSearch(keyword).then((res) => { | 10 | + if (res !== undefined && res !== null) { |
12 | - result.push(res); | 11 | + for (let i = 0; i < res.length && i < 4; i++) { |
13 | - joongnaSingleSearch(keyword).then((res) => { | 12 | + result.push(res[i]); |
14 | - result.push(res); | 13 | + } |
14 | + } | ||
15 | + bunjangMultiSearch(keyword).then((res) => { | ||
16 | + console.log(`bunjang: ${res}`); | ||
17 | + if (res !== undefined && res !== null) { | ||
18 | + for (let i = 0; i < res.length && i < 4; i++) { | ||
19 | + result.push(res[i]); | ||
20 | + } | ||
21 | + } | ||
22 | + joongnaMultiSearch(keyword).then((res) => { | ||
23 | + console.log(`joongna: ${res}`); | ||
24 | + if (res !== undefined && res !== null) { | ||
25 | + for (let i = 0; i < res.length && i < 4; i++) { | ||
26 | + result.push(res[i]); | ||
27 | + } | ||
28 | + } | ||
15 | resolve(result); | 29 | resolve(result); |
16 | }); | 30 | }); |
17 | }); | 31 | }); | ... | ... |
-
Please register or login to post a comment