-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
485 lines (315 loc) · 12.5 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
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
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
<!DOCTYPE html>
<html>
<head>
<meta name="google-site-verification" content="ZXJxKgipGpG7zuAuLxJCc-0wLeDpXdzMhOmDQkxaXDc" />
<meta property="og:title" content="DanfoBot">
<meta property="og:site_name" content="DanfoBot">
<meta property="og:url" content="https://www.danfobot.com/">
<meta property="og:description" content="Chatbot for checking estimate traffic and travel time in Lagos">
<meta property="og:type" content="article">
<meta property="og:image" content="https://res.cloudinary.com/memeafrica/image/upload/v1560005908/6c2ee3e2-0ecb-4a86-998f-940bc523e762.png">
<meta name="title" content="Lagos traffic Assistant">
<meta name="description" content="Lagos traffic Assistant">
<meta name="keywords" content="Lagos traffic, Lagos, traffic chatbot, traffic assistant">
<meta name="robots" content="index, follow">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta name="language" content="English">
<meta name="author" content="Abiodun Adetona">
<meta name="twitter:card" content="summary_large_image">
<meta name="twitter:title" content="Lagos Traffic Assistant">
<meta name="twitter:site" content="@adetona77">
<meta name="twitter:description" content="Chatbot for checking estimate traffic and travel time in Lagos">
<meta name="twitter:image" content="https://res.cloudinary.com/memeafrica/image/upload/v1560005908/6c2ee3e2-0ecb-4a86-998f-940bc523e762.png">
<meta name="theme-color" content="#FFBF00"/>
<link rel="icon" href="https://res.cloudinary.com/memeafrica/image/upload/c_scale,e_make_transparent:10,h_192,w_192/v1560005908/6c2ee3e2-0ecb-4a86-998f-940bc523e762.png">
<title>
DanfoBot - Lagos Traffic Assistant.
</title>
<!-- Global site tag (gtag.js) - Google Analytics -->
<script async src="https://www.googletagmanager.com/gtag/js?id=UA-140632101-1"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', 'UA-140632101-1');
</script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, minimum-scale=1">
<link href="https://fonts.googleapis.com/css?family=Lato&display=swap" rel="stylesheet">
<!--link rel="stylesheet" type="text/css" href="dist/jquery.convform.css"-->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.8.2/css/all.css" integrity="sha384-oS3vJWv+0UjzBfQzYUhtDYW+Pj2yciDJxpsK1OYPAYjqT085Qq/1cq5FLXAZQ7Ay" crossorigin="anonymous">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.8.2/css/all.css">
<link rel="manifest" href="manifest.json">
<script src="public/test.js"></script>
<!--link rel="stylesheet" href="../style.cs"-->
<script>
/*if (location.protocol != 'https:'){
location.href = 'https:' + window.location.href.substring(window.location.protocol.length);
}*/
if(location.hostname != "localhost" && location.protocol != 'https:'){
location.href = 'https:' + window.location.href.substring(window.location.protocol.length);
}
</script>
<script
src="https://maps.googleapis.com/maps/api/js?key=AIzaSyBTo0RgT_iA87Hd76gX8zYixB3PZh3z454">
</script>
<style>
body{
background: #F5F5F5;
font-family: 'Lato', sans-serif;
font-size: 17px;
}
.danfo-header{
background-color: #FFBF00;
font-weight: bold;
height: 70px;
color: white;
}
.messageBox{
/* position: relative;
bottom: 0;
width: 100%;
border-bottom: 0px;
border-left: 0px;
border-right: 0px;
font-size: 16px;
border-top-color: gray;*/
position: fixed;
bottom: 0;
width: 100%;
font-size: 17px;
border-bottom: 0px;
border-left: 0px;
border-right: 0px;
border-top-color: gray;
/*margin-left: 2px;*/
}
input {
outline:none;
height: 50px;
}
.logo{
/*color: white;*/
font-weight: bold;
padding-top: 10px;
font-size: 20px;
}
.danfoMsg{
position: relative;
background: #fff;
margin-left: 50px;
min-width: 30%;
padding: 10px 15px;
border-radius: 6px;
border: 1px solid #fff;
float: left;
right: 20px;
font-size: 17px;
/*color: white;*/
}
.danfoMsg::before{
content: '';
position: absolute;
visibility: visible;
top: -1px;
left: -10px;
border: 10px solid transparent;
border-top: 10px solid #fff;
}
.danfo-row{
margin-top: 20px;
}
/*Mobile css for bot response*/
@media only screen and (max-width: 600px) {
.danfoMsg{
position: relative;
background: #fff;
margin-left: 50px;
min-width: 300px;
padding: 10px 15px;
border-radius: 6px;
border: 1px solid #fff;
float: left;
right: 20px;
font-size: 15px;
/*color: white;*/
}
}
.userMsg {
position: relative;
background: #333333;
min-width: 25%;
padding: 10px 15px;
border-radius: 6px;
border: 1px solid #333333;
float: right;
right: 20px;
color: white;
margin-left: 30px;
}
.userMsg::before {
content: '';
position: absolute;
visibility: visible;
top: -1px;
right: -10px;
border: 10px solid transparent;
border-top: 10px solid #333333;
}
.user-row{
margin-top: 20px;
}
#DanfoName{
margin-top: 10px;
}
</style>
</head>
<body>
<div class="container-fluid chatBody">
<div class="row danfo-header">
<div class="col-md-1 col-sm-1 col-xs-1" style="width: 70px">
<img src="https://res.cloudinary.com/memeafrica/image/upload/c_scale,e_make_transparent:10,h_60,w_50/v1560005908/6c2ee3e2-0ecb-4a86-998f-940bc523e762.png" alt="DanfoBot logo" style="border-radius: 50; margin-top: 5px;">
</div>
<div class="col-md-1 col-sm-1 col-xs-1">
<p id="DanfoName">DanfoBot</p><span style="font-size: 10px">Online</span>
</div>
</div>
<div class="row danfo-row">
<p class="danfoMsg">👋 Hi, I'm DanfoBot.</p>
</div>
<div class="row">
<p class="danfoMsg">I can help check traffic time and average estimated travel time between places in Lagos(eg: traffic from Lekki to Yaba)</p>
</div>
</div>
</div>
<div class="container-fluid">
<div class="row">
<form method="GET">
<input type="text" placeholder="Ask DanfoBot.(eg. traffic from VI to Yaba)" class="messageBox" id="messageBox"/>
</form>
</div>
</div>
</body>
<script type="text/javascript">
$("form").submit(function(event){
event.preventDefault()
//the box where user type in.
var messageBox = $('.messageBox').val();
//extract the origin from the sentence
var extractOrigin = messageBox.split(" ");
//get the second value in the array (traffic from ikeja to vi)
var extractOrigin = extractOrigin[2];
//var extractD = extractOrigin[2];
//extract the destination from the sentence
var extractD = messageBox.split(" ");
//get the fourth value in the array (traffic from ikeja to vi) -
var extractD = extractD[4];
var destination1 = extractD;
var origin = extractOrigin;
//console.log(extractOrigin);
//extractOrigin;
var extractDestination = messageBox.split('to')[1]
var destination = extractDestination;
//api to convert user address to Nigeria address.
var desUrl = "https://maps.googleapis.com/maps/api/geocode/json?address={address}&components=country:NG&key=AIzaSyBfAfFm5WrfIpvpp02i9Qzjt7Zq7rp6Qyk";
var destination = desUrl.replace("{address}", destination);
var origin = origin;
//api to convert user address to Nigeria address.
var originUrl = "https://maps.googleapis.com/maps/api/geocode/json?address={address}&components=country:NG&key=AIzaSyBfAfFm5WrfIpvpp02i9Qzjt7Zq7rp6Qyk";
var origin = originUrl.replace("{address}", origin);
$.when( $.ajax(origin), $.ajax(destination) ).done(function(origin, destination) {
var userQuery = messageBox.split(" ");
var userQuery = userQuery[0].toLowerCase(); //convert to lowercase
var checkTraffic = userQuery.substring(0, 3); //check if the 3 words contains "tra"
//user message
var message = '<div class="row">' + '<p class="userMsg">' + $('.messageBox').val() + '</p>' + '</div>';
if(userQuery == "traffic" || checkTraffic == "tra"){
var origin = origin[0].results[0].formatted_address;
var destination = destination[0].results[0].formatted_address;
console.log(origin);
console.log(destination);
$('.chatBody').append(message);
$('.messageBox').val('');
}
function callback(response, status) {
if (status == 'OK') {
var origins = response.originAddresses;
var destinations = response.destinationAddresses;
for (var i = 0; i < origins.length; i++) {
var results = response.rows[i].elements;
for (var j = 0; j < results.length; j++) {
var element = results[j];
var distance = element.distance.text;
var duration = element.duration.text;
var traffic = element.duration_in_traffic.text;
var from = origins[i];
var to = destinations[j];
console.log('The traffic time is ' + traffic);
console.log('The duration is ' + duration);
console.log('The distance is ' + distance);
var whatsapp = 'From ' + '_' + origin + '_' + ' to ' + '_' + destination + '_' + '%20%0A' + 'Distance:%20' + distance + '%20%0AEstimated travel time:%20' + duration + '%20%0ACurrent travel time:' + traffic + '%20%0A(via Danfobot.com)';
var reply = '<div class="row">' + '<div class="danfoMsg" style="width: 150px">' + '<p>' + 'From ' + '<i>' + origin + '</i>' + ' to ' + '<i>' + destination + '</i>' + '</p>' + '<p>' + 'Distance: ' + distance + '</p>' + '<p>' + 'Estimated travel time: ' + duration + '</p>' + '<p>' + 'Current travel time: ' + traffic + '</p>' + '<p>' + "(Live traffic data from Google)" + '</p>' + "Share:" +
'<a href="https://api.whatsapp.com/send?text='+ whatsapp +'" target="_blank"><img src="https://img.icons8.com/color/48/000000/whatsapp.png" style="width: 20px; height: 20px"></a>' + '</div>' + '</div>';
$('.chatBody').append(reply);
}
}
}
}
var service = new google.maps.DistanceMatrixService();
service.getDistanceMatrix(
{
origins: [origin],
destinations: [destination],
travelMode: 'DRIVING',
drivingOptions: {
departureTime: new Date(Date.now()), // for the time N milliseconds from now.
trafficModel: 'bestguess'
},
unitSystem: google.maps.UnitSystem.METRIC,
}, callback);
function botReply() {
if(userQuery != "traffic" && checkTraffic != "tra" ){
var reply = '<div class="row">' + '<p class="danfoMsg">' + 'Wrong input or non-existing location. type "traffic from {current location} to {Destination}" for the traffic status.(eg.traffic from Maryland to Lekki) "' + '</p>' + '</div>';
$('.chatBody').append(message);
$('.chatBody').append(reply);
}
/*else{
var reply = '<div class="row">' + '<p class="danfoMsg">' + "I'm sorry, I didn't understand. Type FROM {current location} to {Destination} for the traffic status. (eg. From Obalende to Ikeja)" + '</p>' + '</div>';
$('.chatBody').append(message);
$('.chatBody').append(reply);
}*/
}
if (messageBox == ""){
return false;
//alert('Empty Box')
}else{
botReply();
$('.messageBox').val('');
document.getElementById("messageBox").blur();
return false;
}
});
}); //end form submission
</script>
<script>
let deferredPrompt;
window.addEventListener('beforeinstallprompt', (e) => {
// Prevent Chrome 67 and earlier from automatically showing the prompt
e.preventDefault();
// Stash the event so it can be triggered later.
deferredPrompt = e;
});
</script>
<script>
if('serviceWorker' in navigator) {
window.addEventListener('load', function(){
navigator.serviceWorker
.register('service-worker.js')
.then(function() { console.log("Service Worker Registered"); });
});
}
</script>
</html>