jithenderchoudary commited on
Commit
36ad901
·
verified ·
1 Parent(s): d990892

Update static/script.js

Browse files
Files changed (1) hide show
  1. static/script.js +29 -0
static/script.js CHANGED
@@ -138,3 +138,32 @@ function handleResponse(userInput) {
138
  displayOptions(options);
139
  }
140
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
138
  displayOptions(options);
139
  }
140
  }
141
+ function displayOptions(options) {
142
+ const chatMessages = document.getElementById('chatMessages');
143
+ if (!chatMessages) {
144
+ console.error('Chat messages container not found for options!');
145
+ return;
146
+ }
147
+
148
+ // Display each option as a bot message in the chat
149
+ options.forEach(opt => {
150
+ const messageDiv = document.createElement('div');
151
+ messageDiv.className = 'bot-message'; // This makes the options look like bot messages
152
+ const button = document.createElement('button');
153
+ button.textContent = opt.text;
154
+ button.className = `option-button ${opt.class}`;
155
+
156
+ // When an option is clicked, treat it as a user response and trigger the appropriate handler
157
+ button.onclick = () => {
158
+ addMessage('user', opt.text);
159
+ conversation.push({ role: 'user', message: opt.text });
160
+ setTimeout(() => handleResponse(opt.text), 500);
161
+ };
162
+
163
+ messageDiv.appendChild(button);
164
+ chatMessages.appendChild(messageDiv); // Append the button inside a bot message container
165
+ });
166
+
167
+ // Scroll to the bottom of the chat container
168
+ chatMessages.scrollTop = chatMessages.scrollHeight;
169
+ }