(text, desp)
| 1314 | } |
| 1315 | |
| 1316 | function tgBotNotify(text, desp) { |
| 1317 | return new Promise(resolve => { |
| 1318 | if (TG_BOT_TOKEN && TG_USER_ID) { |
| 1319 | const options = { |
| 1320 | url: `https://${TG_API_HOST}/bot${TG_BOT_TOKEN}/sendMessage`, |
| 1321 | json: { |
| 1322 | chat_id: `${TG_USER_ID}`, |
| 1323 | text: `${text}\n\n${desp}`, |
| 1324 | disable_web_page_preview:true |
| 1325 | }, |
| 1326 | headers: { |
| 1327 | 'Content-Type': 'application/json', |
| 1328 | }, |
| 1329 | timeout |
| 1330 | } |
| 1331 | if (TG_PROXY_HOST && TG_PROXY_PORT) { |
| 1332 | const tunnel = require("tunnel"); |
| 1333 | const agent = { |
| 1334 | https: tunnel.httpsOverHttp({ |
| 1335 | proxy: { |
| 1336 | host: TG_PROXY_HOST, |
| 1337 | port: TG_PROXY_PORT * 1, |
| 1338 | proxyAuth: TG_PROXY_AUTH |
| 1339 | } |
| 1340 | }) |
| 1341 | } |
| 1342 | Object.assign(options, {agent}) |
| 1343 | } |
| 1344 | $.post(options, (err, resp, data) => { |
| 1345 | try { |
| 1346 | if (err) { |
| 1347 | console.log('telegram发送通知消息失败!!\n') |
| 1348 | console.log(err); |
| 1349 | } else { |
| 1350 | data = JSON.parse(data); |
| 1351 | if (data.ok) { |
| 1352 | console.log('Telegram发送通知消息成功🎉\n') |
| 1353 | } else if (data.error_code === 400) { |
| 1354 | console.log('请主动给bot发送一条消息并检查接收用户ID是否正确。\n') |
| 1355 | } else if (data.error_code === 401) { |
| 1356 | console.log('Telegram bot token 填写错误。\n') |
| 1357 | } |
| 1358 | } |
| 1359 | } catch (e) { |
| 1360 | $.logErr(e, resp); |
| 1361 | } finally { |
| 1362 | resolve(data); |
| 1363 | } |
| 1364 | }) |
| 1365 | } else { |
| 1366 | resolve() |
| 1367 | } |
| 1368 | }) |
| 1369 | } |
| 1370 | |
| 1371 | function ddBotNotify(text, desp) { |
| 1372 | return new Promise((resolve) => { |
no test coverage detected