-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathchatbot.html
218 lines (192 loc) · 6.72 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
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
<!DOCTYPE html>
<html>
<head>
<title> Portfolio Chatbot</title>
<!-- CSS for Cyber Theme Chatbot -->
<style>
body {
font-family: Arial, sans-serif;
background-color: #000;
color: #0f0;
margin: 0;
padding: 20px;
}
.chat-container {
max-width: 600px;
margin: 0 auto;
background-color: #222;
padding: 20px;
border-radius: 10px;
box-shadow: 0 0 20px rgba(0, 255, 0, 0.5);
}
.user-msg {
background-color: #00f;
color: #fff;
padding: 10px;
border-radius: 5px;
margin-bottom: 10px;
}
.bot-msg {
background-color: #0f0;
color: #000;
padding: 10px;
border-radius: 5px;
margin-bottom: 10px;
}
.chat-input {
width: calc(100% - 40px);
padding: 10px;
border: none;
border-radius: 5px;
margin-right: 10px;
}
.send-btn {
background-color: #00f;
color: #fff;
border: none;
padding: 10px 20px;
border-radius: 5px;
cursor: pointer;
}
.send-btn:hover {
background-color: #0f0;
}
</style>
<!DOCTYPE html>
<html lang="en">
<div class="progress">
<div class="progress-bar" style="width: 75%;"></div>
</div>
<style>
.progress {
background-color: #333;
border-radius: 5px;
overflow: hidden;
}
.progress-bar {
width: 0;
height: 20px;
background-color: #0f0;
transition: width 1s ease;
}
</style>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Portfolio </title>
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css">
<link rel="stylesheet" href="adi.css">
</head>
<body>
<nav class="navbar navbar-expand-lg navbar-dark bg-dark fixed-top">
<div class="container">
<a class="navbar-brand" href="#">Gunapriya</a>
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarNav" aria-controls="navbarNav" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse justify-content-end" id="navbarNav">
<ul class="navbar-nav">
<li class="nav-item">
<a class="nav-link" href="adi.html">Home</a>
</li>
<li class="nav-item">
<a class="nav-link" href="about.html">About</a>
</li>
<li class="nav-item">
<a class="nav-link" href="contact.html">Contact</a>
</li>
<li class="nav-item">
<a class="nav-link" href="portfolio.html">Portfolio</a>
</li>
<li class="nav-item">
<a class="nav-link" href="chatbot">Chatbot</a>
</li>
<!-- Add more social media icons as needed -->
</ul>
</div>
</div>
</nav>
<div class="chat-container">
<div class="chat-box" id="chat-box">
<div class="bot-msg">Hello! I'm your Cyber Portfolio Chatbot. How can I assist you today?</div>
</div>
<form id="chat-form">
<input type="text" id="user-input" class="chat-input" placeholder="Type your message...">
<button type="submit" class="send-btn">Send</button>
</form>
</div>
<!-- Dialogflow Client Library -->
<script src="https://www.gstatic.com/dialogflow-console/fast/messenger/bootstrap.js?v=1"></script>
<script>
// Initialize Dialogflow Chatbot
document.addEventListener('DOMContentLoaded', function () {
const chatbox = document.getElementById('chat-box');
const chatForm = document.getElementById('chat-form');
const userInput = document.getElementById('user-input');
// Replace 'YOUR_CLIENT_ACCESS_TOKEN' with your Dialogflow Client Access Token
window.dfMessenger.init({
accessToken: 'YOUR_CLIENT_ACCESS_TOKEN',
chatId: 'chat-box',
htmlBox: chatbox,
});
chatForm.addEventListener('submit', function (e) {
e.preventDefault();
if (!userInput.value) return;
// Display user message in chat
const userMsg = `<div class="user-msg">${userInput.value}</div>`;
chatbox.innerHTML += userMsg;
// Send user message to Dialogflow
window.dfMessenger.sendText(userInput.value);
// Clear input after sending
userInput.value = '';
});
});
chatForm.addEventListener('submit', function (e) {
e.preventDefault();
if (!userInput.value) return;
// Display user message in chat
const userMsg = `<div class="user-msg">${userInput.value}</div>`;
chatbox.innerHTML += userMsg;
// Send user message to Dialogflow
window.dfMessenger.sendText(userInput.value);
// Clear input after sending
userInput.value = '';
});
// Function to handle Dialogflow responses
window.addEventListener('dfMessenger.response', function (event) {
const response = event.detail.response;
const botMsg = `<div class="bot-msg">${response}</div>`;
chatbox.innerHTML += botMsg;
// Check for specific responses and trigger corresponding functions
handlePortfolioQuestions(response);
});
// Function to handle specific portfolio questions
function handlePortfolioQuestions(response) {
if (response.includes('about me')) {
aboutMeResponse();
} else if (response.includes('my projects')) {
myProjectsResponse();
} else if (response.includes('contact information')) {
contactInfoResponse();
}
// Add more conditions for other questions as needed
}
// Functions for Portfolio Responses
function aboutMeResponse() {
const msg = "I am a web developer passionate about creating innovative and visually appealing websites.";
const botMsg = `<div class="bot-msg">${msg}</div>`;
chatbox.innerHTML += botMsg;
}
function myProjectsResponse() {
const msg = "I have worked on various projects including [Project 1], [Project 2], and [Project 3].";
const botMsg = `<div class="bot-msg">${msg}</div>`;
chatbox.innerHTML += botMsg;
}
function contactInfoResponse() {
const msg = "You can contact me at example@email.com.";
const botMsg = `<div class="bot-msg">${msg}</div>`;
chatbox.innerHTML += botMsg;
}
</script>
</body>
</html>