MCPcopy Index your code
hub / github.com/smallfawn/QLScriptPublic / tgBotNotify

Function tgBotNotify

tools/sendNotify.js:461–520  ·  view source on GitHub ↗
(text, desp)

Source from the content-addressed store, hash-verified

459}
460
461function tgBotNotify(text, desp) {
462 return new Promise((resolve) => {
463 const {
464 TG_BOT_TOKEN,
465 TG_USER_ID,
466 TG_PROXY_HOST,
467 TG_PROXY_PORT,
468 TG_API_HOST,
469 TG_PROXY_AUTH,
470 } = push_config;
471 if (TG_BOT_TOKEN && TG_USER_ID) {
472 let options = {
473 url: `${TG_API_HOST}/bot${TG_BOT_TOKEN}/sendMessage`,
474 json: {
475 chat_id: `${TG_USER_ID}`,
476 text: `${text}\n\n${desp}`,
477 disable_web_page_preview: true,
478 },
479 headers: {
480 'Content-Type': 'application/json',
481 },
482 timeout,
483 };
484 if (TG_PROXY_HOST && TG_PROXY_PORT) {
485 let proxyHost = TG_PROXY_HOST;
486 if (TG_PROXY_AUTH && !TG_PROXY_HOST.includes('@')) {
487 proxyHost = `${TG_PROXY_AUTH}@${TG_PROXY_HOST}`;
488 }
489 let agent;
490 agent = new ProxyAgent({
491 uri: `http://${proxyHost}:${TG_PROXY_PORT}`,
492 });
493 options.dispatcher = agent;
494 }
495 $.post(options, (err, resp, data) => {
496 try {
497 if (err) {
498 console.log('Telegram 发送通知消息失败😞\n', err);
499 } else {
500 if (data.ok) {
501 console.log('Telegram 发送通知消息成功🎉。\n');
502 } else if (data.error_code === 400) {
503 console.log(
504 '请主动给bot发送一条消息并检查接收用户ID是否正确。\n',
505 );
506 } else if (data.error_code === 401) {
507 console.log('Telegram bot token 填写错误。\n');
508 }
509 }
510 } catch (e) {
511 $.logErr(e, resp);
512 } finally {
513 resolve(data);
514 }
515 });
516 } else {
517 resolve();
518 }

Callers 1

sendNotifyFunction · 0.70

Calls 3

postMethod · 0.45
logMethod · 0.45
logErrMethod · 0.45

Tested by

no test coverage detected