-
Notifications
You must be signed in to change notification settings - Fork 2
/
index.js
110 lines (93 loc) · 3.11 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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
const express = require("express");
const app = express();
const AWS = require("aws-sdk");
require("express-async-errors");
const qMetrics = require("./qMetrics");
const instanceConfig = require("./instanceConfig");
const connectInstanceId = instanceConfig.connectInstanceId;
const connectQArns = instanceConfig.connectQArns;
var connectClient = new AWS.Connect({
apiVersion: "2017-08-08",
region: "us-east-1"
});
// serve static content from public directory
app.use(express.static("public"));
// handle form data
app.use(express.urlencoded({ extended: true }));
// configuration for pug views
app.set("views", "./views");
app.set("view engine", "pug");
// index - list of users
app.get("/", async (req, res) => {
var listUsersParams = {
InstanceId: connectInstanceId
};
var listUsersPromise = connectClient.listUsers(listUsersParams).promise();
var listUsersResponse = await listUsersPromise;
res.render("index", {
title: "Connect Users",
dataList: listUsersResponse.UserSummaryList
});
});
// user detail by user id
app.get("/user/:userId", async (req, res) => {
var userId = req.params.userId;
var describeUserParams = {
InstanceId: connectInstanceId,
UserId: userId
};
var describeUserPromise = connectClient
.describeUser(describeUserParams)
.promise();
var describeUserResult = await describeUserPromise;
res.render("user", {
title: describeUserResult.User.Username,
user: describeUserResult.User
});
});
app.get("/updateAttributes", async (req, res) => {
res.render("updateAttributes", {
title: "Update Contact Attributes"
});
});
app.post("/submit-updateAttributes", async (req, res) => {
const contactId = req.body.contactId;
const flagForFollowUpRaw = req.body.flagForFollowUp; // will equal "on" if checked, undefined if false
const flagForFollowUp = flagForFollowUpRaw && flagForFollowUpRaw === "on";
var updateContactAttributesParams = {
InstanceId: connectInstanceId,
InitialContactId: contactId,
Attributes: {
FlaggedForFollowUp: flagForFollowUp.toString()
}
};
var updateContactAttributesPromise = connectClient
.updateContactAttributes(updateContactAttributesParams)
.promise();
var updateContactAttributesResult = await updateContactAttributesPromise;
console.log("result", updateContactAttributesResult);
res.render("submittedUpdateAttributes", {
title: "Contact Attributes Updated"
});
});
app.get("/currentMetrics", async (req, res) => {
var getCurrentMetricsParams = {
InstanceId: connectInstanceId,
Filters: {
Channels: ["VOICE"],
Queues: connectQArns
},
CurrentMetrics: qMetrics.metricsList,
Groupings: ["QUEUE"]
};
var getCurrentMetricsPromise = connectClient
.getCurrentMetricData(getCurrentMetricsParams)
.promise();
var getCurrentMetricsResult = await getCurrentMetricsPromise;
console.log("current metrics:", JSON.stringify(getCurrentMetricsResult));
res.render("currentMetrics", {
title: "Current Queue Metrics",
metricResults: getCurrentMetricsResult.MetricResults
});
});
app.listen(3000, () => console.log("App listening on port 3000!"));