@@ -80,7 +80,7 @@ <h1 class="mb-3 mb-md-0 hero-heading mb-0">Test our chatBot client</h1>
80
80
$ ( window ) . load ( function ( ) {
81
81
$messages . mCustomScrollbar ( ) ;
82
82
{ % if user . is_authenticated % }
83
- insertResponseMessage ( 'Hi {{ user.username }}, I\'m your Personal Concierge. How can I help? ' ) ;
83
+ insertResponseMessage ( 'Hi {{ user.username }}, I’m a virtual assistant that can help you find COVID-19 compliant restaurants. ' ) ;
84
84
{ % endif % }
85
85
} ) ;
86
86
@@ -120,7 +120,7 @@ <h1 class="mb-3 mb-md-0 hero-heading mb-0">Test our chatBot client</h1>
120
120
if ( m != d . getMinutes ( ) ) {
121
121
m = d . getMinutes ( ) ;
122
122
}
123
- $ ( '<div class="media col-md-9 col-xl-7 ml-auto mb-3"><div class="media-body mr-3"><div class="bg-primary rounded p-4 mb-2"><p class="text-sm mb-0 text-white">' + msg + '</p></div><p class="small ml-3">' + d . getHours ( ) + ':' + m + '</p></div><img class="avatar avatar-border-white" src="https://d19m59y37dris4.cloudfront.net/directory/1-6/img/avatar/avatar-10.jpg " alt="user" /></div>' ) . appendTo ( $ ( '.mCSB_container' ) ) . addClass ( 'new' ) ;
123
+ $ ( '<div class="media col-md-9 col-xl-7 ml-auto mb-3"><div class="media-body mr-3"><div class="bg-primary rounded p-4 mb-2"><p class="text-sm mb-0 text-white">' + msg + '</p></div><p class="small ml-3">' + d . getHours ( ) + ':' + m + '</p></div><img class="avatar avatar-border-white" src="https://dine-safely.s3.amazonaws.com/icon-user-1.png " alt="user" /></div>' ) . appendTo ( $ ( '.mCSB_container' ) ) . addClass ( 'new' ) ;
124
124
$ ( '.message-input' ) . val ( '' ) ;
125
125
updateScrollbar ( ) ;
126
126
@@ -136,10 +136,17 @@ <h1 class="mb-3 mb-md-0 hero-heading mb-0">Test our chatBot client</h1>
136
136
137
137
for ( var message of messages ) {
138
138
if ( message . type === 'unstructured' ) {
139
- insertResponseMessage ( message . unstructured . text ) ;
139
+
140
+ // Got json from aws
141
+ if ( message . unstructured . text [ 0 ] == "{" ) {
142
+ var aws_data = JSON . parse ( message . unstructured . text ) ;
143
+ insertResponseMessageWithFilter ( aws_data ) ;
144
+ } else {
145
+ insertResponseMessage ( message . unstructured . text ) ;
146
+ }
147
+
140
148
} else if ( message . type === 'structured' && message . structured . type === 'product' ) {
141
149
var html = '' ;
142
-
143
150
insertResponseMessage ( message . structured . text ) ;
144
151
145
152
setTimeout ( function ( ) {
@@ -174,6 +181,33 @@ <h1 class="mb-3 mb-md-0 hero-heading mb-0">Test our chatBot client</h1>
174
181
return false ;
175
182
}
176
183
} )
184
+ function insertResponseMessageWithFilter ( filter ) {
185
+ console . log ( filter ) ;
186
+ $ . ajax ( {
187
+ type : 'POST' ,
188
+ url : '../restaurant/chatbot/keywordtest' ,
189
+ data : JSON . stringify ( filter ) ,
190
+ contentType : 'application/json; charset=UTF-8' ,
191
+ dataType : 'json' ,
192
+ success : function ( data ) {
193
+ if ( data [ 'restaurants' ] . length == 0 ) {
194
+ insertResponseMessage ( "Sorry, we couldn't find any compliant restaurants based on your inputs." ) ;
195
+ } else {
196
+ let recommend_restaurants_str = "Here, I found some highly-rated restaurant(s) for you!<br>" ;
197
+ for ( var i = 0 ; i < data [ 'restaurants' ] . length ; i ++ ) {
198
+ recommend_restaurants_str += "<a target='_blank' href=" + "https://dine-safe-ly.herokuapp.com/restaurant/profile/" + data [ 'restaurants' ] [ i ] [ 'id' ] . toString ( ) + ">" + data [ 'restaurants' ] [ i ] [ 'restaurant_name' ] . toString ( ) + "</a>" ;
199
+ recommend_restaurants_str += "<br>" ;
200
+ }
201
+ insertResponseMessage ( recommend_restaurants_str ) ;
202
+ }
203
+
204
+
205
+
206
+ } ,
207
+ error : function ( xhr , type ) {
208
+ }
209
+ } ) ;
210
+ }
177
211
178
212
function insertResponseMessage ( content ) {
179
213
$ ( '<div class="message loading new"><figure class="avatar"><img src="https://media1.tenor.com/images/672b62d967f8d00d608d22f36c1831db/tenor.gif" width="25px" height="25px" /></figure><span></span></div>' ) . appendTo ( $ ( '.mCSB_container' ) ) ;
@@ -185,7 +219,7 @@ <h1 class="mb-3 mb-md-0 hero-heading mb-0">Test our chatBot client</h1>
185
219
if ( m != d . getMinutes ( ) ) {
186
220
m = d . getMinutes ( ) ;
187
221
}
188
- $ ( '<div class="media col-md-9 col-xl-7 mb-3"><img class="avatar avatar-border-white" src="https://d19m59y37dris4.cloudfront.net/directory/1-6/img/avatar/avatar-1.jpg " alt="user"><div class="message media-body ml-3"><div class="bg-gray-200 rounded p-4 mb-2"><p class="text-sm mb-0">' + content + '</p></div><p class="small ml-3">' + d . getHours ( ) + ':' + m + '</p></div>' ) . appendTo ( $ ( '.mCSB_container' ) ) . addClass ( 'new' ) ;
222
+ $ ( '<div class="media col-md-9 col-xl-7 mb-3"><img class="avatar avatar-border-white" src="https://dine-safely.s3.amazonaws.com/icons8-chatbot-80.png " alt="user"><div class="message media-body ml-3"><div class="bg-gray-200 rounded p-4 mb-2"><p class="text-sm mb-0">' + content + '</p></div><p class="small ml-3">' + d . getHours ( ) + ':' + m + '</p></div>' ) . appendTo ( $ ( '.mCSB_container' ) ) . addClass ( 'new' ) ;
189
223
190
224
updateScrollbar ( ) ;
191
225
i ++ ;
0 commit comments