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

Function webhookNotify

sendNofity.js:1226–1279  ·  view source on GitHub ↗
(text, desp)

Source from the content-addressed store, hash-verified

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