-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.html
88 lines (80 loc) · 2.26 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
<!DOCTYPE html>
<html>
<head>
<script
crossorigin="anonymous"
src="https://cdn.botframework.com/botframework-webchat/latest/webchat.js"
></script>
<script
crossorigin="anonymous"
src="https://unpkg.com/simple-update-in/dist/simple-update-in.production.min.js"
></script>
<style>
html,
body {
height: 100%;
}
body {
margin: 0;
}
#webchat {
height: 100%;
width: 100%;
}
</style>
</head>
<body>
<div id="webchat" role="main"></div>
<script>
const queryString = window.location.search;
const urlParams = new URLSearchParams(queryString);
const baseUrl = urlParams.get('baseUrl') ?? 'http://localhost:3000/';
const userId = urlParams.get('userId') ?? '1';
const personId = urlParams.get('personId') ?? '1';
const fullName = urlParams.get('fullName') ?? 'Roberto Emilio Placencio Pinto';
fetch(`${baseUrl}v3/directline/tokens/generate`, {
method: 'POST',
headers:{
"Content-Type":"application/json",
},
body: JSON.stringify({
userId: `${userId}-${personId}`,
password: ""
}),
})
.then(res => res.json())
.then(res => {
const styleOptions = {
showAvatarInGroup: false,
botAvatarImage: 'img/bot.png',
botAvatarInitials: 'BF',
userAvatarImage: 'img/user.png',
userAvatarInitials: 'WC'
};
const store = window.WebChat.createStore({}, ({ dispatch }) => next => action => {
if (action.type === 'DIRECT_LINE/POST_ACTIVITY')
{
action = window.simpleUpdateIn(
action,
['payload', 'activity', 'channelData', 'fullName'],
() => fullName
);
}
return next(action);
});
const directLine = window.WebChat.createDirectLine({
domain: `${baseUrl}v3/directline`,
token: res.token,
webSocket: false
});
window.WebChat.renderWebChat({
directLine,
store,
styleOptions,
locale: 'en-US'
}, document.getElementById('webchat'));
document.querySelector('#webchat > *').focus();
});
</script>
</body>
</html>