PluginProbe
WPBot – AI ChatBot for Live Support, Lead Generation, WordPress Automation, AI Services / 8.7.5
WPBot – AI ChatBot for Live Support, Lead Generation, WordPress Automation, AI Services v8.7.5
8.7.7 8.7.6 8.7.5 8.7.4 8.7.3 8.7.2 8.7.1 8.7.0 8.6.9 8.6.8 8.6.7 8.6.6 8.6.5 8.6.4 8.6.2 8.6.1 8.6.0 8.5.9 8.5.8 8.5.7 8.5.6 8.5.5 8.5.4 8.5.3 8.5.2 All 533 releases
chatbot / includes / chat-sessions / js / admin.js

admin.js in WPBot – AI ChatBot for Live Support, Lead Generation, WordPress Automation, AI Services 8.7.5, at includes/chat-sessions/js/admin.js

424 lines 15.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 jQuery(document).ready(function(){
2 'use strict'
3 //start new-update-for-codecanyon
4 jQuery('#qcld_chatsessions_enter_license_or_purchase_key').on('focusout', function(){
5 qc_chatsessions_set_plugin_license_fields();
6 });
7
8 jQuery('#qcld_chatsessions_enter_license_or_purchase_key').on('keypress',function (e) {
9 qc_chatsessions_set_plugin_license_fields();
10 });
11
12 jQuery('#qc-license-form input[type="submit"]').on('click', function(){
13 qc_chatsessions_set_plugin_license_fields();
14 jQuery('#qc-license-form').removeAttr('onsubmit').submit();
15 });
16
17 function qc_chatsessions_set_plugin_license_fields(){
18 var license_input = jQuery('#qcld_chatsessions_enter_license_or_purchase_key').val();
19 if( /^(\w{8})-((\w{4})-){3}(\w{12})$/.test(license_input) ){
20 jQuery('input[name="qcld_chatsessions_buy_from_where"]').val('codecanyon');
21 jQuery('input[name="qcld_chatsessions_enter_envato_key"]').val(license_input);
22 }else{
23 jQuery('input[name="qcld_chatsessions_buy_from_where"]').val('quantumcloud');
24 jQuery('input[name="qcld_chatsessions_enter_license_key"]').val(license_input);
25 }
26 }
27 function htmlspecialchars_decode(text) {
28 const parser = new DOMParser();
29 const doc = parser.parseFromString(text, 'text/html');
30 return doc.documentElement.textContent;
31 }
32 var session_hover_state = '';
33 const modal = document.getElementById("session_details_modal");
34 jQuery('.session_detail_hover').hover(function(e) {
35 var self = this;
36 var hoverTimer = '';
37 const modal = document.getElementById("session_details_modal");
38
39 window.onclick = function(event) {
40 if (event.target == modal) {
41 modal.style.display = "none";
42 }
43 }
44 if(session_hover_state == ''){
45 session_hover_state = 1;
46 modal.style.display = "none";
47 jQuery('.details_modal_body').html('');
48 modal.style.left = '';
49 modal.style.top = '';
50 setTimeout(function() {
51 modal.style.display = "block";
52 jQuery('.loader-mask').show();
53 jQuery('.loader').show();
54 jQuery.ajax({
55 url: ajax_object.ajax_url,
56 type: 'POST',
57 dataType: "JSON",
58 data: {
59 action : 'wpbot_session_hover_details',
60 security: ajax_object.ajax_nonce,
61 session_id: jQuery(self).attr('data-id'),
62 },
63 success: function (response) {
64 jQuery('.loader').fadeOut();
65 jQuery('.loader-mask').delay(350).fadeOut('slow');
66 // SECURITY FIX: Server now returns sanitized HTML (wp_kses output).
67 // Do NOT run htmlspecialchars_decode() on conversation data before .html();
68 // that decode-then-inject pattern was the DOM XSS sink.
69 let htmlString = response.conversation;
70 let doc = '<div class="session-details-sction-modal">' ;
71 doc += htmlString;
72 doc += '</div>';
73 if (response.email) {
74 doc += '<div class="email-reply-container">' +
75 '<p class="email-reply-meta">Reply via <strong>Email to:</strong> ' + response.email + ' <strong>From:</strong> <input type="email" id="reply_from_email" class="form-control" value="' + ( response.email_from ? '' + response.email_from : '' ) + '"></p>' +
76 '<div class="form-group mb-2">' +
77 '<input type="text" id="reply_subject" class="form-control" placeholder="Reply to your chat session">' +
78 '</div>' +
79 '<div class="form-group mb-2">' +
80 '<textarea id="reply_message" class="form-control" rows="4" placeholder="Type your reply here..."></textarea>' +
81 '</div>' +
82 '<button type="button" class="btn btn-primary" id="btn_send_reply_email" data-email="' + response.email + '">Send Reply</button>' +
83 '</div>';
84 } else {
85 doc += '<div class="email-reply-container">' +
86 '<p class="email-reply-warning">Enable Asking for Email to get email reply option</p>' +
87 '</div>';
88 }
89 jQuery('.details_modal_body').html(doc);
90 session_hover_state = '';
91 // location.reload();
92 },
93 });
94 }, 100);
95 }
96 });
97 jQuery('#chatsession-table').on('click', '.show_details_click', function(e) {
98 var self = this;
99 const modal = document.getElementById("session_details_modal");
100
101 window.onclick = function(event) {
102 if (event.target == modal) {
103 modal.style.display = "none";
104 }
105 }
106 if(session_hover_state == ''){
107 session_hover_state = 1;
108 modal.style.display = "none";
109 jQuery('.details_modal_body').html('');
110 modal.style.left = '';
111 modal.style.top = '';
112
113 if (typeof Swal !== 'undefined') {
114 Swal.fire({
115 html: '<div class="qcld-save-settings-spinner"></div>',
116 allowOutsideClick: false,
117 allowEscapeKey: false,
118 showConfirmButton: false,
119 background: 'transparent',
120 customClass: {
121 popup: 'qcld-swal-loading-only'
122 }
123 });
124 }
125
126 jQuery.ajax({
127 url: ajax_object.ajax_url,
128 type: 'POST',
129 dataType: "JSON",
130 data: {
131 action : 'wpbot_session_hover_details',
132 security: ajax_object.ajax_nonce,
133 session_id: jQuery(self).attr('data-id'),
134 },
135 success: function (response) {
136 if (typeof Swal !== 'undefined') {
137 Swal.close();
138 }
139 // SECURITY FIX: Server now returns sanitized HTML (wp_kses output).
140 // Do NOT run htmlspecialchars_decode() on conversation data before .html();
141 // that decode-then-inject pattern was the DOM XSS sink.
142 let htmlString = response.conversation;
143 let doc = '<div class="session-details-sction-modal">' ;
144 doc += htmlString;
145 doc += '</div>';
146 if (response.email) {
147 var replyEmail = response.email || '';
148 var replyEmailText = jQuery('<div>').text(replyEmail).html();
149 var replyEmailLink = '<a href="mailto:' + encodeURIComponent(replyEmail) + '">' + replyEmailText + '</a>';
150 doc += '<div class="email-reply-container">' +
151 '<p class="email-reply-meta">Reply via <strong>Email to:</strong> ' + replyEmailLink + ' <strong>From:</strong> <input type="email" id="reply_from_email" value="' + ( response.email_from ? '' + response.email_from : '' ) + '"></p>' +
152 '<div class="form-group mb-2">' +
153 '<input type="text" id="reply_subject" class="form-control" placeholder="Reply to your chat session">' +
154 '</div>' +
155 '<div class="form-group mb-2">' +
156 '<textarea id="reply_message" class="form-control" rows="4" placeholder="Type your reply here..."></textarea>' +
157 '</div>' +
158 '<button type="button" class="btn btn-primary" id="btn_send_reply_email" data-email="' + response.email + '">Send Reply</button>' +
159 '</div>';
160 } else {
161 doc += '<div class="email-reply-container">' +
162 '<p class="email-reply-warning">To email this user and chat session, enable Asking for Email in General Settings</p>' +
163 '<p class="email-reply-meta">Reply via <strong>Email to:</strong> ' + (response.email || '') + ' <strong>From:</strong> <input type="email" id="reply_from_email" disabled value="' + ( response.email_from ? '' + response.email_from : '' ) + '"></p>' +
164 '<div class="form-group mb-2">' +
165 '<input type="text" id="reply_subject" disabled class="form-control" placeholder="Reply to your chat session">' +
166 '</div>' +
167 '<div class="form-group mb-2">' +
168 '<textarea id="reply_message" disabled class="form-control" rows="4" placeholder="Type your reply here..."></textarea>' +
169 '</div>' +
170 '<button type="button" disabled class="btn btn-primary" id="btn_send_reply_email" data-email="' + response.email + '">Send Reply</button>' +
171 '</div>';
172 }
173 jQuery('.details_modal_body').html(doc);
174 modal.style.display = "block";
175 session_hover_state = '';
176 },
177 error: function () {
178 if (typeof Swal !== 'undefined') {
179 Swal.close();
180 }
181 session_hover_state = '';
182 }
183 });
184 }
185 });
186 jQuery('#session_details_modal').on('click','.details_session_close',function(){
187 const modal = document.getElementById("session_details_modal");
188 modal.style.display = "none";
189 });
190
191 jQuery(document).on('click', '#btn_send_reply_email', function () {
192 var email = jQuery(this).attr('data-email');
193 var container = jQuery(this).closest('.email-reply-container');
194 var fromEmail = container.find('#reply_from_email').val();
195 var subject = container.find('#reply_subject').val();
196 var message = container.find('#reply_message').val();
197 var btn = jQuery(this);
198
199 if (!message.trim()) {
200 alert('Please enter a message.');
201 return;
202 }
203
204 btn.prop('disabled', true).text('Sending...');
205
206 jQuery.ajax({
207 url: ajax_object.ajax_url,
208 type: 'POST',
209 dataType: "JSON",
210 data: {
211 action: 'wpbot_send_reply_email',
212 security: ajax_object.ajax_nonce,
213 email: email,
214 from_email: fromEmail,
215 subject: subject,
216 message: message
217 },
218 success: function (response) {
219 btn.prop('disabled', false).text('Send Reply');
220 if (response.success) {
221 if (typeof Swal !== 'undefined') {
222 Swal.fire({
223 title: 'Success',
224 text: response.msg,
225 icon: 'success',
226 confirmButtonText: 'OK'
227 });
228 } else {
229 alert(response.msg);
230 }
231 container.find('#reply_message').val('');
232 } else {
233 if (typeof Swal !== 'undefined') {
234 Swal.fire({
235 title: 'Error',
236 text: response.msg,
237 icon: 'error',
238 confirmButtonText: 'OK'
239 });
240 } else {
241 alert(response.msg);
242 }
243 }
244 },
245 error: function() {
246 btn.prop('disabled', false).text('Send Reply');
247 alert('An error occurred. Please try again.');
248 }
249 });
250 });
251 jQuery('#wpchatbot-sessioncorn-settings').on('click','#save_wpsseion_corn_setting',function(){
252 Swal.showLoading();
253 if (jQuery('#is_ai_enabled').is(":checked")){
254 var is_ai_enabled = 1;
255 }else{
256 var is_ai_enabled = 0;
257 }
258 var corn_schedule_interval = jQuery("[id*='corn_schedule_interval'] :selected").val();
259 var qcld_wbsession_corn_starttime = jQuery('#qcld_wbsession_corn_starttime').val();
260 var qcld_wpsession_corn_promt = jQuery('#wpsession_corn_promt').val();
261 jQuery.ajax({
262 url: ajax_object.ajax_url,
263 type: 'POST',
264 dataType: "JSON",
265 data: {
266 action : 'wpbot_seesion_corn_save',
267 security: ajax_object.ajax_nonce,
268 ai_enabled: is_ai_enabled,
269 corn_schedule_interval: corn_schedule_interval,
270 qcld_wbsession_corn_starttime: qcld_wbsession_corn_starttime,
271 qcld_wpsession_corn_promt: qcld_wpsession_corn_promt,
272 },
273 success: function (response) {
274 var cleanResponse = response.response ? response.response.replace(/<br\s*\/?>/gi, '\n').replace(/<\/?[^>]+(>|$)/g, "") : "";
275 var cleanMsg = response.msg ? response.msg.replace(/<br\s*\/?>/gi, '\n').replace(/<\/?[^>]+(>|$)/g, "") : "";
276 Swal.fire({
277 title: cleanMsg,
278 text: cleanResponse,
279 icon: response.icon,
280 width: 450,
281 confirmButtonText: 'Got it',
282 confirmButtonWidth: 100,
283 confirmButtonClass: 'btn btn-lg'
284 }).then(() => {
285 // location.reload();
286 })
287
288 },
289 });
290 })
291 jQuery('#wpchatbot-sessioncorn-mannual').on('click','#swpsseion_mannual_scraper_corn',function(){
292 Swal.showLoading();
293 var wpchatbot_sessioncorn_mannual_number = jQuery('#wpchatbot-sessioncorn-mannual-number').val();
294 jQuery.ajax({
295 url: ajax_object.ajax_url,
296 type: 'POST',
297 dataType: "JSON",
298 data: {
299 action : 'qcld_chatbot_session_mannual_scraper',
300 security: ajax_object.ajax_nonce,
301 wpchatbot_session_mannual_number : wpchatbot_sessioncorn_mannual_number,
302 },
303 success: function (response) {
304 var cleanResponse = response.response ? response.response.replace(/<br\s*\/?>/gi, '\n').replace(/<\/?[^>]+(>|$)/g, "") : "";
305 var cleanMsg = response.msg ? response.msg.replace(/<br\s*\/?>/gi, '\n').replace(/<\/?[^>]+(>|$)/g, "") : "";
306 Swal.fire({
307 title: cleanMsg,
308 text: cleanResponse,
309 icon: response.icon,
310 width: 450,
311 confirmButtonText: 'Got it',
312 confirmButtonWidth: 100,
313 confirmButtonClass: 'btn btn-lg'
314 }).then(() => {
315 // location.reload();
316 })
317 },
318 });
319 })
320
321 //end new-update-for-codecanyon
322 jQuery('#wpcs_form_sessions').on('change', '#is_enabled_session_email_notice', function() {
323 if(this.checked) {
324 jQuery.ajax({
325 url: ajax_object.ajax_url,
326 type: 'POST',
327 dataType: "JSON",
328 data: {
329 action : 'session_email_notification_update',
330 security: ajax_object.ajax_nonce,
331 email_notification: 'checked',
332 },
333 success: function (response) {
334 location.reload();
335 },
336 });
337 }else{
338 jQuery.ajax({
339 url: ajax_object.ajax_url,
340 type: 'POST',
341 dataType: "JSON",
342 data: {
343 action : 'session_email_notification_update',
344 security: ajax_object.ajax_nonce,
345 email_notification: '',
346 },
347 success: function (response) {
348 location.reload();
349 },
350 });
351 }
352 });
353
354 jQuery('#chatsession-table').on('click', '.forward_session', function () {
355 jQuery('.details_modal_body').html('');
356
357 const forwardModal = document.getElementById("session_foward_modal");
358 if (forwardModal) {
359 forwardModal.style.display = "block";
360 jQuery('#details_session_id').val(jQuery(this).attr('data-id'));
361 }
362
363 });
364 jQuery('#session_foward_modal').on('click', '.forward_session_close', function () {
365 const forwardModal = document.getElementById("session_foward_modal");
366 if (forwardModal) {
367 forwardModal.style.display = "none";
368 }
369 });
370
371 jQuery('#session_foward_modal').on('click', '#qcld_details_forward_submit', function () {
372 var session_id = jQuery('#details_session_id').val();
373 jQuery.ajax({
374 url: ajax_object.ajax_url,
375 type: 'POST',
376 dataType: "JSON",
377 data: {
378 action : 'forward_session_to_email',
379 security: ajax_object.ajax_nonce,
380 session_id: session_id,
381 email: jQuery('#details_session_email').val(),
382 subject: jQuery('#details_session_subject').val(),
383 },
384 success: function (response) {
385 jQuery('#session_foward_modal').hide()
386 }
387 });
388 });
389 jQuery('.wp-chatbot-messages-wrapper').on('click', '.forward_session', function () {
390
391 var session_id = jQuery('#details_session_id').val();
392 jQuery.ajax({
393 url: ajax_object.ajax_url,
394 type: 'POST',
395 dataType: "JSON",
396 data: {
397 action : 'forward_session_to_email',
398 security: ajax_object.ajax_nonce,
399 session_id: session_id,
400 email: jQuery('#details_session_email').val(),
401 subject: jQuery('#details_session_subject').val(),
402 },
403 success: function (response) {
404 if(response.success){
405 Swal.fire({
406 title: 'Success',
407 text: response.message,
408 icon: 'success',
409 confirmButtonText: 'OK'
410 });
411 } else {
412 Swal.fire({
413 title: 'Error',
414 text: response.message,
415 icon: 'error',
416 confirmButtonText: 'OK'
417 });
418 }
419 }
420 });
421 });
422
423 });
424