This repository was archived by the owner on Dec 23, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 23
/
Copy pathxdsl.js
125 lines (107 loc) · 4.24 KB
/
xdsl.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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
const { TextMessage, Button, ButtonsMessage } = require("../platforms/generics");
const translator = require("../utils/translator");
const checkxDSLDiagAdvanced = (diag, locale) => {
let responses = "";
let linePb = false;
responses = translator("xdsl-diagnosticTime", locale, new Date(diag.diagnosticTime).toUTCString());
if (diag.isModemConnected != null) {
if (!diag.isModemConnected) {
responses += translator("xdsl-diagnosticModemUnplug", locale);
linePb = true;
} else {
responses += translator("xdsl-diagnosticModemPlug", locale);
}
}
if (diag.lineDetails != null && Array.isArray(diag.lineDetails)) {
responses += translator("xdsl-diagnosticLineStatus", locale);
for (let i = 0; i < diag.lineDetails.length; i++) {
// detect sync
const lineDiag = diag.lineDetails[i];
responses += translator("xdsl-diagnosticLineSync", locale, lineDiag.number, lineDiag.sync ? translator("xdsl-sync", locale) : translator("xdsl-unsync", locale));
if (lineDiag.lineTest != null) {
switch (lineDiag.lineTest) {
case "customerSideProblem":
responses += translator("xdsl-diagnosticCustomerSideProblem", locale);
break;
case "ovhSideProblem":
responses += translator("xdsl-diagnosticOvhSideProblem", locale);
break;
case "error":
responses += translator("xdsl-diagnosticError", locale);
break;
default:break;
}
}
if (!lineDiag.sync) {
linePb = true;
}
}
}
if (diag.ping != null) {
if (!diag.ping) {
responses += translator("xdsl-diagnosticPing", locale);
linePb = true;
} else {
responses += translator("xdsl-diagnosticNoPing", locale);
}
}
if (!linePb) {
responses += translator("xdsl-diagnosticResultOk", locale);
} else {
responses += translator("xdsl-diagnosticResultNOk", locale);
}
responses += translator("xdsl-diagnosticResultMore", locale);
return [new TextMessage(responses)];
};
const checkxDSLDiag = (xdslOffer, serviceInfos, orderFollowUp, incident, diag, managerLink, locale) => {
let responses = [];
let orderOk = false;
let orderString = "";
if (incident != null) {
responses = [new TextMessage(translator("xdsl-incident", locale, incident.comment || "N/A", incident.endDate || "N/A", `http://travaux.ovh.net/?do=details&id=${incident.taskId}`))];
}
for (let i = 0; i < orderFollowUp.length; i++) {
const orderStep = orderFollowUp[i];
if (orderStep.name === "accessIsOperational") {
if (orderStep.status === "done") {
orderOk = true;
}
} else {
switch (orderStep.status) {
case "doing":
case "todo":
case "error":
orderString += translator("xdsl-orderStepStatus", locale, translator(`xdsl-${orderStep.name}`, locale), translator(`xdsl-${orderStep.status}`, locale), orderStep.expectedDuration, translator(`xdsl-${orderStep.durationUnit}`, locale));
break;
case "done":
default:
break;
}
}
}
if (!orderOk) {
return [...responses, new TextMessage(translator("xdsl-orderNotReady", locale, orderString, `${managerLink}/order`))];
}
if (xdslOffer.status === "slamming") {
const button = new Button("web_url", "tel:1007", translator("xdsl-callSupport", locale));
responses = [...responses, new ButtonsMessage(translator("xdsl-lineSlamming", locale), [button])];
}
if (serviceInfos.status === "unPaid") {
responses = [...responses, new TextMessage(translator("xdsl-lineUnPaid", locale))];
}
if (responses.length === 0) {
const button = new Button("postback", `XDSL_DIAG_${xdslOffer.accessName}`, translator("xdsl-launchDiag", locale));
let resultOk = translator("xdsl-resultOk", locale, managerLink);
let diagRemaing = translator("xdsl-resultDiagRemaining", locale, diag ? diag.remaining : 5);
let advanceDiag = translator("xdsl-resultAdvancedDiag", locale);
responses = [new ButtonsMessage(`${resultOk}\n${diagRemaing}\n${advanceDiag}`, [button])];
}
if (diag) {
responses = [...responses, new TextMessage(translator("xdsl-resultLastDiag", locale)), ...checkxDSLDiagAdvanced(diag, locale)];
}
return responses;
};
module.exports = {
checkxDSLDiag,
checkxDSLDiagAdvanced
};