-
Notifications
You must be signed in to change notification settings - Fork 0
/
bot-client.html
319 lines (292 loc) · 13.2 KB
/
bot-client.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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
<!--
Copyright (c) 2016-2017, Oracle and/or its affiliates. All rights reserved.
-->
<div id="page" class="oj-hybrid-applayout-page">
<!-- Content: all other templates will be called from here! -->
<div id="content" class="oj-panel oj-margin ">
<div class="message-container">
<div id="listview" data-bind="if: allItems">
<div
data-bind="template: { name: 'chat_template', foreach: allItems, as: 'item' }"></div>
</div>
<img src="js/jet-composites/bot-client/waitingForText.gif"
style="width: 50px; border-radius: 10px; margin-top: 15px; margin-left: 15px;"
data-bind="visible:waitingForText" />
</div>
</div>
<!-- FOOTER -->
<div id="chatDialogFooter" class="oj-applayout-fixed-bottom" style="width: 98%; position:fixed;">
<div class="oj-flex oj-flex-items-pad" style="width: 100%;">
<div class="oj-flex-item" style="padding-right: 0;">
<input id="text-input" onfocus="scrollpage()" onblur="scrollMinor()" type="text"
data-bind="ojComponent: {
component: 'ojInputText',
value: value,
placeholder: 'Type a message',
optionChange: valueChangeHandler,
rootAttributes: {
style:'max-width:100%'
}
}" />
</div>
<div style="width: 65px; margin-right: 5px;">
<button id="send"
data-bind="click: sendMessage,
ojComponent: {
component:'ojButton',
label: 'Send',
chroming: 'full',
display: 'all'
}"></button>
</div>
</div>
</div>
</div>
<!-- USER prompt option -->
<script type="text/html" id="promt-template-client">
<div class="oj-flex oj-sm-justify-content-flex-end oj-sm-flex-items-initial bubble-right-container ">
<div class="oj-flex-item" style="margin-top: 3px;background: #A0E759; margin-right: 40px; padding: 10px;border-radius: 10px;position:relative; max-width: 85%; margin-left: 40px;">
<img src="css/images/User.png" style="position:absolute;right:-50px;top:0px;width: 40px;height: 40px; margin-right:5px;">
<span class="bubble-right" style="padding:0px;"><span data-bind="html: item.payload"></span></span>
</div>
</div>
</div>
</script>
<!-- BOT Prompt Template -->
<script type="text/html" id="promt-template-bot">
<div data-bind="if: prompts.prompt" class="oj-flex " style="width: 85%" >
<div class="oj-flex" style="width: 100%">
<div class="oj-flex-item bubble-left" data-bind="css:prompts.options ? 'bubble-left-with-options' : ''" >
<span data-bind="html: prompts.prompt"></span>
</div>
</div>
<div data-bind="if: prompts.options" style="width: 100%;margin-right: 2px;">
<div class="options">
<div data-bind="foreach: prompts.options">
<div class="oj-flex oj-sm-justify-content-left" data-bind="css:($index() === ($parent.options.length - 1)) ? 'option-last' : 'option'" >
<div class="flex-item " >
<div data-bind="template: { name: 'option-template'
, data: {clazz:'option-link',prompt:prompt,payload:payload,type:'postback'
,parent:$parentContext.$parents[2]} }"></div>
</div>
</div>
</div>
</div>
</div>
</div>
</script>
<!-- ERROR message template -->
<script type="text/html" id="errorMessage-template">
<div class="oj-flex bubble-right" style="margin: 5px">
<div class="oj-lg-10 oj-md-10 oj-sm-12">
<div class="oj-flex row">
<div class="oj-lg-12 oj-md-12 oj-sm-12">
<span data-bind="html: errorMessage"></span>
</div>
</div>
</div>
</div>
</script>
<!-- Vertical CARDs template -->
<script type="text/html" id="cards-vertical">
<div id="cardsListView"
aria-label="Vertical Cards"
data-bind="ojComponent: {component: 'ojListView', selectionMode: 'none'
, rootAttributes:{class:'card'}}">
<!-- ko foreach: cards -->
<li data-bind="attr: { id: 'prefix_' + $index() }">
<div class="oj-flex ">
<div class="oj-flex-item">
<div class="oj-flex">
<div class="oj-flex-item" data-bind="if: $data && $data.hasOwnProperty('title')">
<span class="card-title" data-bind="html: title" class="name"></span>
</div>
</div>
<div class="oj-flex">
<div class="oj-flex-item" data-bind="if: $data && $data.hasOwnProperty('subTitle')">
<span class="card-sub-title" data-bind="html: subTitle" ></span>
</div>
</div>
<div class="oj-flex">
<div class="oj-flex-item" data-bind="if: $data && $data.hasOwnProperty('cardUrl')">
<a class="card-url" target="_blank" data-bind="text: cardUrl, attr: {href: cardUrl}"></a>
</div>
</div>
<div class="oj-flex">
<div class="oj-flex-item" style="margin-top:10px;" >
<!-- ko if: $data && $data.hasOwnProperty("options") -->
<!-- ko foreach: options -->
<div data-bind="template: { name: 'option-template'
, data: {clazz:'vert-card-link',prompt:prompt,payload:payload,type:'postback'
,parent:$parentContext.$parents[3]} }"></div>
<!-- /ko -->
<!-- /ko -->
</div>
</div>
</div>
<!-- ko if: $data.hasOwnProperty("imageUrl") -->
<div class="oj-flex-item oj-sm-flex-initial " >
<img class="vert-card-image" data-bind="attr: {src: imageUrl}"/>
</div>
<!-- /ko -->
</div>
</li>
<!-- /ko -->
</div>
</script>
<!-- Horizontal CARDs template -->
<script type="text/html" id="cards-horizontal2">
<div id="filmStripDiv"
aria-label="Horizontal Cards"
class="demo-stretch-items"
data-bind="ojComponent: {
component: 'ojFilmStrip',
maxItemsPerPage: 1,
arrowPlacement: 'overlay',
arrowVisibility: $parentContext.$parents[2].currentNavArrowVisibility}">
<!-- ko foreach: cards -->
<div class="card-filmstrip-item">
<div class="oj-flex-items-pad">
<div class="oj-flex">
<div class="oj-flex-item " data-bind="if: $data && $data.hasOwnProperty('imageUrl')">
<img style="max-width:100%;height:auto;" data-bind="attr: {src: imageUrl}"/>
</div>
</div>
<div class="oj-flex ">
<div class="oj-flex-item oj-sm-flex-initial" data-bind="if: $data && $data.hasOwnProperty('title')">
<div class="card-title" data-bind="html: title" class="name"></div>
</div>
</div>
<div class="oj-flex">
<div class="oj-flex-item oj-sm-flex-initial" data-bind="if: $data && $data.hasOwnProperty('subTitle')">
<div class="card-sub-title" data-bind="html: subTitle" ></div>
</div>
</div>
<div class="oj-flex">
<div class="oj-flex-item oj-sm-flex-initial" data-bind="if: $data && $data.hasOwnProperty('cardUrl')">
<a class="card-url" target="_blank" data-bind="text: cardUrl, attr: {href: cardUrl}"></a>
</div>
</div>
<!-- ko if: $data && $data.hasOwnProperty("options") -->
<div class="options card-options">
<!-- ko foreach: options -->
<div class="oj-flex oj-sm-justify-content-center" data-bind="css:($index() === ($parent.options.length - 1)) ? 'option-last' : 'option'" >
<div class="flex-item " >
<div data-bind="template: { name: 'option-template', data: {clazz:'option-link',prompt:prompt,payload:payload,type:'postback',parent:$parentContext.$parents[3]} }"></div>
</div>
</div>
<!-- /ko -->
</div>
<!-- /ko -->
</div>
</div>
<!-- /ko -->
</div>
</script>
<!-- Option Template -->
<script type="text/html" id="option-template">
<!-- ko if: type != 'url' -->
<a id="globalLink" href="#last"
data-bind="css:clazz,text:prompt, click: function() { parent.onClientSelection(prompt, payload,type); }"></a>
<!-- /ko -->
<!-- ko if: type === 'url' -->
<a data-bind="css:clazz,text: prompt, attr: {href: payload.url}" target="_blank" ></a>
<!-- /ko -->
</script>
<script type="text/html" id="attachment">
<div>
<!-- ko if: attachmentType == 'image' -->
<img style="width:85%;height:auto;" data-bind="attr: {src: url}"/>
<!-- /ko -->
<!-- ko if: attachmentType == 'video' -->
<video id="myVideo" width="330" controls="controls">
<source data-bind="attr: {src: url}" type="video/mp4" >
Your browser does not support HTML5 video.
</video>
<!-- /ko -->
<!-- ko if: attachmentType == 'audio' -->
<audio controls="controls" width="330">
<source data-bind="attr: {src: url}" type="audio/mpeg">
Your browser does not support HTML5 audio.
</audio>
<!-- /ko -->
<!-- ko if: attachmentType == 'file' -->
<a data-bind="text: url, attr: {href: url}" target="_blank" ></a>
<!-- /ko -->
</div>
</script>
<!-- CHAT template -->
<script type="text/html" id="chat_template">
<div class="oj-flex-items-pad message-content-container" style="position:relative;" data-bind="if: bot">
<div style="position:absolute; top:15px;">
<img src="img/Robot.png" style="width: 40px;height: 40px;">
</div>
<div data-bind="if: payload.items" style="margin-left:45px;">
<div data-bind="foreach: { data: payload.items, as: 'prompts' }">
<div data-bind="if: $data && $data.hasOwnProperty('type')">
<div data-bind="if: type == 'prompt'">
<div data-bind="template: { name: 'promt-template-bot', data: prompts }"></div>
</div>
<div data-bind="if: type == 'attachment'">
<div data-bind="template: { name: 'attachment', data: prompts }"></div>
</div>
<!-- check the type of the cards from the uihint! vertical/horizontal -->
<div data-bind="if: type == 'cards' && uihints.cardLayout == 'vertical'">
<div data-bind="template: { name: 'cards-vertical', data: prompts }"></div>
<div data-bind="if: prompts.options">
<div class="options">
<div data-bind="foreach: prompts.options">
<div class="oj-flex oj-sm-justify-content-center" data-bind="css:($index() === ($parent.options.length - 1)) ? 'option-last' : 'option'" >
<div class="flex-item " >
<div data-bind="template: { name: 'option-template'
, data: {clazz:'option-link',prompt:prompt,payload:payload,type:'postback'
,parent:$parentContext.$parents[1]} }"></div>
</div>
</div>
</div>
</div>
</div>
</div>
<div data-bind="if: type == 'cards' && uihints.cardLayout == 'horizontal'">
<div data-bind="template: { name: 'cards-horizontal2', data: prompts }"></div>
</div>
</div>
</div>
</div>
<div data-bind="if: payload.hasOwnProperty('globalOptions')">
<!-- global options button -->
<div class="oj-flex oj-sm-justify-content-center" style="margin-top:30px;" >
<!-- ko foreach: payload.globalOptions -->
<div class="flex-item " >
<div data-bind="template: { name: 'option-template'
, data: {clazz:'global-option-link',prompt:prompt,payload:payload,type:'postback'
,parent:$parentContext.$parents[0]} }"></div>
</div>
<!-- /ko -->
</div>
</div>
<div data-bind="if: payload.errorCode">
<div data-bind="template: { name: 'errorMessage-template', data: payload }"></div>
</div>
</div>
<div class="oj-flex-items-pad" style="margin: 5px" data-bind="if: !bot">
<div class="oj-flex">
<div class="oj-flex-item">
<div data-bind="template: { name: 'promt-template-client', data: item }"></div>
</div>
</div>
</div>
</script>
<div id="notSupportedDialogWrapper">
<div style="display: none" id="notSupportedDialog"
data-bind="ojComponent:{component: 'ojDialog', initialVisibility: 'hide',title:'Not Supported'}">
<div class="oj-dialog-body">
<span data-bind="html:notSupportedMessage"></span>
</div>
<div class="oj-dialog-footer">
<button id="closeDialog"
data-bind="click: closeNotSupportedDialog ,ojComponent: {component: 'ojButton', label: 'OK'}">
</button>
</div>
</div>
</div>