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

Function webhookNotify

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

Source from the content-addressed store, hash-verified

1220}
1221
1222function webhookNotify(text, desp) {
1223 return new Promise((resolve) => {
1224 const {
1225 WEBHOOK_URL,
1226 WEBHOOK_BODY,
1227 WEBHOOK_HEADERS,
1228 WEBHOOK_CONTENT_TYPE,
1229 WEBHOOK_METHOD,
1230 } = push_config;
1231 if (
1232 !WEBHOOK_METHOD ||
1233 !WEBHOOK_URL ||
1234 (!WEBHOOK_URL.includes('$title') && !WEBHOOK_BODY.includes('$title'))
1235 ) {
1236 resolve();
1237 return;
1238 }
1239
1240 const headers = parseHeaders(WEBHOOK_HEADERS);
1241 const body = parseBody(WEBHOOK_BODY, WEBHOOK_CONTENT_TYPE, (v) =>
1242 v
1243 ?.replaceAll('$title', text?.replaceAll('\n', '\\n'))
1244 ?.replaceAll('$content', desp?.replaceAll('\n', '\\n')),
1245 );
1246 const bodyParam = formatBodyFun(WEBHOOK_CONTENT_TYPE, body);
1247 const options = {
1248 method: WEBHOOK_METHOD,
1249 headers,
1250 allowGetBody: true,
1251 ...bodyParam,
1252 timeout,
1253 retry: 1,
1254 };
1255
1256 const formatUrl = WEBHOOK_URL.replaceAll(
1257 '$title',
1258 encodeURIComponent(text),
1259 ).replaceAll('$content', encodeURIComponent(desp));
1260 httpClient.request(formatUrl, options).then(async (resp) => {
1261 const body = await resp.body.text();
1262 try {
1263 if (resp.statusCode !== 200) {
1264 console.log(`自定义发送通知消息失败😞 ${body}\n`);
1265 } else {
1266 console.log(`自定义发送通知消息成功🎉 ${body}\n`);
1267 }
1268 } catch (e) {
1269 $.logErr(e, resp);
1270 } finally {
1271 resolve(body);
1272 }
1273 });
1274 });
1275}
1276
1277function ntfyNotify(text, desp) {
1278 function encodeRFC2047(text) {

Callers 1

sendNotifyFunction · 0.70

Calls 6

parseHeadersFunction · 0.70
parseBodyFunction · 0.70
formatBodyFunFunction · 0.70
requestMethod · 0.45
logMethod · 0.45
logErrMethod · 0.45

Tested by

no test coverage detected