-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathindex.js
90 lines (81 loc) · 2.42 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
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
const dataModel = {
theme: 'cisco',
step: 'start',
answers: {
comments: '',
name: '',
},
createIncident: false,
incidentNumber: false,
roomName: 'Unknown room',
showQr: false,
busy: false,
init() {
const params = new URLSearchParams(location.search);
const askRating = params.get('askrating');
this.step = askRating ? 'start' : 'whatwaswrong';
this.theme = params.get('theme') || 'cisco';
this.roomName = params.get('roomname');
this.device = params.get('device');
this.createQrCode();
},
createQrCode() {
const url = location.href;
new QRCode(document.getElementById("qr-code"), url);
},
answer(step, choice) {
this.answers[step] = choice;
if (step === 'start') {
if (choice === 'notgood') {
this.step = 'whatwaswrong';
}
else {
this.step = 'done';
}
}
else if (step === 'whatwaswrong') {
this.step = 'moreinfo';
}
},
back() {
if (this.step === 'moreinfo') {
this.step = 'whatwaswrong';
}
},
async submit() {
const { whatwaswrong, comments, name } = this.answers;
const { roomName, device } = this;
this.createIncident = true;
this.busy = true;
this.incidentNumber = await createReport(whatwaswrong, comments, name, roomName, device);
this.busy = false;
console.log('created', this.incidentNumber);
this.step = 'done';
this.notifyWithWebex(this.incidentNumber, whatwaswrong, comments, name, roomName, device);
},
async notifyWithWebex(id, category, comments, name, roomName, device) {
const params = new URLSearchParams(location.search);
const bot = params.get('webextoken');
const notify = params.get('notify');
const instance = params.get('i');
console.log({ bot, notify });
const url = `${instance}.service-now.com/incident.do?sysparm_query=number=${id}`;
let msg = `New ServiceNow incident created\n`;
msg += `\n* Id: **${id}**`;
msg += `\n* Category: **${category}**`;
msg += `\n* comments: **${comments}**`;
msg += `\n* Room: **${roomName}**`;
msg += `\n* Device: **${device}**`;
msg += `\n* Reporter: **${name}**`;
msg += `\n\nYou can log in to [${url}](https://${url}) to view the details.`;
if (bot && notify) {
try {
await sendMessage(bot, notify, msg);
}
catch(e) {
alert('Unable to send Webex message to ' + notify);
console.log(e);
}
}
}
}