diff --git a/bot.js b/bot.js index 320bc29..eee055b 100644 --- a/bot.js +++ b/bot.js @@ -1,8 +1,8 @@ const Telegraf = require("telegraf"); const Sequelize = require("sequelize"); -const main = require("./bot"); -const config = require("./config"); +const main = require("./bot/index"); +const { bot: config } = require("./config"); const db = require("./data")(Sequelize, config); const bot = new Telegraf(config.botApiKey); diff --git a/sample.config.js b/sample.config.js index 0943f97..72dc46d 100644 --- a/sample.config.js +++ b/sample.config.js @@ -1,10 +1,14 @@ module.exports = { - // Create a new bot by messaging @BotFather and follow the instructions - // Replace the key by the actual token recieved from BotFather - botApiKey: "key", - + bot: { + // Create a new bot by messaging @BotFather and follow the instructions + // Replace the key by the actual token recieved from BotFather + botApiKey: "bot_api_key", + }, + server: { + port: 2000 + }, // Connection information for database - "sequelize": { + sequelize: { database: "git-alerts-bot", username: "git-bot", password: "hopefully_a_secure_password", @@ -12,7 +16,7 @@ module.exports = { host: "localhost", dialect: "sqlite", // SQLite only - storage: "./store/git-alerts-bot.sqlite" - } + storage: "./store/git-alerts-bot.sqlite", + }, }, }; diff --git a/server.js b/server.js index e7c8cdb..7e0e1a1 100644 --- a/server.js +++ b/server.js @@ -1,12 +1,19 @@ const express = require("express"); -const app = express(); -app.use(express.json()); +const main = require("./server/index"); const convert = require("./util/convert"); +const { server: config } = require("./config"); +const PORT = config.server.port; -app.get("/webhook/:provider", (req) => { +const app = express(); - const strategy = req.params.provider; - const eventType = convert.getEvent[strategy](req.body); +app.use(express.json()); +app.use((req, res, next) => { + + req.convert = convert; + next(); }); -app.listen(2000, () => console.log("Listening on port 2000")); + +main(app); + +app.listen(PORT, () => console.log("Listening on port", PORT)); diff --git a/server/index.js b/server/index.js new file mode 100644 index 0000000..0a58bff --- /dev/null +++ b/server/index.js @@ -0,0 +1,10 @@ +module.exports = app => { + + app.get("/webhook/:provider", (req, res) => { + + const strategy = req.params.provider; + const eventType = req.convert.getEvent[strategy](req.body); + + }); + +};