PluginProbe
WPBot – AI ChatBot for Live Support, Lead Generation, WordPress Automation, AI Services / 8.6.1
WPBot – AI ChatBot for Live Support, Lead Generation, WordPress Automation, AI Services v8.6.1
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.6.1, at includes/chat-sessions/js/admin.js

397 lines 15.5 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 = (jQuery('.session_detail_hover').width() * 2)+'px';
49 setTimeout(function() {
50 modal.style.display = "block";
51 jQuery('.loader-mask').show();
52 jQuery('.loader').show();
53 jQuery.ajax({
54 url: ajax_object.ajax_url,
55 type: 'POST',
56 dataType: "JSON",
57 data: {
58 action : 'wpbot_session_hover_details',
59 security: ajax_object.ajax_nonce,
60 session_id: jQuery(self).attr('data-id'),
61 },
62 success: function (response) {
63 jQuery('.loader').fadeOut();
64 jQuery('.loader-mask').delay(350).fadeOut('slow');
65 let htmlString = response.conversation;
66 let doc = '<div class="session-details-sction-modal">' ;
67 doc += htmlspecialchars_decode(htmlString);
68 doc += '</div>';
69 if (response.email) {
70 doc += '</div><div class="email-reply-container" style="margin-top:20px; padding:15px; border-top:1px solid #ccc; background:#f9f9f9; border-radius: 6px;">' +
71 '<h4 style="margin-top:0;">Reply via Email to: <strong>' + response.email + ' From: ' + (response.email_from ? response.email_from : '****') + '</strong></h4>' +
72 '<div class="form-group mb-2" style="margin-bottom: 10px;">' +
73 '<input type="text" id="reply_subject" class="form-control" style="width:100%; box-sizing:border-box;" value="Reply to your chat session">' +
74 '</div>' +
75 '<div class="form-group mb-2" style="margin-bottom: 10px;">' +
76 '<textarea id="reply_message" class="form-control" rows="4" style="width:100%; box-sizing:border-box;" placeholder="Type your reply here..."></textarea>' +
77 '</div>' +
78 '<button type="button" class="btn btn-primary" id="btn_send_reply_email" data-email="' + response.email + '" style="background:#0d6efd; color:#fff; border:none; padding:8px 16px; border-radius:4px; cursor:pointer;">Send Reply</button>' +
79 '</div>';
80 } else {
81 doc += '<div class="email-reply-container" style="margin-top:20px; padding:15px; border-top:1px solid #ccc; background:#f9f9f9; border-radius: 6px;">' +
82 '<p style="margin:0; color:#d9534f; font-weight:bold;">Enable Asking for Email to get email reply option</p>' +
83 '</div>';
84 }
85 jQuery('.details_modal_body').html(doc);
86 session_hover_state = '';
87 // location.reload();
88 },
89 });
90 }, 100);
91 }
92 });
93 jQuery('#chatsession-table').on('click', '.show_details_click', function(e) {
94 var self = this;
95 const modal = document.getElementById("session_details_modal");
96
97 window.onclick = function(event) {
98 if (event.target == modal) {
99 modal.style.display = "none";
100 }
101 }
102 if(session_hover_state == ''){
103 session_hover_state = 1;
104 modal.style.display = "none";
105 jQuery('.details_modal_body').html('');
106 modal.style.left = (jQuery('.session_detail_hover').width() * 2)+'px';
107 setTimeout(function() {
108 modal.style.display = "block";
109 jQuery('.loader-mask').show();
110 jQuery('.loader').show();
111 jQuery.ajax({
112 url: ajax_object.ajax_url,
113 type: 'POST',
114 dataType: "JSON",
115 data: {
116 action : 'wpbot_session_hover_details',
117 security: ajax_object.ajax_nonce,
118 session_id: jQuery(self).attr('data-id'),
119 },
120 success: function (response) {
121 jQuery('.loader').fadeOut();
122 jQuery('.loader-mask').delay(350).fadeOut('slow');
123 let htmlString = response.conversation;
124 let doc = '<div class="session-details-sction-modal">' ;
125 doc += htmlspecialchars_decode(htmlString);
126 doc += '</div>';
127 if (response.email) {
128 doc += '</div><div class="email-reply-container" style="margin-top:20px; padding:15px; border-top:1px solid #ccc; background:#f9f9f9; border-radius: 6px;">' +
129 '<p style="margin-top:0;"> Reply via <strong>Email to: </strong>' + response.email + ( response.email_from ? ' <strong>From: </strong>' + response.email_from : '' ) + '</p>' +
130 '<div class="form-group mb-2" style="margin-bottom: 10px;">' +
131 '<input type="text" id="reply_subject" class="form-control" style="width:100%; box-sizing:border-box;" value="Reply to your chat session">' +
132 '</div>' +
133 '<div class="form-group mb-2" style="margin-bottom: 10px;">' +
134 '<textarea id="reply_message" class="form-control" rows="4" style="width:100%; box-sizing:border-box;" placeholder="Type your reply here..."></textarea>' +
135 '</div>' +
136 '<button type="button" class="btn btn-primary" id="btn_send_reply_email" data-email="' + response.email + '" style="background:#0d6efd; color:#fff; border:none; padding:8px 16px; border-radius:4px; cursor:pointer;">Send Reply</button>' +
137 '</div>';
138 } else {
139 doc += '<div class="email-reply-container" style="margin-top:20px; padding:15px; border-top:1px solid #ccc; background:#f9f9f9; border-radius: 6px;">' +
140 '<p style="margin:0; color:#d9534f; font-weight:bold;">To email this user and chat session, enable Asking for Email in General Settings</p>' +
141 '</div></div><div class="email-reply-container" style="margin-top:20px; padding:15px; border-top:1px solid #ccc; background:#f9f9f9; border-radius: 6px;">' +
142 '<p style="margin-top:0;"> Reply via <strong>Email to: </strong>' + response.email + ( response.email_from ? ' <strong>From: </strong>' + response.email_from : '' ) + '</p>' +
143 '<div class="form-group mb-2" style="margin-bottom: 10px;">' +
144 '<input type="text" id="reply_subject" disabled class="form-control" style="width:100%; box-sizing:border-box;" value="Reply to your chat session">' +
145 '</div>' +
146 '<div class="form-group mb-2" style="margin-bottom: 10px;">' +
147 '<textarea id="reply_message" disabled class="form-control" rows="4" style="width:100%; box-sizing:border-box;" placeholder="Type your reply here..."></textarea>' +
148 '</div>' +
149 '<button type="button" disabled class="btn btn-primary" id="btn_send_reply_email" data-email="' + response.email + '" style="background:#0d6efd; color:#fff; border:none; padding:8px 16px; border-radius:4px; cursor:pointer;">Send Reply</button>' +
150 '</div';
151 }
152 jQuery('.details_modal_body').html(doc);
153 session_hover_state = '';
154 // location.reload();
155 },
156 });
157 }, 100);
158 }
159 });
160 jQuery('#session_details_modal').on('click','.details_session_close',function(){
161 const modal = document.getElementById("session_details_modal");
162 modal.style.display = "none";
163 });
164
165 jQuery(document).on('click', '#btn_send_reply_email', function () {
166 var email = jQuery(this).attr('data-email');
167 var container = jQuery(this).closest('.email-reply-container');
168 var subject = container.find('#reply_subject').val();
169 var message = container.find('#reply_message').val();
170 var btn = jQuery(this);
171
172 if (!message.trim()) {
173 alert('Please enter a message.');
174 return;
175 }
176
177 btn.prop('disabled', true).text('Sending...');
178
179 jQuery.ajax({
180 url: ajax_object.ajax_url,
181 type: 'POST',
182 dataType: "JSON",
183 data: {
184 action: 'wpbot_send_reply_email',
185 security: ajax_object.ajax_nonce,
186 email: email,
187 subject: subject,
188 message: message
189 },
190 success: function (response) {
191 btn.prop('disabled', false).text('Send Reply');
192 if (response.success) {
193 if (typeof Swal !== 'undefined') {
194 Swal.fire({
195 title: 'Success',
196 text: response.msg,
197 icon: 'success',
198 confirmButtonText: 'OK'
199 });
200 } else {
201 alert(response.msg);
202 }
203 container.find('#reply_message').val('');
204 } else {
205 if (typeof Swal !== 'undefined') {
206 Swal.fire({
207 title: 'Error',
208 text: response.msg,
209 icon: 'error',
210 confirmButtonText: 'OK'
211 });
212 } else {
213 alert(response.msg);
214 }
215 }
216 },
217 error: function() {
218 btn.prop('disabled', false).text('Send Reply');
219 alert('An error occurred. Please try again.');
220 }
221 });
222 });
223 jQuery('#wpchatbot-sessioncorn-settings').on('click','#save_wpsseion_corn_setting',function(){
224 Swal.showLoading();
225 if (jQuery('#is_ai_enabled').is(":checked")){
226 var is_ai_enabled = 1;
227 }else{
228 var is_ai_enabled = 0;
229 }
230 var corn_schedule_interval = jQuery("[id*='corn_schedule_interval'] :selected").val();
231 var qcld_wbsession_corn_starttime = jQuery('#qcld_wbsession_corn_starttime').val();
232 var qcld_wpsession_corn_promt = jQuery('#wpsession_corn_promt').val();
233 jQuery.ajax({
234 url: ajax_object.ajax_url,
235 type: 'POST',
236 dataType: "JSON",
237 data: {
238 action : 'wpbot_seesion_corn_save',
239 security: ajax_object.ajax_nonce,
240 ai_enabled: is_ai_enabled,
241 corn_schedule_interval: corn_schedule_interval,
242 qcld_wbsession_corn_starttime: qcld_wbsession_corn_starttime,
243 qcld_wpsession_corn_promt: qcld_wpsession_corn_promt,
244 },
245 success: function (response) {
246 var cleanResponse = response.response ? response.response.replace(/<br\s*\/?>/gi, '\n').replace(/<\/?[^>]+(>|$)/g, "") : "";
247 var cleanMsg = response.msg ? response.msg.replace(/<br\s*\/?>/gi, '\n').replace(/<\/?[^>]+(>|$)/g, "") : "";
248 Swal.fire({
249 title: cleanMsg,
250 text: cleanResponse,
251 icon: response.icon,
252 width: 450,
253 confirmButtonText: 'Got it',
254 confirmButtonWidth: 100,
255 confirmButtonClass: 'btn btn-lg'
256 }).then(() => {
257 // location.reload();
258 })
259
260 },
261 });
262 })
263 jQuery('#wpchatbot-sessioncorn-mannual').on('click','#swpsseion_mannual_scraper_corn',function(){
264 Swal.showLoading();
265 var wpchatbot_sessioncorn_mannual_number = jQuery('#wpchatbot-sessioncorn-mannual-number').val();
266 jQuery.ajax({
267 url: ajax_object.ajax_url,
268 type: 'POST',
269 dataType: "JSON",
270 data: {
271 action : 'qcld_chatbot_session_mannual_scraper',
272 security: ajax_object.ajax_nonce,
273 wpchatbot_session_mannual_number : wpchatbot_sessioncorn_mannual_number,
274 },
275 success: function (response) {
276 var cleanResponse = response.response ? response.response.replace(/<br\s*\/?>/gi, '\n').replace(/<\/?[^>]+(>|$)/g, "") : "";
277 var cleanMsg = response.msg ? response.msg.replace(/<br\s*\/?>/gi, '\n').replace(/<\/?[^>]+(>|$)/g, "") : "";
278 Swal.fire({
279 title: cleanMsg,
280 text: cleanResponse,
281 icon: response.icon,
282 width: 450,
283 confirmButtonText: 'Got it',
284 confirmButtonWidth: 100,
285 confirmButtonClass: 'btn btn-lg'
286 }).then(() => {
287 // location.reload();
288 })
289 },
290 });
291 })
292
293 //end new-update-for-codecanyon
294 jQuery('#wpcs_form_sessions').on('change', '#is_enabled_session_email_notice', function() {
295 if(this.checked) {
296 jQuery.ajax({
297 url: ajax_object.ajax_url,
298 type: 'POST',
299 dataType: "JSON",
300 data: {
301 action : 'session_email_notification_update',
302 security: ajax_object.ajax_nonce,
303 email_notification: 'checked',
304 },
305 success: function (response) {
306 location.reload();
307 },
308 });
309 }else{
310 jQuery.ajax({
311 url: ajax_object.ajax_url,
312 type: 'POST',
313 dataType: "JSON",
314 data: {
315 action : 'session_email_notification_update',
316 security: ajax_object.ajax_nonce,
317 email_notification: '',
318 },
319 success: function (response) {
320 location.reload();
321 },
322 });
323 }
324 });
325
326 jQuery('#chatsession-table').on('click', '.forward_session', function () {
327 setTimeout(function() {
328 var detailselement = document.getElementById("wp-chatbot-messages-container");
329 detailselement.remove();
330 }, 500);
331 const forwardModal = document.getElementById("session_foward_modal");
332 if (forwardModal) {
333 forwardModal.style.display = "block";
334 jQuery('#details_session_id').val(jQuery(this).attr('data-id'));
335 }
336
337 });
338 jQuery('#session_foward_modal').on('click', '.forward_session_close', function () {
339 const forwardModal = document.getElementById("session_foward_modal");
340 if (forwardModal) {
341 forwardModal.style.display = "none";
342 }
343 });
344
345 jQuery('#session_foward_modal').on('click', '#qcld_details_forward_submit', function () {
346 var session_id = jQuery('#details_session_id').val();
347 jQuery.ajax({
348 url: ajax_object.ajax_url,
349 type: 'POST',
350 dataType: "JSON",
351 data: {
352 action : 'forward_session_to_email',
353 security: ajax_object.ajax_nonce,
354 session_id: session_id,
355 email: jQuery('#details_session_email').val(),
356 subject: jQuery('#details_session_subject').val(),
357 },
358 success: function (response) {
359 jQuery('#session_foward_modal').hide()
360 }
361 });
362 });
363 jQuery('.wp-chatbot-messages-wrapper').on('click', '.forward_session', function () {
364
365 var session_id = jQuery('#details_session_id').val();
366 jQuery.ajax({
367 url: ajax_object.ajax_url,
368 type: 'POST',
369 dataType: "JSON",
370 data: {
371 action : 'forward_session_to_email',
372 security: ajax_object.ajax_nonce,
373 session_id: session_id,
374 email: jQuery('#details_session_email').val(),
375 subject: jQuery('#details_session_subject').val(),
376 },
377 success: function (response) {
378 if(response.success){
379 Swal.fire({
380 title: 'Success',
381 text: response.message,
382 icon: 'success',
383 confirmButtonText: 'OK'
384 });
385 } else {
386 Swal.fire({
387 title: 'Error',
388 text: response.message,
389 icon: 'error',
390 confirmButtonText: 'OK'
391 });
392 }
393 }
394 });
395 });
396
397 });