Skip to content

Instantly share code, notes, and snippets.

@phm200
Created September 11, 2018 21:16
Show Gist options
  • Save phm200/10c21a026f260300cc3c5e2b7e935e0d to your computer and use it in GitHub Desktop.
Save phm200/10c21a026f260300cc3c5e2b7e935e0d to your computer and use it in GitHub Desktop.
Connect User API Epress App - index.js
const express = require("express");
const app = express();
const AWS = require("aws-sdk");
require("express-async-errors");
const connectInstanceId = "7f03...";
var connectClient = new AWS.Connect({
apiVersion: "2017-08-08",
region: "us-east-1"
});
// serve static content from public directory
app.use(express.static("public"));
// 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.listen(3000, () => console.log("App listening on port 3000!"));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment