From 2408b8474c9b7972ea28fcb3fa7da51358363d0e Mon Sep 17 00:00:00 2001 From: Moe Date: Tue, 5 Apr 2022 17:43:15 +0700 Subject: [PATCH] Add Telegram Module --- modules/telegram.js | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 modules/telegram.js diff --git a/modules/telegram.js b/modules/telegram.js new file mode 100644 index 0000000..5591049 --- /dev/null +++ b/modules/telegram.js @@ -0,0 +1,30 @@ +const axios = require("axios"); + +let config; +try { + config = require("../config"); +} catch (e) { + console.log("No config file found"); + process.exit(0); +} + +const TG_API = "https://api.telegram.org/bot" +const TG_BOT_TOKEN = config.telegram; + +const TG_URL = TG_API + TG_BOT_TOKEN; + +function send(to, text) { + const params = { + chat_id: to, + text: text, + parse_mode: 'HTML' + } + return axios + .get(TG_URL + "/sendMessage", { params }) + .then((response) => response.data) + .catch((error) => console.log(error)); +} + +module.exports = { + send +} \ No newline at end of file