-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathchatbot.html
200 lines (179 loc) · 5.59 KB
/
chatbot.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
<!DOCTYPE html>
<head>
<meta name="viewport" content="width=device-width,initial-scale=1.0">
<title>chatBot</title>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.4.0/css/font-awesome.min.css">
<style>
::-webkit-scrollbar{
width: 0;
}
*{
margin:0;
padding:0;
box-sizing: border-box;
}
body{
width:100vw;
height: 100vw;
display:grid;
justify-content: center;
overflow: hidden;
}
h2{
text-align: center;
font-family:sans-serif;
background: #1c1c46;
color:#fff;
padding: 8px;
text-shadow: 1px 1px 4px #111;
margin-bottom: 8px;
}
#msg_area{
height:40%;
padding: 0 12%;
overflow-y:scroll;
scroll-behavior: smooth;
}
#bot{
width:50px;
height: 50px;
background:url("https://support.upwork.com/hc/article_attachments/360040474034/chatbot-data.png");
background-size: 100%;
border-radius:50%;
margin:10px;
}
#robot{
display:flex;
align-items:center;
}
#main{
width: 100vw;
max-width: 540px;
height: 100vw;
box-shadow: inset 0 0 10px 4px black;
}
h3{
font-family:monospace;
font-size:20px;
}
#input{
height:3%;
min-height:1%;
display:grid;
grid-template-columns:70% 30%;
margin:8px 16px;
border-radius:32px;
background: linear-gradient(#ececee 50%,green 50%);
box-shadow: inset 0 1px 0 #777;
}
#text{
outline: none;
font-size:20px;
background:#ececee;
color:#333;
border-radius: 10px 0 10px 10px;
padding :0 2px;
border:solid 1px #777;
border-right:none;
}
#send{
outline:none;
font-size: 20px;
color:#eee;
background:green;
border-radius:32px;
transition-duration: 0.2s;
}
#send:active{
font-size:16px;
}
.left, .right{
font-size:18px;
font-family:monospace;
display:inline-black;
width:auto;
max-width:60%;
padding:14px;
word-wrap:break-word;
}
.left{
color:#000;
background: #b3bfca;
border-radius:0 16px 16px 16px;
}
.right{
color:#fff;
background:#1c1f46;
border-radius:16px 16px 0 16px;
float:right;
}
.msgCon1, .msgCon2{
width:100%;
display:inline-block;
}
</style>
</head>
<body onload="start()">
<div id="main">
<h2>AfyaChat</h2>
<div id="msg_area">
<div id="robot">
<div id="bot">
<!--<img src="https://support.upwork.com/hc/article_attachments/360040474034/chatbot-data.png">... --></div>
<h2>doctar GEORGE chat</h2>
</div>
</div>
<div id="input">
<input type="text" placeholder="New Message" id="text">
<button id="send" >Send<i class="fa fa-paper-plane"></i></button>
</div>
</div>
<footer>
<p>© 2021 GitHub, Inc.</p>
</footer>
<script src="https://cdn.jsdelivr.net/npm/axios/dist/axios.min.js"></script>
<script>
function start(){
res_msg=document.createElement('div');
res_msg.innerHTML="hello NUHU, how can i help you?";
res_msg.setAttribute("class","left");
document.getElementById('input').appendChild(res_msg);
}
document.getElementById('send').addEventListener("click",async(e) =>
{
e.preventDefault();
var req=document.getElementById('text').value;
if(req==undefined || req==""){
}else{
let res="";
axios.get('https://api.monkedev.com/fun/chat?msg=${req}').then(data=>{
res=JSON.stringify(data.data.response)
})
let msg_req=document.createElement('div');
let msg_res=document.createElement('div');
let con1=document.createElement('div');
let con2=document.createElement('div');
con1.setAttribute("class","msgcon1");
con2.setAttribute("class","msgcon2");
msg_req.innerHTML=req;
msg_res.innerHTML=res;
msg_req.setAttribute("class","right");
msg_res.setAttribute("class","left");
let Message=document.getElementById('msg_area');
Message.appendChild(con1);
Message.appendChild(con2);
con1.appendChild(msg_req);
con2.appendChild(msg_res);
document.getElementById('text').value="";
//var scrollMsg=document.getElemetById('msg_area');
var scrollMsg=document.querySelector("#msg_area");
function scroll(){
scrollMsg.scrollTop= scrollMsg.scrollHeight;
}
scroll();
}
}
);
</script>
</body>
</html>