-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
executable file
·44 lines (39 loc) · 1.35 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
const axios = require("axios");
const process = require("process");
const config = require("./config.json");
const totalURL = `${config.API_url}${config.PACKAGE_number}?lang=${config.API_lang}`;
async function main() {
const { data } = await axios.get(totalURL, {
headers: {
"X-Okapi-Key": config.API_key,
"accept": "application/json",
}
}).catch((error) => {
console.log(`Request to ${totalURL} failed`);
console.log(error.toString());
process.exit();
});
// formatting
let dataWebHook = {
username: "La Poste",
content: "Info colis",
embeds: [],
};
for (let oneTimeEvent of data.shipment.timeline) {
if (oneTimeEvent.shortLabel != "") {
dataWebHook.embeds.push({
title: oneTimeEvent.date || "No date",
description: oneTimeEvent.shortLabel || "",
});
}
}
//console.log(JSON.stringify(data.shipment.timeline));
if (typeof config.WEBHOOK_URL !== "undefined" && config.WEBHOOK_URL !== "") {
await axios.post(config.WEBHOOK_URL, dataWebHook).catch((error) => {
console.log(`Request to ${config.WEBHOOK_URL} failed`);
console.log(error.toString());
process.exit();
});
}
}
main();