mirror of
https://gitlab.com/nekoya/web.git
synced 2024-11-21 13:56:19 +01:00
Add Telegram Module
This commit is contained in:
parent
aba4255ab8
commit
2408b8474c
1 changed files with 30 additions and 0 deletions
30
modules/telegram.js
Normal file
30
modules/telegram.js
Normal file
|
@ -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
|
||||||
|
}
|
Loading…
Reference in a new issue