Showing
5 changed files
with
36 additions
and
6 deletions
| ... | @@ -10,12 +10,6 @@ sequelize | ... | @@ -10,12 +10,6 @@ sequelize |
| 10 | .sync({ force: false }) | 10 | .sync({ force: false }) |
| 11 | .then(() => { | 11 | .then(() => { |
| 12 | console.log("database connection complete"); | 12 | console.log("database connection complete"); |
| 13 | - database.addKeyword("rtx3060", "junseok"); | ||
| 14 | - database.getKeywordsByUserId("junseok"); | ||
| 15 | - database.deleteKeyword("phobyjun", "rtx3080"); | ||
| 16 | - database.getAllUsers(); | ||
| 17 | - database.getUsersByKeyword("rtx3060"); | ||
| 18 | - database.getAllKeywords(); | ||
| 19 | }) | 13 | }) |
| 20 | .catch((err) => { | 14 | .catch((err) => { |
| 21 | console.log("database connection failed"); | 15 | console.log("database connection failed"); | ... | ... |
server/chatbot/checkMamul/checkMamul.js
0 → 100644
| 1 | +const { marketMultiSearch } = require("../search/marketSearch"); | ||
| 2 | +const setCarouselMessage = require("../message/setCarouselMessage"); | ||
| 3 | +// Database APIs | ||
| 4 | +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 | + | ||
| 13 | +const checkMamul = (client) => { | ||
| 14 | + db.getAllKeywords().then((keywords) => { | ||
| 15 | + for (let i = 0, pending = Promise.resolve(); i < keywords.length; i++) { | ||
| 16 | + pending = db.getUsersByKeyword(keywords[i]).then((userIds) => { | ||
| 17 | + marketMultiSearch(keywords[i]).then((res) => { | ||
| 18 | + client.multicast(userIds, [setCarouselMessage(res)]); | ||
| 19 | + }); | ||
| 20 | + }); | ||
| 21 | + } | ||
| 22 | + }); | ||
| 23 | +}; | ||
| 24 | + | ||
| 25 | +module.exports = { checkMamul }; |
| ... | @@ -15,6 +15,12 @@ const { marketMultiSearch } = require("./search/marketSearch"); | ... | @@ -15,6 +15,12 @@ const { marketMultiSearch } = require("./search/marketSearch"); |
| 15 | // File search - Will be deleted (Unused) | 15 | // File search - Will be deleted (Unused) |
| 16 | const fs = require("fs"); | 16 | const fs = require("fs"); |
| 17 | 17 | ||
| 18 | +// Cron for Mamul Notification | ||
| 19 | +const schedule = require("node-schedule"); | ||
| 20 | +const job = schedule.scheduleJob("0 */1 * * *", () => { | ||
| 21 | + checkMamul(client); | ||
| 22 | +}); | ||
| 23 | + | ||
| 18 | // Database APIs | 24 | // Database APIs |
| 19 | const db = require("../apis/database"); | 25 | const db = require("../apis/database"); |
| 20 | // API List | 26 | // API List |
| ... | @@ -32,6 +38,10 @@ const config = { | ... | @@ -32,6 +38,10 @@ const config = { |
| 32 | channelSecret: process.env.channelSecret, | 38 | channelSecret: process.env.channelSecret, |
| 33 | }; | 39 | }; |
| 34 | 40 | ||
| 41 | +// Cron for Mamul Notification | ||
| 42 | +const { checkMamul } = require("./checkMamul/checkMamul"); | ||
| 43 | + | ||
| 44 | +// Line chat bot client & event | ||
| 35 | const client = new line.Client(config); | 45 | const client = new line.Client(config); |
| 36 | 46 | ||
| 37 | let waitNewMamulList = []; // 매물 키워드 입력 기다리는 목록 | 47 | let waitNewMamulList = []; // 매물 키워드 입력 기다리는 목록 | ... | ... |
This diff is collapsed. Click to expand it.
| ... | @@ -20,6 +20,7 @@ | ... | @@ -20,6 +20,7 @@ |
| 20 | "dotenv": "^16.0.1", | 20 | "dotenv": "^16.0.1", |
| 21 | "express": "^4.18.1", | 21 | "express": "^4.18.1", |
| 22 | "mysql2": "^2.3.3", | 22 | "mysql2": "^2.3.3", |
| 23 | + "node-schedule": "^2.1.0", | ||
| 23 | "nodemon": "^2.0.16", | 24 | "nodemon": "^2.0.16", |
| 24 | "sequelize": "^6.20.0" | 25 | "sequelize": "^6.20.0" |
| 25 | } | 26 | } | ... | ... |
-
Please register or login to post a comment