-
Notifications
You must be signed in to change notification settings - Fork 43
/
index.html
99 lines (88 loc) · 3.96 KB
/
index.html
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
<!DOCTYPE html>
<html>
<head>
<title></title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script src="amazon-connect-chat-interface.js"></script>
<script src="backendEndpoints.js"></script>
</head>
<body>
<div>
<section class="section-main" id="section-main" style="position: absolute; float: left; width: 50%;">
<header>
<h1>Amazon Connect - Custom Implementation of Customer Chat</h1>
</header>
<form name="contactDetails" id="contactDetails" style="padding-top: 30px">
<fieldset>
<div>
<table>
<tbody>
<tr>
<td>
<label for="firstName"
style="width: 128px; padding-right: 25px; padding-bottom: 10px;">Name:</label>
</td>
<td>
<input name="firstName" type="text" id="firstName" placeholder="First Name"
style="width:161px;">
</td>
<td style="padding-left: 10px;">
<input type="submit" style="padding-left: 10px;" class="submit" id="startChat"
value="Start Chat"></input>
</td>
</tr>
</tbody>
</table>
</div>
</fieldset>
</form>
</section>
<section class="section-chat" id="section-chat" style="float: right; width: 50%; transition: opacity 1s; opacity: 0;">
<div id="root"></div>
</section>
</div>
<script>
(function () {
connect.ChatInterface.init({
containerId: 'root' // This is the id of the container where you want the widget to reside
});
document.getElementById('contactDetails').addEventListener('submit', function (e) {
e.preventDefault();
customerName = document.getElementById('firstName').value;
if (!customerName) {
alert('you must enter a name & username');
document.getElementById("contactDetails").reset();
} else {
console.log("this is the first name:" + customerName);
document.getElementById("contactDetails").reset();
connect.ChatInterface.initiateChat({
name: customerName,
region,
apiGatewayEndpoint,
contactAttributes: JSON.stringify({
"customerName": customerName
}),
featurePermissions: {
"ATTACHMENTS": false, // this is the override flag from user for attachments
},
supportedMessagingContentTypes: "text/plain,text/markdown", // enable rich messaging
contactFlowId,
instanceId
},successHandler, failureHandler);
}
});
})();
function successHandler(chatSession) {
console.log("success!");
document.getElementById('section-chat').style.opacity = 1;
chatSession.onChatDisconnected(function(data) {
document.getElementById('section-chat').style.opacity = 0;
});
}
function failureHandler(error) {
console.log("There was an error: ");
console.log(error);
}
</script>
</body>