(text, desp)
| 389 | } |
| 390 | |
| 391 | function tgBotNotify(text, desp) { |
| 392 | return new Promise(resolve => { |
| 393 | if (TG_BOT_TOKEN && TG_USER_ID) { |
| 394 | const options = { |
| 395 | url: `https://${TG_API_HOST}/bot${TG_BOT_TOKEN}/sendMessage`, |
| 396 | json: { |
| 397 | chat_id: `${TG_USER_ID}`, |
| 398 | text: `${text}\n\n${desp}`, |
| 399 | disable_web_page_preview: true, |
| 400 | }, |
| 401 | headers: { |
| 402 | 'Content-Type': 'application/json', |
| 403 | }, |
| 404 | timeout |
| 405 | } |
| 406 | if (TG_PROXY_HOST && TG_PROXY_PORT) { |
| 407 | const tunnel = require("tunnel"); |
| 408 | const agent = { |
| 409 | https: tunnel.httpsOverHttp({ |
| 410 | proxy: { |
| 411 | host: TG_PROXY_HOST, |
| 412 | port: TG_PROXY_PORT * 1, |
| 413 | proxyAuth: TG_PROXY_AUTH |
| 414 | } |
| 415 | }) |
| 416 | } |
| 417 | Object.assign(options, {agent}) |
| 418 | } |
| 419 | $.post(options, (err, resp, data) => { |
| 420 | try { |
| 421 | if (err) { |
| 422 | console.log('telegram发送通知消息失败!!\n') |
| 423 | console.log(err); |
| 424 | } else { |
| 425 | data = JSON.parse(data); |
| 426 | if (data.ok) { |
| 427 | console.log('Telegram发送通知消息成功🎉。\n') |
| 428 | } else if (data.error_code === 400) { |
| 429 | console.log('请主动给bot发送一条消息并检查接收用户ID是否正确。\n') |
| 430 | } else if (data.error_code === 401) { |
| 431 | console.log('Telegram bot token 填写错误。\n') |
| 432 | } |
| 433 | } |
| 434 | } catch (e) { |
| 435 | $.logErr(e, resp); |
| 436 | } finally { |
| 437 | resolve(data); |
| 438 | } |
| 439 | }) |
| 440 | } else { |
| 441 | // console.log('您未提供telegram机器人推送所需的TG_BOT_TOKEN和TG_USER_ID,取消telegram推送消息通知🚫\n'); |
| 442 | resolve() |
| 443 | } |
| 444 | }) |
| 445 | } |
| 446 | |
| 447 | function ddBotNotify(text, desp) { |
| 448 | return new Promise(resolve => { |
no test coverage detected