forked from MissionMarsFourthHorizon/operation-max
-
Notifications
You must be signed in to change notification settings - Fork 0
/
default.htm
107 lines (94 loc) · 2.96 KB
/
default.htm
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
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<link href="https://unpkg.com/botframework-webchat/botchat.css" rel="stylesheet" />
<style>
.wc-chatview-panel {
width: 400px;
margin: 0 auto;
border: 1px solid black;
}
aside {
font-size: 12px;
font-family: Arial, Helvetica, sans-serif;
position: absolute;
width: calc((100% - 420px) / 2);
right: 0;
color: #3a96dd;
}
aside div {
color: black;
}
#results h3 {
margin-top: 0;
margin-bottom: 0;
cursor: pointer;
}
#results span {
color: #006621;
}
#results p {
margin-top: 0;
word-wrap: break-word;
font-weight: normal;
}
</style>
</head>
<body>
<div id="bot">
</div>
<aside>
<h1>The user might be interested in some of these related articles:</h1>
<div id="results">
<p>No insights yet!</p>
</div>
</aside>
<script src="https://unpkg.com/botframework-webchat/botchat.js"></script>
<script>
var botConnection = new BotChat.DirectLine({
secret: '{DIRECTLINE_SECRET}'
});
var resPanel = document.getElementById('results');
BotChat.App({
botConnection: botConnection,
user: { id: 'WebChatUser' },
bot: { id: '{BOT_ID}' },
locale: 'en-us',
}, document.getElementById('bot'));
// catch incomming backchannel "event"
botConnection.activity$
.filter(function (activity) {
return activity.type === 'event' && activity.name === 'searchResults';
})
.subscribe(function (activity) {
updateSearchResults(activity.value)
});
function updateSearchResults(results) {
resPanel.innerHTML = ''; // clear
results.forEach(function (result) {
resPanel.appendChild(createSeachResult(result));
});
}
function createSeachResult(result) {
var el = document.createElement('div');
el.innerHTML = '<h3>' + result.title + '</h3>' +
'<p>' + result.text.substring(0, 140) + '...</p>';
el.getElementsByTagName('h3')[0]
.addEventListener('click', function () {
botConnection
.postActivity({
type: 'event',
value: this.textContent.trim(),
from: { id: 'user' },
name: 'showDetailsOf'
})
.subscribe(function (id) {
console.log('event sent', id);
});
});
return el;
}
</script>
</body>
</html>