(text, desp)
| 296 | } |
| 297 | |
| 298 | function tgBotNotify(text, desp) { |
| 299 | return new Promise(resolve => { |
| 300 | if (TG_BOT_TOKEN && TG_USER_ID) { |
| 301 | const options = { |
| 302 | url: `https://${TG_API_HOST}/bot${TG_BOT_TOKEN}/sendMessage`, |
| 303 | body: `chat_id=${TG_USER_ID}&text=${text}\n\n${desp}&disable_web_page_preview=true`, |
| 304 | headers: { |
| 305 | 'Content-Type': 'application/x-www-form-urlencoded' |
| 306 | }, |
| 307 | timeout |
| 308 | } |
| 309 | if (TG_PROXY_HOST && TG_PROXY_PORT) { |
| 310 | const tunnel = require("tunnel"); |
| 311 | const agent = { |
| 312 | https: tunnel.httpsOverHttp({ |
| 313 | proxy: { |
| 314 | host: TG_PROXY_HOST, |
| 315 | port: TG_PROXY_PORT * 1, |
| 316 | proxyAuth: TG_PROXY_AUTH |
| 317 | } |
| 318 | }) |
| 319 | } |
| 320 | Object.assign(options, { agent }) |
| 321 | } |
| 322 | $.post(options, (err, resp, data) => { |
| 323 | try { |
| 324 | if (err) { |
| 325 | console.log('telegram发送通知消息失败!!\n') |
| 326 | console.log(err); |
| 327 | } else { |
| 328 | data = JSON.parse(data); |
| 329 | if (data.ok) { |
| 330 | console.log('Telegram发送通知消息成功🎉。\n') |
| 331 | } else if (data.error_code === 400) { |
| 332 | console.log('请主动给bot发送一条消息并检查接收用户ID是否正确。\n') |
| 333 | } else if (data.error_code === 401) { |
| 334 | console.log('Telegram bot token 填写错误。\n') |
| 335 | } |
| 336 | } |
| 337 | } catch (e) { |
| 338 | $.logErr(e, resp); |
| 339 | } finally { |
| 340 | resolve(data); |
| 341 | } |
| 342 | }) |
| 343 | } else { |
| 344 | console.log('您未提供telegram机器人推送所需的TG_BOT_TOKEN和TG_USER_ID,取消telegram推送消息通知🚫\n'); |
| 345 | resolve() |
| 346 | } |
| 347 | }) |
| 348 | } |
| 349 | function ddBotNotify(text, desp) { |
| 350 | return new Promise(resolve => { |
| 351 | const options = { |
no test coverage detected