MCPcopy Create free account
hub / github.com/6dylan6/jdm / tgBotNotify

Function tgBotNotify

sendNotify.js:2053–2106  ·  view source on GitHub ↗
(text, desp)

Source from the content-addressed store, hash-verified

2051}
2052
2053function tgBotNotify(text, desp) {
2054 return new Promise(resolve => {
2055 if (TG_BOT_TOKEN && TG_USER_ID) {
2056 const options = {
2057 url: `https://${TG_API_HOST}/bot${TG_BOT_TOKEN}/sendMessage`,
2058 json: {
2059 chat_id: `${TG_USER_ID}`,
2060 text: `${text}\n\n${desp}`,
2061 disable_web_page_preview:true,
2062 },
2063 headers: {
2064 'Content-Type': 'application/json',
2065 },
2066 timeout
2067 }
2068 if (TG_PROXY_HOST && TG_PROXY_PORT) {
2069 const tunnel = require("tunnel");
2070 const agent = {
2071 https: tunnel.httpsOverHttp({
2072 proxy: {
2073 host: TG_PROXY_HOST,
2074 port: TG_PROXY_PORT * 1,
2075 proxyAuth: TG_PROXY_AUTH
2076 }
2077 })
2078 }
2079 Object.assign(options, {agent})
2080 }
2081 $.post(options, (err, resp, data) => {
2082 try {
2083 if (err) {
2084 console.log('telegram发送通知消息失败!!\n')
2085 console.log(err);
2086 } else {
2087 data = JSON.parse(data);
2088 if (data.ok) {
2089 console.log('Telegram发送通知消息成功�。\n')
2090 } else if (data.error_code === 400) {
2091 console.log('请主动给bot发送一条消息并检查接收用户ID是否正确。\n')
2092 } else if (data.error_code === 401) {
2093 console.log('Telegram bot token 填写错误。\n')
2094 }
2095 }
2096 } catch (e) {
2097 $.logErr(e, resp);
2098 } finally {
2099 resolve(data);
2100 }
2101 })
2102 } else {
2103 resolve()
2104 }
2105 })
2106}
2107
2108function ddBotNotify(text, desp) {
2109 return new Promise((resolve) => {

Callers 1

sendNotifyFunction · 0.70

Calls 3

postMethod · 0.45
logMethod · 0.45
logErrMethod · 0.45

Tested by

no test coverage detected