aboutsummaryrefslogtreecommitdiffstats
path: root/src/index.ts
diff options
context:
space:
mode:
Diffstat (limited to 'src/index.ts')
-rw-r--r--src/index.ts53
1 files changed, 30 insertions, 23 deletions
diff --git a/src/index.ts b/src/index.ts
index 3f0c7ef..7553b56 100644
--- a/src/index.ts
+++ b/src/index.ts
@@ -1,36 +1,43 @@
import { App } from "@tinyhttp/app";
import { logger } from "@tinyhttp/logger";
import config from "./config";
-import { broadcast } from "./sheets";
+import { buildSheetsClient } from "./sheets";
import { bot } from "./tg";
-const app = new App({
- onError: (err, _req, res) => {
- console.log(err);
- res.status(500).send("Something bad happened");
- },
-});
+const main = async () => {
+ const sheets = await buildSheetsClient();
-app
- .use(logger({
- timestamp: {
- format: "YYYY-MM-DDTHH:mm:ssZ[Z]",
+ const app = new App({
+ onError: (err, _req, res) => {
+ console.log(err);
+ res.status(500).send("Something bad happened");
},
- }))
- .use(bot.webhookCallback("/webhook/telegram"))
- .get("/", async (_, res) => {
- res.send({ service: "hommabot2 API" });
- })
- .post("/scheduler/trigger", async (_req, res) => {
- await broadcast();
- res.send({ scheduler: "trigger" });
});
-console.log(`Setting up webhook on ${config.tgWebhookUrl}`);
-bot.telegram.setWebhook(config.tgWebhookUrl);
+ app
+ .use(logger({
+ timestamp: {
+ format: "YYYY-MM-DDTHH:mm:ssZ[Z]",
+ },
+ }))
+ .use(bot.webhookCallback("/webhook/telegram"))
+ .get("/", async (_, res) => {
+ res.send({ service: "hommabot2 API" });
+ })
+ .post("/scheduler/trigger", async (_req, res) => {
+ await sheets.fetchSheetData();
+ res.send({ scheduler: "trigger" });
+ });
-console.log(`Serving on http://localhost:${config.port}`);
-app.listen(config.port);
+ console.log(`Setting up webhook on ${config.tgWebhookUrl}`);
+ bot.telegram.setWebhook(config.tgWebhookUrl);
+
+ console.log(`Serving on http://localhost:${config.port}`);
+ app.listen(config.port);
+
+};
+
+main();
// Enable graceful stop
process.once("SIGINT", () => bot.stop("SIGINT"));