|
@@ -1,3303 +1,3722 @@ |
|
1
|
|
-/*
|
|
2
|
|
- * Project: wpwBot jQuery Plugin
|
|
3
|
|
- * Description: wpwBot AI based Chatting functionality are handled .
|
|
4
|
|
- * Author: QuantumCloud
|
|
5
|
|
- * Version: 1.0
|
|
6
|
|
- */
|
|
7
|
|
-var wpwKits;
|
|
8
|
|
-(function($) {
|
|
9
|
|
- /*
|
|
10
|
|
- * Global variable as object will beused to handle
|
|
11
|
|
- * wpwbot chatting initialize, tree change transfer,
|
|
12
|
|
- * changing tree steps and cookies etc.
|
|
13
|
|
- */
|
|
14
|
|
- var globalwpw={
|
|
15
|
|
- initialize:0,
|
|
16
|
|
- settings:{},
|
|
17
|
|
- wildCard:0,
|
|
18
|
|
- wildcards:'',
|
|
19
|
|
- wildcardsHelp:['start','support','reset', 'search', 'email'],
|
|
20
|
|
- productStep:'asking',
|
|
21
|
|
- orderStep:'welcome',
|
|
22
|
|
- supportStep:'welcome',
|
|
23
|
|
- formStep: 'welcome',
|
|
24
|
|
- formfieldid:'',
|
|
25
|
|
- formid:'',
|
|
26
|
|
- formentry:0,
|
|
27
|
|
- hasNameCookie:$.cookie("shopper"),
|
|
28
|
|
- shopperUserName:'',
|
|
29
|
|
- shopperEmail:'',
|
|
30
|
|
- shopperMessage:'',
|
|
31
|
|
- emptymsghandler:0,
|
|
32
|
|
- repeatQueryEmpty:'',
|
|
33
|
|
- wpwIsWorking:0,
|
|
34
|
|
- ai_step:0,
|
|
35
|
|
- df_status_lock:0,
|
|
36
|
|
- counter:0
|
|
37
|
|
- };
|
|
38
|
|
- /*
|
|
39
|
|
- * wpwbot welcome section coverd
|
|
40
|
|
- * greeting for new and already visited shopper
|
|
41
|
|
- * based the memory after asking thier name.
|
|
42
|
|
- */
|
|
43
|
|
- var wpwWelcome={
|
|
44
|
|
- greeting:function () {
|
|
45
|
|
- //generating unique session id.
|
|
46
|
|
- if(!localStorage.getItem('botsessionid')){
|
|
47
|
|
- var number = Math.random() // 0.9394456857981651
|
|
48
|
|
- number.toString(36); // '0.xtis06h6'
|
|
49
|
|
- var id = number.toString(36).substr(2); // 'xtis06h6'
|
|
50
|
|
- localStorage.setItem('botsessionid', id);
|
|
51
|
|
- }
|
|
52
|
|
- // console.log(globalwpw.settings.obj.skip_wp_greetings=='1')
|
|
53
|
|
- if((globalwpw.settings.obj.skip_wp_greetings=='1') || (globalwpw.settings.obj.skip_greetings_and_menu =='1') ){
|
|
54
|
|
- }else{
|
|
55
|
|
- //Very begining greeting.
|
|
56
|
|
- if(globalwpw.settings.obj.re_target_handler==0){
|
|
57
|
|
- var botJoinMsg="<strong>"+wpwMsg.oncommand_filter(globalwpw.settings.obj.agent)+" </strong> "+wpwKits.randomMsg(globalwpw.settings.obj.agent_join);
|
|
58
|
|
- wpwMsg.single(botJoinMsg);
|
|
59
|
|
- }
|
|
60
|
|
- //Showing greeting for name in cookie or fresh shopper.
|
|
61
|
|
- setTimeout(function(){
|
|
62
|
|
- var firstMsg=wpwKits.randomMsg(globalwpw.settings.obj.hi_there)+' '+wpwKits.randomMsg(globalwpw.settings.obj.welcome)+" <strong>"+globalwpw.settings.obj.host+"!</strong> ";
|
|
63
|
|
- var secondMsg=wpwKits.randomMsg(globalwpw.settings.obj.asking_name);
|
|
64
|
|
-
|
|
65
|
|
- wpwMsg.double(firstMsg,secondMsg);
|
|
66
|
|
-
|
|
67
|
|
- }, globalwpw.settings.preLoadingTime*2);
|
|
68
|
|
- }
|
|
69
|
|
-
|
|
70
|
|
- var serviceOffer=wpwKits.randomMsg(globalwpw.settings.obj.wildcard_msg);
|
|
71
|
|
- if(globalwpw.settings.obj.skip_greetings_and_menu != 0){
|
|
72
|
|
- wpwMsg.single(serviceOffer);
|
|
73
|
|
- }
|
|
74
|
|
- if( ( globalwpw.settings.obj.show_menu_after_greetings!=0 ) && ( globalwpw.wildcards !='' ) ){
|
|
75
|
|
- wpwMsg.double_nobg(serviceOffer, globalwpw.wildcards);
|
|
76
|
|
- } if( ( globalwpw.settings.obj.skip_wp_greetings !=0 ) && ( globalwpw.wildcards !='' ) ){
|
|
77
|
|
- wpwMsg.double_nobg(serviceOffer, globalwpw.wildcards);
|
|
78
|
|
- } else{
|
|
79
|
|
- //wpwMsg.single(serviceOffer);
|
|
80
|
|
- }
|
|
81
|
|
- }
|
|
82
|
|
- };
|
|
83
|
|
- //Append the message to the message container based on the requirement.
|
|
84
|
|
- var wpwMsg={
|
|
85
|
|
- oncommand_filter:function(msg){
|
|
86
|
|
- var str = msg;
|
|
87
|
|
- if(typeof(str) === 'string'){
|
|
88
|
|
- str = str.replace(/on[a-zA-Z]+\s*=/g, "");
|
|
89
|
|
- }
|
|
90
|
|
- return str;
|
|
91
|
|
- },
|
|
92
|
|
- open_new_tab: function(msg){
|
|
93
|
|
- if(wp_chatbot_obj.open_links_newtab == '1'){
|
|
94
|
|
- var temp = document.createElement('div');
|
|
95
|
|
- temp.innerHTML = msg;
|
|
96
|
|
- let links = temp.querySelectorAll('a');
|
|
97
|
|
- links.forEach(link => {
|
|
98
|
|
- link.setAttribute('target', '_blank');
|
|
99
|
|
- });
|
|
100
|
|
- let temps = temp.innerHTML;
|
|
101
|
|
- return temps;
|
|
102
|
|
- }else{
|
|
103
|
|
- return msg;
|
|
104
|
|
- }
|
|
105
|
|
- },
|
|
106
|
|
- single_openai:function (msg) {
|
|
107
|
|
- msg = wpwMsg.open_new_tab(msg);
|
|
108
|
|
- globalwpw.wpwIsWorking=1;
|
|
109
|
|
- if($(globalwpw.settings.messageLastChild+' .wp-chatbot-comment-loader').length==0){
|
|
110
|
|
- $(globalwpw.settings.messageContainer).append(wpwKits.botPreloader());
|
|
111
|
|
- }
|
|
112
|
|
-
|
|
113
|
|
- //Scroll to the last message
|
|
114
|
|
- wpwKits.scrollTo();
|
|
115
|
|
- setTimeout(function(){
|
|
116
|
|
- $(globalwpw.settings.messageLastChild+' .wp-chatbot-paragraph').text( msg );
|
|
117
|
|
- //If has youtube link then show video
|
|
118
|
|
- wpwKits.videohandler();
|
|
119
|
|
- //scroll to the last message
|
|
120
|
|
- wpwKits.scrollTo();
|
|
121
|
|
- //Enable the editor
|
|
122
|
|
- wpwKits.enableEditor(wpwKits.randomMsg(globalwpw.settings.obj.send_a_msg));
|
|
123
|
|
- //keeping in history
|
|
124
|
|
- wpwKits.wpwHistorySave();
|
|
125
|
|
-
|
|
126
|
|
- }, globalwpw.settings.preLoadingTime);
|
|
127
|
|
- },
|
|
128
|
|
- single:function (msg) {
|
|
129
|
|
- msg = wpwMsg.open_new_tab(msg);
|
|
130
|
|
- globalwpw.wpwIsWorking=1;
|
|
131
|
|
- if($(globalwpw.settings.messageLastChild+' .wp-chatbot-comment-loader').length==0){
|
|
132
|
|
- $(globalwpw.settings.messageContainer).append(wpwKits.botPreloader());
|
|
133
|
|
- }
|
|
134
|
|
- //Scroll to the last message
|
|
135
|
|
- wpwKits.scrollTo();
|
|
136
|
|
- oncommand_filter = wpwMsg.oncommand_filter(msg);
|
|
137
|
|
-
|
|
138
|
|
- setTimeout(function(){
|
|
139
|
|
- $(globalwpw.settings.messageLastChild+' .wp-chatbot-paragraph').html( '<div class="wp-chatbot-textanimation">' + oncommand_filter + '</div>');
|
|
140
|
|
- //If has youtube link then show video
|
|
141
|
|
- wpwKits.videohandler();
|
|
142
|
|
- //scroll to the last message
|
|
143
|
|
- wpwKits.scrollTo();
|
|
144
|
|
- //Enable the editor
|
|
145
|
|
- wpwKits.enableEditor(wpwKits.randomMsg(globalwpw.settings.obj.send_a_msg));
|
|
146
|
|
- //keeping in history
|
|
147
|
|
- wpwKits.wpwHistorySave();
|
|
148
|
|
- }, globalwpw.settings.preLoadingTime);
|
|
149
|
|
- },
|
|
150
|
|
- single_nobg:function (msg) {
|
|
151
|
|
- msg = wpwMsg.open_new_tab(msg);
|
|
152
|
|
- globalwpw.wpwIsWorking=1;
|
|
153
|
|
- if($(globalwpw.settings.messageLastChild+' .wp-chatbot-comment-loader').length==0){
|
|
154
|
|
- $(globalwpw.settings.messageContainer).append(wpwKits.botPreloader());
|
|
155
|
|
- }
|
|
156
|
|
- //Scroll to the last message
|
|
157
|
|
- oncommand_filter = wpwMsg.oncommand_filter(msg);
|
|
158
|
|
- wpwKits.scrollTo();
|
|
159
|
|
- setTimeout(function(){
|
|
160
|
|
- $(globalwpw.settings.messageLastChild+' .wp-chatbot-paragraph').parent().addClass('wp-chatbot-msg-flat').html( '<div class="wp-chatbot-textanimation">' + oncommand_filter + '</div>');
|
|
161
|
|
- //scroll to the last message
|
|
162
|
|
- wpwKits.scrollTo();
|
|
163
|
|
- //Enable the editor
|
|
164
|
|
- wpwKits.enableEditor(wpwKits.randomMsg(globalwpw.settings.obj.send_a_msg));
|
|
165
|
|
- //Keeping the chat history in localStorage
|
|
166
|
|
- wpwKits.wpwHistorySave();
|
|
167
|
|
- // disabled editor
|
|
168
|
|
- // wpwKits.disableEditor('Please choose an option.');
|
|
169
|
|
- }, globalwpw.settings.preLoadingTime);
|
|
170
|
|
- },
|
|
171
|
|
- double:function (fristMsg,secondMsg) {
|
|
172
|
|
- fristMsg = wpwMsg.open_new_tab(fristMsg);
|
|
173
|
|
- secondMsg = wpwMsg.open_new_tab(secondMsg);
|
|
174
|
|
- globalwpw.wpwIsWorking=1;
|
|
175
|
|
- if($(globalwpw.settings.messageLastChild+' .wp-chatbot-comment-loader').length==0){
|
|
176
|
|
- $(globalwpw.settings.messageContainer).append(wpwKits.botPreloader());
|
|
177
|
|
- }
|
|
178
|
|
- oncommand_fristMsg_filter = wpwMsg.oncommand_filter(fristMsg);
|
|
179
|
|
- oncommand_secondMsg_filter = wpwMsg.oncommand_filter(secondMsg);
|
|
180
|
|
- //Scroll to the last message
|
|
181
|
|
- wpwKits.scrollTo();
|
|
182
|
|
- setTimeout(function(){
|
|
183
|
|
- $(globalwpw.settings.messageLastChild+' .wp-chatbot-paragraph').html('<div class="wp-chatbot-textanimation">' + oncommand_fristMsg_filter + '</div>');
|
|
184
|
|
- //Second Message with interval
|
|
185
|
|
- if($(globalwpw.settings.messageLastChild+' .wp-chatbot-comment-loader').length==0){
|
|
186
|
|
- $(globalwpw.settings.messageContainer).append(wpwKits.botPreloader());
|
|
187
|
|
- }
|
|
188
|
|
- //Scroll to the last message
|
|
189
|
|
- wpwKits.scrollTo();
|
|
190
|
|
- setTimeout(function(){
|
|
191
|
|
- $(globalwpw.settings.messageLastChild+' .wp-chatbot-paragraph').html('<div class="wp-chatbot-textanimation">' + oncommand_secondMsg_filter + '</div>');
|
|
192
|
|
- //Scroll to the last message
|
|
193
|
|
- wpwKits.scrollTo();
|
|
194
|
|
- //Enable the editor
|
|
195
|
|
- wpwKits.enableEditor(wpwKits.randomMsg(globalwpw.settings.obj.send_a_msg));
|
|
196
|
|
- //keeping in history
|
|
197
|
|
- wpwKits.wpwHistorySave();
|
|
198
|
|
- }, globalwpw.settings.preLoadingTime*2);
|
|
199
|
|
- }, globalwpw.settings.preLoadingTime);
|
|
200
|
|
- },
|
|
201
|
|
- double_nobg:function (fristMsg,secondMsg) {
|
|
202
|
|
- fristMsg = wpwMsg.open_new_tab(fristMsg);
|
|
203
|
|
- secondMsg = wpwMsg.open_new_tab(secondMsg);
|
|
204
|
|
- oncommand_fristMsg_filter = wpwMsg.oncommand_filter(fristMsg);
|
|
205
|
|
- oncommand_secondMsg_filter = wpwMsg.oncommand_filter(secondMsg);
|
|
206
|
|
-
|
|
207
|
|
- globalwpw.wpwIsWorking=1;
|
|
208
|
|
- if($(globalwpw.settings.messageLastChild+' .wp-chatbot-comment-loader').length==0){
|
|
209
|
|
- $(globalwpw.settings.messageContainer).append(wpwKits.botPreloader());
|
|
210
|
|
- }
|
|
211
|
|
- //Scroll to the last message
|
|
212
|
|
- wpwKits.scrollTo();
|
|
213
|
|
- setTimeout(function(){
|
|
214
|
|
- $(globalwpw.settings.messageLastChild+' .wp-chatbot-paragraph').html('<div class="wp-chatbot-textanimation">' + oncommand_fristMsg_filter + '</div>');
|
|
215
|
|
- //Second Message with interval
|
|
216
|
|
- if($(globalwpw.settings.messageLastChild+' .wp-chatbot-comment-loader').length==0){
|
|
217
|
|
- $(globalwpw.settings.messageContainer).append(wpwKits.botPreloader());
|
|
218
|
|
- }
|
|
219
|
|
- //Scroll to the last message
|
|
220
|
|
- wpwKits.scrollTo();
|
|
221
|
|
- setTimeout(function(){
|
|
222
|
|
- if( globalwpw.wildCard>0 && ((globalwpw.settings.obj.disable_back_to_start != '1' && globalwpw.settings.obj.skip_greetings_and_menu != 1)) ){
|
|
223
|
|
- $(globalwpw.settings.messageLastChild+' .wp-chatbot-paragraph').parent().addClass('wp-chatbot-msg-flat').html(oncommand_secondMsg_filter).append('<span class="qcld-chatbot-wildcard" data-wildcart="back">' + wpwKits.randomMsg(globalwpw.settings.obj.back_to_start) + '</span>');
|
|
224
|
|
- }else{
|
|
225
|
|
- $(globalwpw.settings.messageLastChild+' .wp-chatbot-paragraph').parent().addClass('wp-chatbot-msg-flat').html('<div class="wp-chatbot-textanimation">' + oncommand_secondMsg_filter + '</div>');
|
|
226
|
|
- }
|
|
227
|
|
- //scroll to the last message
|
|
228
|
|
- wpwKits.scrollTo();
|
|
229
|
|
- //Enable the editor
|
|
230
|
|
- if(globalwpw.wildCard==1 && globalwpw.supportStep=='welcome'){
|
|
231
|
|
- //wpwKits.disableEditor('Support');
|
|
232
|
|
- wpwKits.enableEditor(wpwKits.randomMsg(globalwpw.settings.obj.send_a_msg));
|
|
233
|
|
- }else{
|
|
234
|
|
- wpwKits.enableEditor(wpwKits.randomMsg(globalwpw.settings.obj.send_a_msg));
|
|
235
|
|
- }
|
|
236
|
|
- //keeping in history
|
|
237
|
|
- wpwKits.wpwHistorySave();
|
|
238
|
|
- // disabled editor
|
|
239
|
|
- // wpwKits.disableEditor('Please choose an option.');
|
|
240
|
|
- }, globalwpw.settings.preLoadingTime*2);
|
|
241
|
|
- }, globalwpw.settings.preLoadingTime);
|
|
242
|
|
- },
|
|
243
|
|
- triple_nobg:function (fristMsg,secondMsg,thirdMsg) {
|
|
244
|
|
- fristMsg = wpwMsg.open_new_tab(fristMsg);
|
|
245
|
|
- secondMsg = wpwMsg.open_new_tab(secondMsg);
|
|
246
|
|
- oncommand_fristMsg_filter = wpwMsg.oncommand_filter(fristMsg);
|
|
247
|
|
- oncommand_secondMsg_filter = wpwMsg.oncommand_filter(secondMsg);
|
|
248
|
|
- globalwpw.wpwIsWorking=1;
|
|
249
|
|
- $(globalwpw.settings.messageContainer).append(wpwKits.botPreloader());
|
|
250
|
|
- //Scroll to the last message
|
|
251
|
|
- wpwKits.scrollTo();
|
|
252
|
|
- setTimeout(function(){
|
|
253
|
|
- $(globalwpw.settings.messageLastChild+' .wp-chatbot-paragraph').html('<div class="wp-chatbot-textanimation">' + oncommand_fristMsg_filter + '</div>');
|
|
254
|
|
- wpwKits.videohandler();
|
|
255
|
|
- //Second Message with interval
|
|
256
|
|
- if($(globalwpw.settings.messageLastChild+' .wp-chatbot-comment-loader').length==0){
|
|
257
|
|
- $(globalwpw.settings.messageContainer).append(wpwKits.botPreloader());
|
|
258
|
|
- }
|
|
259
|
|
- //Scroll to the last message
|
|
260
|
|
- wpwKits.scrollTo();
|
|
261
|
|
- setTimeout(function(){
|
|
262
|
|
- $(globalwpw.settings.messageLastChild+' .wp-chatbot-paragraph').html('<div class="wp-chatbot-textanimation">' + oncommand_secondMsg_filter + '</div>');
|
|
263
|
|
- wpwKits.videohandler();
|
|
264
|
|
- if($(globalwpw.settings.messageLastChild+' .wp-chatbot-comment-loader').length==0){
|
|
265
|
|
- $(globalwpw.settings.messageContainer).append(wpwKits.botPreloader());
|
|
266
|
|
- }
|
|
267
|
|
- //Scroll to the last message
|
|
268
|
|
- wpwKits.scrollTo();
|
|
269
|
|
- setTimeout(function(){
|
|
270
|
|
- if(globalwpw.wildCard>0 && (globalwpw.settings.obj.disable_back_to_start != '1' && globalwpw.settings.obj.skip_greetings_and_menu != 1)){
|
|
271
|
|
- $(globalwpw.settings.messageLastChild+' .wp-chatbot-paragraph').parent().addClass('wp-chatbot-msg-flat').html(thirdMsg).append('<span class="qcld-chatbot-wildcard qcld_back_to_start" data-wildcart="back">' + wpwKits.randomMsg(globalwpw.settings.obj.back_to_start) + '</span>');
|
|
272
|
|
- }else{
|
|
273
|
|
- $(globalwpw.settings.messageLastChild+' .wp-chatbot-paragraph').parent().addClass('wp-chatbot-msg-flat').html('<div class="wp-chatbot-textanimation">' + thirdMsg + '</div>');
|
|
274
|
|
- }
|
|
275
|
|
- //scroll to the last message
|
|
276
|
|
- wpwKits.scrollTo();
|
|
277
|
|
- wpwKits.videohandler();
|
|
278
|
|
- //Enable the editor
|
|
279
|
|
- if(globalwpw.wildCard==1 && globalwpw.supportStep=='welcome'){
|
|
280
|
|
- //wpwKits.disableEditor('Support');
|
|
281
|
|
- }else{
|
|
282
|
|
- wpwKits.enableEditor(wpwKits.randomMsg(globalwpw.settings.obj.send_a_msg));
|
|
283
|
|
- }
|
|
284
|
|
- //keeping in history
|
|
285
|
|
- wpwKits.wpwHistorySave();
|
|
286
|
|
- // disabled editor
|
|
287
|
|
- // wpwKits.disableEditor('Please choose an option.');
|
|
288
|
|
- }, globalwpw.settings.preLoadingTime);
|
|
289
|
|
- }, globalwpw.settings.preLoadingTime);
|
|
290
|
|
- }, globalwpw.settings.preLoadingTime);
|
|
291
|
|
- },
|
|
292
|
|
- shopper:function (shopperMsg) {
|
|
293
|
|
- $(globalwpw.settings.messageContainer).append(wpwKits.shopperMsgDom(shopperMsg));
|
|
294
|
|
- //scroll to the last message
|
|
295
|
|
- wpwKits.scrollTo();
|
|
296
|
|
- //keeping in history
|
|
297
|
|
- wpwKits.wpwHistorySave();
|
|
298
|
|
- },
|
|
299
|
|
- shopper_choice:function (shopperChoice) {
|
|
300
|
|
- $(globalwpw.settings.messageLastChild).fadeOut(globalwpw.settings.preLoadingTime);
|
|
301
|
|
- $(globalwpw.settings.messageContainer).append(wpwKits.shopperMsgDom(shopperChoice));
|
|
302
|
|
- //scroll to the last message
|
|
303
|
|
- wpwKits.scrollTo();
|
|
304
|
|
- //keeping in history
|
|
305
|
|
- wpwKits.wpwHistorySave();
|
|
306
|
|
- }
|
|
307
|
|
- };
|
|
308
|
|
- //Every tiny tools are implemented in wpwKits as object literal.
|
|
309
|
|
- wpwKits={
|
|
310
|
|
- enableEditor:function(placeHolder){
|
|
311
|
|
- if(globalwpw.settings.editor_handler==0){
|
|
312
|
|
- if($(window).width()>380){
|
|
313
|
|
- $("#wp-chatbot-editor").attr('disabled',false).focus();
|
|
314
|
|
- }else{
|
|
315
|
|
- $("#wp-chatbot-editor").attr('disabled',false)
|
|
316
|
|
- }
|
|
317
|
|
- $("#wp-chatbot-editor").attr('placeholder',placeHolder);
|
|
318
|
|
- $("#wp-chatbot-send-message").attr('disabled',false);
|
|
319
|
|
- }
|
|
320
|
|
- },
|
|
321
|
|
- disableEditor:function (placeHolder) {
|
|
322
|
|
- if(globalwpw.settings.editor_handler==0){
|
|
323
|
|
- $("#wp-chatbot-editor").attr('placeholder',placeHolder);
|
|
324
|
|
- $("#wp-chatbot-editor").attr('disabled',true);
|
|
325
|
|
- $("#wp-chatbot-send-message").attr('disabled',true);
|
|
326
|
|
- }
|
|
327
|
|
- //Remove extra pre loader.
|
|
328
|
|
- if($('.wp-chatbot-messages-container').find('.wp-chatbot-comment-loader').length>0){
|
|
329
|
|
- $('.wp-chatbot-messages-container').find('.wp-chatbot-comment-loader').parent().parent().hide();
|
|
330
|
|
- }
|
|
331
|
|
- },
|
|
332
|
|
- htmlEntities:function(str) {
|
|
333
|
|
- return String(str).replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>').replace(/"/g, '"');
|
|
334
|
|
- },
|
|
335
|
|
- wpwHistorySave:function () {
|
|
336
|
|
- globalwpw.wpwIsWorking=0;
|
|
337
|
|
- var wpwHistory= $(globalwpw.settings.messageWrapper).html();
|
|
338
|
|
- localStorage.setItem("wpwHitory", wpwHistory);
|
|
339
|
|
- if(localStorage.getItem('botsessionid')){
|
|
340
|
|
- if(!localStorage.getItem('shopperemail')){
|
|
341
|
|
- var useremail = '';
|
|
342
|
|
- }else{
|
|
343
|
|
- var useremail = localStorage.getItem('shopperemail');
|
|
344
|
|
- }
|
|
345
|
|
- if(globalwpw.hasNameCookie){
|
|
346
|
|
- var shopper=globalwpw.hasNameCookie;
|
|
347
|
|
- } else{
|
|
348
|
|
- var shopper=globalwpw.settings.obj.shopper_demo_name;
|
|
349
|
|
- }
|
|
350
|
|
- if(localStorage.getItem('shopperphone')){
|
|
351
|
|
- var shopperphone = localStorage.getItem('shopperphone');
|
|
352
|
|
- }else{
|
|
353
|
|
- var shopperphone = '';
|
|
354
|
|
- }
|
|
355
|
|
- var data = {'action':'qcld_wb_chatbot_conversation_save','session_id': localStorage.getItem('botsessionid'),'name':shopper,'email':useremail, 'phone':shopperphone, 'conversation':wpwKits.htmlEntities(wpwHistory), 'security':globalwpw.settings.obj.ajax_nonce, 'user_id': globalwpw.settings.obj.current_user_id};
|
|
356
|
|
- if( globalwpw.settings.obj.is_chat_session_active == 1 ){
|
|
357
|
|
- wpwKits.ajax(data).done(function (response) {
|
|
358
|
|
- //console.log(response);
|
|
359
|
|
- })
|
|
360
|
|
- }
|
|
361
|
|
- }
|
|
362
|
|
- //},globalwpw.settings.wildcardsShowTime);
|
|
363
|
|
- },
|
|
364
|
|
- decodehtml: function(str) {
|
|
365
|
|
- var doc = new DOMParser().parseFromString(str, "text/html");
|
|
366
|
|
-
|
|
367
|
|
- return doc.body.firstChild.data || "";
|
|
368
|
|
-
|
|
369
|
|
- },
|
|
370
|
|
- randomMsg:function(arrMsg){
|
|
371
|
|
- var index=Math.floor(Math.random() * arrMsg.length);
|
|
372
|
|
- var msg = arrMsg[index];
|
|
373
|
|
- if (typeof msg === 'string' && msg.indexOf('%%username%%') !== -1) {
|
|
374
|
|
- var shopperName = localStorage.getItem('shopper') || (globalwpw.settings.obj.display_name || '');
|
|
375
|
|
- msg = msg.replace(/%%username%%/g, shopperName);
|
|
376
|
|
- }
|
|
377
|
|
- return msg;
|
|
378
|
|
- },
|
|
379
|
|
- ajax:function (data) {
|
|
380
|
|
- return jQuery.post(globalwpw.settings.obj.ajax_url, data);
|
|
381
|
|
- },
|
|
382
|
|
- dailogAIOAction:function(text){
|
|
383
|
|
- if(globalwpw.settings.obj.df_api_version=='v1'){
|
|
384
|
|
- return jQuery.ajax({
|
|
385
|
|
- type : "POST",
|
|
386
|
|
- url :"https://api.dialogflow.com/v1/query?v=20170712",
|
|
387
|
|
- contentType : "application/json; charset=utf-8",
|
|
388
|
|
- dataType : "json",
|
|
389
|
|
- headers : {
|
|
390
|
|
- "Authorization" : "Bearer "+globalwpw.settings.obj.ai_df_token
|
|
391
|
|
- },
|
|
392
|
|
- data: JSON.stringify( {
|
|
393
|
|
- query: text,
|
|
394
|
|
- lang : globalwpw.settings.obj.df_agent_lan,
|
|
395
|
|
- sessionId: localStorage.getItem('botsessionid')?localStorage.getItem('botsessionid'):'wpwBot_df_2018071'
|
|
396
|
|
- } )
|
|
397
|
|
- });
|
|
398
|
|
- }else{
|
|
399
|
|
-
|
|
400
|
|
- return jQuery.post(globalwpw.settings.obj.ajax_url, {
|
|
401
|
|
- 'action': 'qcld_wp_df_api_call',
|
|
402
|
|
- 'dfquery': text,
|
|
403
|
|
- 'nonce': globalwpw.settings.obj.ajax_nonce,
|
|
404
|
|
- 'sessionid': localStorage.getItem('botsessionid')?localStorage.getItem('botsessionid'):'wpwBot_df_2018071'
|
|
405
|
|
- });
|
|
406
|
|
- }
|
|
407
|
|
- },
|
|
408
|
|
- responseIsOk(response){
|
|
409
|
|
- if(globalwpw.settings.obj.df_api_version=='v1'){
|
|
410
|
|
- if(response.status.code==200 || response.status.code==206){
|
|
411
|
|
- return true;
|
|
412
|
|
- }else{
|
|
413
|
|
- return false;
|
|
414
|
|
- }
|
|
415
|
|
- }else{
|
|
416
|
|
- if(typeof response.responseId !== "undefined"){
|
|
417
|
|
- return true;
|
|
418
|
|
- }else{
|
|
419
|
|
- return false;
|
|
420
|
|
- }
|
|
421
|
|
- }
|
|
422
|
|
- },
|
|
423
|
|
- getIntentName(response){
|
|
424
|
|
- if(globalwpw.settings.obj.df_api_version=='v1'){
|
|
425
|
|
- return response.result.metadata.intentName;
|
|
426
|
|
- }else{
|
|
427
|
|
- return response.queryResult.intent.displayName;
|
|
428
|
|
- }
|
|
429
|
|
- },
|
|
430
|
|
- getParameters(response){
|
|
431
|
|
- if(globalwpw.settings.obj.df_api_version=='v1'){
|
|
432
|
|
- return response.result.parameters;
|
|
433
|
|
- }else{
|
|
434
|
|
- return response.queryResult.parameters;
|
|
435
|
|
- }
|
|
436
|
|
- },
|
|
437
|
|
- getFulfillmentText(response){
|
|
438
|
|
- if(globalwpw.settings.obj.df_api_version=='v1'){
|
|
439
|
|
- return response.result.fulfillment.messages;
|
|
440
|
|
- }else{
|
|
441
|
|
- return response.queryResult.fulfillmentText;
|
|
442
|
|
- }
|
|
443
|
|
- },
|
|
444
|
|
- getFulfillmentSpeech(response){
|
|
445
|
|
- if(globalwpw.settings.obj.df_api_version=='v1'){
|
|
446
|
|
- return response.result.fulfillment.speech;
|
|
447
|
|
- }else{
|
|
448
|
|
- return response.queryResult.fulfillmentText;
|
|
449
|
|
- }
|
|
450
|
|
- },
|
|
451
|
|
- getScore(response){
|
|
452
|
|
- if(globalwpw.settings.obj.df_api_version=='v1'){
|
|
453
|
|
- return response.result.score;
|
|
454
|
|
- }else{
|
|
455
|
|
- return response.queryResult.intentDetectionConfidence;
|
|
456
|
|
- }
|
|
457
|
|
- },
|
|
458
|
|
- getAction(response){
|
|
459
|
|
- if(globalwpw.settings.obj.df_api_version=='v1'){
|
|
460
|
|
- return response.result.action;
|
|
461
|
|
- }else{
|
|
462
|
|
- if(typeof response.queryResult.action !=="undefined"){
|
|
463
|
|
- return response.queryResult.action;
|
|
464
|
|
- }else{
|
|
465
|
|
- return '';
|
|
466
|
|
- }
|
|
467
|
|
- }
|
|
468
|
|
- },
|
|
469
|
|
- queryText(response){
|
|
470
|
|
- if(globalwpw.settings.obj.df_api_version=='v1'){
|
|
471
|
|
- return response.result.resolvedQuery;
|
|
472
|
|
- }else{
|
|
473
|
|
- return response.queryResult.queryText;
|
|
474
|
|
- }
|
|
475
|
|
- },
|
|
476
|
|
- isActionComplete(response){
|
|
477
|
|
- if(globalwpw.settings.obj.df_api_version=='v1'){
|
|
478
|
|
- if(!response.result.actionIncomplete){
|
|
479
|
|
- return true;
|
|
480
|
|
- }else{
|
|
481
|
|
- return false;
|
|
482
|
|
- }
|
|
483
|
|
- }else{
|
|
484
|
|
- return response.queryResult.allRequiredParamsPresent;
|
|
485
|
|
- }
|
|
486
|
|
- },
|
|
487
|
|
- isConversationEnd(response){
|
|
488
|
|
- if(globalwpw.settings.obj.df_api_version=='v1'){
|
|
489
|
|
- if(typeof(response.result.metadata.endConversation)!=="undefined" && response.result.metadata.endConversation){
|
|
490
|
|
- return true;
|
|
491
|
|
- }else{
|
|
492
|
|
- return false;
|
|
493
|
|
- }
|
|
494
|
|
- }else{
|
|
495
|
|
- if(typeof response.queryResult.diagnosticInfo !=="undefined"){
|
|
496
|
|
- if(typeof response.queryResult.diagnosticInfo.end_conversation !== "undefined"){
|
|
497
|
|
- return response.queryResult.diagnosticInfo.end_conversation;
|
|
498
|
|
- }else{
|
|
499
|
|
- return false;
|
|
500
|
|
- }
|
|
501
|
|
- }else{
|
|
502
|
|
- return false;
|
|
503
|
|
- }
|
|
504
|
|
- }
|
|
505
|
|
- },
|
|
506
|
|
- sugestCat:function () {
|
|
507
|
|
- var productSuggest=wpwKits.randomMsg(globalwpw.settings.obj.product_suggest);
|
|
508
|
|
- var data={'action':'qcld_wb_chatbot_category'};
|
|
509
|
|
- var result=wpwKits.ajax(data);
|
|
510
|
|
- result.done(function( response ) {
|
|
511
|
|
- wpwMsg.double_nobg(productSuggest,response);
|
|
512
|
|
- if(globalwpw.settings.obj.ai_df_enable==1 && globalwpw.df_status_lock==0){
|
|
513
|
|
- globalwpw.wildCard=0;
|
|
514
|
|
- globalwpw.ai_step=1;
|
|
515
|
|
- localStorage.setItem("wildCard", globalwpw.wildCard);
|
|
516
|
|
- localStorage.setItem("aiStep", globalwpw.ai_step);
|
|
517
|
|
- }
|
|
518
|
|
- });
|
|
519
|
|
- },
|
|
520
|
|
- subCats:function (parentId) {
|
|
521
|
|
- var subCatMsg=wpwKits.randomMsg(globalwpw.settings.obj.product_suggest);
|
|
522
|
|
- var data={'action':'qcld_wb_chatbot_sub_category','parent_id':parentId};
|
|
523
|
|
- var result=wpwKits.ajax(data);
|
|
524
|
|
- result.done(function( response ) {
|
|
525
|
|
- wpwMsg.double_nobg(subCatMsg,response);
|
|
526
|
|
- });
|
|
527
|
|
- },
|
|
528
|
|
- suggestEmail:function (emailFor) {
|
|
529
|
|
- var sugMsg=wpwKits.randomMsg(globalwpw.settings.obj.support_option_again);
|
|
530
|
|
- var sugOptions= '<span class="qcld-chatbot-wildcard qcld_back_to_start" data-wildcart="back">' + wpwKits.randomMsg(globalwpw.settings.obj.back_to_start) + '</span>'; // /*emailFor+*/globalwpw.wildcards;
|
|
531
|
|
- if( ( globalwpw.settings.obj.disable_back_to_start != '1' && globalwpw.settings.obj.skip_greetings_and_menu != 1 )){
|
|
532
|
|
- wpwMsg.single_nobg('<span class="qcld-chatbot-wildcard qcld_back_to_start" data-wildcart="back">' + wpwKits.randomMsg(globalwpw.settings.obj.back_to_start) + '</span>');
|
|
533
|
|
- }
|
|
534
|
|
- },
|
|
535
|
|
- videohandler:function () {
|
|
536
|
|
- $(globalwpw.settings.messageLastChild+' .wp-chatbot-paragraph').html(function(i, html) {
|
|
537
|
|
- return html.replace(/(?:https:\/\/)?(?:www\.)?(?:youtube\.com|youtu\.be)\/(?:watch\?v=)?(.+)/g, '<iframe width="250" height="180" src="http://www.youtube.com/embed/$1" frameborder="0" allowfullscreen></iframe>');
|
|
538
|
|
- });
|
|
539
|
|
- },
|
|
540
|
|
- scrollTo:function () {
|
|
541
|
|
- $(globalwpw.settings.botContainer).animate({ scrollTop: $(globalwpw.settings.messageWrapper).prop("scrollHeight")}, 'slow').parent().find('.slimScrollBar').css({'top':$(globalwpw.settings.botContainer).height()+'px'});;
|
|
542
|
|
- },
|
|
543
|
|
- botPreloader:function () {
|
|
544
|
|
- var enableleReactions = globalwpw.settings.obj.skip_chat_reactions_menu;
|
|
545
|
|
- var eanleeReport = globalwpw.settings.obj.enable_chat_report_menu;
|
|
546
|
|
- var enableshare = globalwpw.settings.obj.enable_chat_share_menu;
|
|
547
|
|
- var likeTxt = globalwpw.settings.obj.qlcd_wp_chatbot_like_text;
|
|
548
|
|
- var disLikeTxt = globalwpw.settings.obj.qlcd_wp_chatbot_dislike_text;
|
|
549
|
|
- var reportTxt = globalwpw.settings.obj.qlcd_wp_chatbot_report_text;
|
|
550
|
|
- var sharetTxt = globalwpw.settings.obj.qlcd_wp_chatbot_share_text;
|
|
551
|
|
-
|
|
552
|
|
- var msgContent='<li class="wp-chatbot-msg">' +
|
|
553
|
|
- '<div class="wp-chatbot-avatar">'+
|
|
554
|
|
- '<img src="'+globalwpw.settings.obj.agent_image_path+'" alt="">'+
|
|
555
|
|
- '</div>'+
|
|
556
|
|
- '<div class="wp-chatbot-agent">'+ wpwMsg.oncommand_filter(globalwpw.settings.obj.agent)+'</div>'
|
|
557
|
|
- +'<div class="chat-container"><div class="wp-chatbot-paragraph"><img class="wp-chatbot-comment-loader" src="'+globalwpw.settings.obj.image_path+'comment.gif" alt="Typing..." /></div>'+
|
|
558
|
|
- '<div class="qcld-like-dislike-icon">' +
|
|
559
|
|
- (enableleReactions == 1
|
|
560
|
|
- ? '<a href="#" title="' + (likeTxt?.en_US || 'Like') + '"><i class="dashicons dashicons-thumbs-up" aria-hidden="true"></i></a>' +
|
|
561
|
|
- '<a href="#" title="' + (disLikeTxt?.en_US || 'Dislike') + '"><i class="dashicons dashicons-thumbs-down" aria-hidden="true"></i></a>'
|
|
562
|
|
- : '') +
|
|
563
|
|
-
|
|
564
|
|
- (eanleeReport == 1
|
|
565
|
|
- ? '<a href="#" title="' + (reportTxt?.en_US || 'Report') + '"><i class="dashicons dashicons-admin-comments"></i></a>'
|
|
566
|
|
- : '') +
|
|
567
|
|
-
|
|
568
|
|
- (enableshare == 1
|
|
569
|
|
- ? '<div class="qcld-share">' +
|
|
570
|
|
- '<a href="#" class="share-toggle" title="' + (sharetTxt?.en_US || 'Share') + '"><i class="dashicons dashicons-share"></i></a>' +
|
|
571
|
|
- '<div class="share-menu" style="display:none;">' +
|
|
572
|
|
- '<a href="#" class="share-fb"><i class="dashicons dashicons-facebook"></i></a>' +
|
|
573
|
|
- '<a href="#" class="share-wa"><i class="dashicons dashicons-whatsapp"></i></a>' +
|
|
574
|
|
- '<a href="#" class="share-x"><i class="dashicons dashicons-twitter"></i></a>' +
|
|
575
|
|
- '<a href="#" class="share-email"><i class="dashicons dashicons-email-alt"></i></a>' +
|
|
576
|
|
- '</div>' +
|
|
577
|
|
- '</div>'
|
|
578
|
|
- : '') +
|
|
579
|
|
- '</div>' +'</div>' +
|
|
580
|
|
- '</li>';
|
|
581
|
|
- return msgContent;
|
|
582
|
|
- },
|
|
583
|
|
- shopperMsgDom:function (msg) {
|
|
584
|
|
- if(globalwpw.hasNameCookie){
|
|
585
|
|
- var shopper=globalwpw.hasNameCookie;
|
|
586
|
|
- } else{
|
|
587
|
|
- var shopper=globalwpw.settings.obj.shopper_demo_name;
|
|
588
|
|
- }
|
|
589
|
|
- //var date = new Date();
|
|
590
|
|
- date = new Date();
|
|
591
|
|
- var msgContent='<li class="wp-chat-user-msg">' +
|
|
592
|
|
- '<div style="margin-top:40px;" class="wp-chatbot-avatar">'+
|
|
593
|
|
- '<img src="'+globalwpw.settings.obj.image_path+'client.png" alt="User Image">'+
|
|
594
|
|
- '</div>'+
|
|
595
|
|
- '<div class="wp-chatbot-agent">'+shopper +'</div>'
|
|
596
|
|
- +'<div class="wp-chatbot-paragraph"><div class="wp-chatbot-textanimation">'+msg+'</div></div></li>';
|
|
597
|
|
- return msgContent;
|
|
598
|
|
- },
|
|
599
|
|
- showCart:function () {
|
|
600
|
|
- var data = {'action':'qcld_wb_chatbot_show_cart'}
|
|
601
|
|
- this.ajax(data).done(function (response) {
|
|
602
|
|
- //if cart show on message board
|
|
603
|
|
- if($('#wp-chatbot-shortcode-template-container').length == 0) {
|
|
604
|
|
- $(globalwpw.settings.messageWrapper).html(response.html);
|
|
605
|
|
- $('#wp-chatbot-cart-numbers').html(response.items);
|
|
606
|
|
- $('.wp-chatbot-ball-cart-items').html(response.items);
|
|
607
|
|
- wpwKits.disableEditor(wpwKits.randomMsg(globalwpw.settings.obj.shopping_cart));
|
|
608
|
|
- }else{ //Cart show on shortcode
|
|
609
|
|
- $('.wp-chatbot-cart-shortcode-container').html(response.html);
|
|
610
|
|
- }
|
|
611
|
|
- //Add scroll to the cart shortcode
|
|
612
|
|
- if($('#wp-chatbot-shortcode-template-container').length > 0 && $('.chatbot-shortcode-template-02').length==0) {
|
|
613
|
|
- $('.wp-chatbot-cart-body').slimScroll({height: '200px', start: 'bottom'});
|
|
614
|
|
- }
|
|
615
|
|
- });
|
|
616
|
|
- },
|
|
617
|
|
- toTitlecase:function (msg) {
|
|
618
|
|
- return msg.replace(/\w\S*/g, function(txt){return txt.charAt(0).toUpperCase() + txt.substr(1).toLowerCase();});
|
|
619
|
|
- },
|
|
620
|
|
- filterStopWords:function(msg){
|
|
621
|
|
- var spcialStopWords=",;,/,\\,[,],{,},(,),&,*,.,+ ,?,^,$,=,!,<,>,|,:,-";
|
|
622
|
|
- var userMsg="";
|
|
623
|
|
- //Removing Special Characts from last position.
|
|
624
|
|
- var msgLastChar=msg.slice(-1);
|
|
625
|
|
- if(spcialStopWords.indexOf(msgLastChar) >= 0 ){
|
|
626
|
|
- userMsg=msg.slice(0, -1);
|
|
627
|
|
- }else{
|
|
628
|
|
- userMsg=msg;
|
|
629
|
|
- }
|
|
630
|
|
- var stopWords=globalwpw.settings.obj.stop_words+spcialStopWords;
|
|
631
|
|
- var stopWordsArr=stopWords.split(',');
|
|
632
|
|
- var msgArr=userMsg.split(' ');
|
|
633
|
|
- var filtermsgArr = msgArr.filter(function myCallBack(el){
|
|
634
|
|
- return stopWordsArr.indexOf(el.toLowerCase()) < 0;
|
|
635
|
|
- });
|
|
636
|
|
- filterMsg=filtermsgArr.join(' ');
|
|
637
|
|
- return filterMsg;
|
|
638
|
|
- },
|
|
639
|
|
- htmlTagsScape:function(userString) {
|
|
640
|
|
- var tagsToReplace = {
|
|
641
|
|
- '&': '&',
|
|
642
|
|
- '<': '<',
|
|
643
|
|
- '>': '>'
|
|
644
|
|
- };
|
|
645
|
|
- return userString.replace(/[&<>]/g, function(tag) {
|
|
646
|
|
- return tagsToReplace[tag] || tag;
|
|
647
|
|
- });
|
|
648
|
|
- },
|
|
649
|
|
- reset: function() {
|
|
650
|
|
- $('#wp-chatbot-messages-container').html('');
|
|
651
|
|
- localStorage.removeItem("wpwHitory");
|
|
652
|
|
- localStorage.removeItem('shopper');
|
|
653
|
|
- globalwpw.wildCard=0;
|
|
654
|
|
- globalwpw.ai_step=0;
|
|
655
|
|
- localStorage.setItem("wildCard", globalwpw.wildCard);
|
|
656
|
|
- localStorage.setItem("aiStep", globalwpw.ai_step);
|
|
657
|
|
- globalwpw.formfieldid = '';
|
|
658
|
|
- localStorage.setItem("formfieldid", globalwpw.formfieldid);
|
|
659
|
|
- globalwpw.formStep='welcome';
|
|
660
|
|
- localStorage.setItem("formStep", globalwpw.formStep);
|
|
661
|
|
- globalwpw.formid='';
|
|
662
|
|
- localStorage.setItem("formid", globalwpw.formid);
|
|
663
|
|
- globalwpw.formentry = 0;
|
|
664
|
|
- localStorage.setItem("formentry", globalwpw.formentry);
|
|
665
|
|
- localStorage.removeItem("cx-name" );
|
|
666
|
|
- localStorage.removeItem("cx-diaplayname" );
|
|
667
|
|
- localStorage.removeItem("cx-languagecode" );
|
|
668
|
|
- localStorage.removeItem("cx-timezone" );
|
|
669
|
|
- }
|
|
670
|
|
- }
|
|
671
|
|
- /*
|
|
672
|
|
- * wpwbot Trees are basically product,order and support
|
|
673
|
|
- * product tree : asking,showing & shopping part will be covered.
|
|
674
|
|
- * order tree : showing order list and email to admin option.
|
|
675
|
|
- * support tree : List of support query-answer including text & video and email to admin option.
|
|
676
|
|
- */
|
|
677
|
|
- var wpwTree={
|
|
678
|
|
- greeting:function (msg) {
|
|
679
|
|
- /**
|
|
680
|
|
- * When Enable DialogFlow then or else
|
|
681
|
|
- */
|
|
682
|
|
-
|
|
683
|
|
- if(globalwpw.settings.obj.ai_df_enable==1 && globalwpw.df_status_lock==0){
|
|
684
|
|
- //When intialize 1 and don't have cookies then keep the name of shooper in in cookie
|
|
685
|
|
- if(globalwpw.initialize==1 && !localStorage.getItem('shopper') && globalwpw.wildCard==0 && globalwpw.ai_step==0 ){
|
|
686
|
|
- msg=wpwKits.toTitlecase(wpwKits.filterStopWords(msg));
|
|
687
|
|
- $.cookie("shopper", msg, { expires : 365 });
|
|
688
|
|
- localStorage.setItem('shopper',msg);
|
|
689
|
|
- globalwpw.hasNameCookie=msg;
|
|
690
|
|
- //Greeting with name and suggesting the wildcard.
|
|
691
|
|
- var NameGreeting=wpwKits.randomMsg(globalwpw.settings.obj.i_am) +" <strong>"+wpwMsg.oncommand_filter(globalwpw.settings.obj.agent)+"</strong>! "+ wpwKits.randomMsg(globalwpw.settings.obj.name_greeting);
|
|
692
|
|
- NameGreeting = NameGreeting.replace("%%username%%", msg);
|
|
693
|
|
- var serviceOffer=wpwKits.randomMsg(globalwpw.settings.obj.wildcard_msg);
|
|
694
|
|
- serviceOffer = serviceOffer.replace("%%username%%", msg);
|
|
695
|
|
- //After completing two steps messaging showing wildcards.
|
|
696
|
|
- wpwMsg.triple_nobg( NameGreeting,serviceOffer, globalwpw.wildcards )
|
|
697
|
|
- globalwpw.ai_step=1;
|
|
698
|
|
- globalwpw.wildCard=0;
|
|
699
|
|
- localStorage.setItem("wildCard", globalwpw.wildCard);
|
|
700
|
|
- localStorage.setItem("aiStep", globalwpw.ai_step);
|
|
701
|
|
- }
|
|
702
|
|
- //When returning shopper then greeting with name and wildcards.
|
|
703
|
|
- else if(localStorage.getItem('shopper') && globalwpw.wildCard==0 && globalwpw.ai_step==0){
|
|
704
|
|
- //After asking service show the wildcards.
|
|
705
|
|
- var serviceOffer=wpwKits.randomMsg(globalwpw.settings.obj.wildcard_msg);
|
|
706
|
|
- globalwpw.ai_step=1;
|
|
707
|
|
- globalwpw.wildCard=0;
|
|
708
|
|
- localStorage.setItem("wildCard", globalwpw.wildCard);
|
|
709
|
|
- localStorage.setItem("aiStep", globalwpw.ai_step);
|
|
710
|
|
- if( ( globalwpw.settings.obj.show_menu_after_greetings==1) && ( globalwpw.wildcards !='' ) ){
|
|
711
|
|
- wpwMsg.double_nobg(serviceOffer, globalwpw.wildcards);
|
|
712
|
|
- }else{
|
|
713
|
|
- wpwMsg.single(serviceOffer);
|
|
714
|
|
- }
|
|
715
|
|
- }
|
|
716
|
|
- //When user asking needs then DialogFlow will given intent after NLP steps.
|
|
717
|
|
- else if(globalwpw.wildCard==0 && globalwpw.ai_step==1){
|
|
718
|
|
- var dfReturns=wpwKits.dailogAIOAction(msg);
|
|
719
|
|
- dfReturns.done(function( response ) {
|
|
720
|
|
- if(globalwpw.settings.obj.df_api_version=='v2'){
|
|
721
|
|
- response = $.parseJSON(JSON.parse(response));
|
|
722
|
|
- }
|
|
723
|
|
- if(wpwKits.responseIsOk(response)){
|
|
724
|
|
- var userIntent=wpwKits.getIntentName(response);
|
|
725
|
|
-
|
|
726
|
|
- if(userIntent=='start'){
|
|
727
|
|
- globalwpw.wildCard=0;
|
|
728
|
|
- var serviceOffer=wpwKits.randomMsg(globalwpw.settings.obj.wildcard_msg);
|
|
729
|
|
- console.log( globalwpw.wildcards);
|
|
730
|
|
- wpwMsg.double_nobg(serviceOffer,globalwpw.wildcards);
|
|
731
|
|
- }else if(userIntent=='welcome'){
|
|
732
|
|
- var messages = wpwKits.getFulfillmentSpeech(response);
|
|
733
|
|
- setTimeout(function () {
|
|
734
|
|
- wpwMsg.single(messages);
|
|
735
|
|
- },globalwpw.settings.preLoadingTime);
|
|
736
|
|
- }else if(userIntent=='help'){
|
|
737
|
|
- $(globalwpw.settings.messageWrapper).html(localStorage.getItem("wpwHitory"));
|
|
738
|
|
- //Showing help message
|
|
739
|
|
- setTimeout(function () {
|
|
740
|
|
- wpwKits.scrollTo();
|
|
741
|
|
-
|
|
742
|
|
- var helpWelcome = wpwKits.randomMsg(globalwpw.settings.obj.help_welcome);
|
|
743
|
|
- var helpMsg = wpwKits.randomMsg(globalwpw.settings.obj.help_msg);
|
|
744
|
|
- wpwMsg.double(helpWelcome,helpMsg);
|
|
745
|
|
- //dialogflow
|
|
746
|
|
- if(globalwpw.settings.obj.ai_df_enable==1 && globalwpw.df_status_lock==0){
|
|
747
|
|
- globalwpw.wildCard=0;
|
|
748
|
|
- globalwpw.ai_step=1;
|
|
749
|
|
- localStorage.setItem("wildCard", globalwpw.wildCard);
|
|
750
|
|
- localStorage.setItem("aiStep", globalwpw.ai_step);
|
|
751
|
|
- }
|
|
752
|
|
- },globalwpw.settings.preLoadingTime);
|
|
753
|
|
- }else if(userIntent=='reset'){
|
|
754
|
|
- var restWarning=globalwpw.settings.obj.reset;
|
|
755
|
|
- var confirmBtn='<span class="qcld-chatbot-reset-btn" reset-data="yes" >'+globalwpw.settings.obj.yes+'</span> <span> '+globalwpw.settings.obj.or+' </span><span class="qcld-chatbot-reset-btn" reset-data="no">'+globalwpw.settings.obj.no+'</span>';
|
|
756
|
|
- wpwMsg.double_nobg(restWarning,confirmBtn);
|
|
757
|
|
- }else if(userIntent=='phone'){
|
|
758
|
|
- if(typeof(globalwpw.hasNameCookie)=='undefined'|| globalwpw.hasNameCookie==''){
|
|
759
|
|
- var shopperName= globalwpw.settings.obj.shopper_demo_name;
|
|
760
|
|
- }else{
|
|
761
|
|
- var shopperName=globalwpw.hasNameCookie;
|
|
762
|
|
- }
|
|
763
|
|
- var ask_msg = wpwKits.randomMsg(globalwpw.settings.obj.asking_phone);
|
|
764
|
|
- var askEmail = (globalwpw.settings.obj.skip_wp_greetings=='1' || globalwpw.settings.obj.skip_greetings_and_menu =='1') ? 'Hello ' + ask_msg : 'Hello '+shopperName+'! '+ ask_msg;
|
|
765
|
|
- wpwMsg.single(askEmail);
|
|
766
|
|
- //Now updating the support part as .
|
|
767
|
|
- globalwpw.supportStep='phone';
|
|
768
|
|
- globalwpw.wildCard=1;
|
|
769
|
|
- //keeping value in localstorage
|
|
770
|
|
- localStorage.setItem("wildCard", globalwpw.wildCard);
|
|
771
|
|
- localStorage.setItem("supportStep", globalwpw.supportStep);
|
|
772
|
|
- }else if(userIntent=='email'){
|
|
773
|
|
- if(typeof(globalwpw.hasNameCookie)=='undefined'|| globalwpw.hasNameCookie==''){
|
|
774
|
|
- var shopperName= globalwpw.settings.obj.shopper_demo_name;
|
|
775
|
|
- }else{
|
|
776
|
|
- var shopperName=globalwpw.hasNameCookie;
|
|
777
|
|
- }
|
|
778
|
|
- var ask_msg = wpwKits.randomMsg(globalwpw.settings.obj.asking_email);
|
|
779
|
|
- var askEmail = (globalwpw.settings.obj.skip_wp_greetings=='1' || globalwpw.settings.obj.skip_greetings_and_menu =='1') ? wpwKits.randomMsg(globalwpw.settings.obj.hello)+' '+ ask_msg : wpwKits.randomMsg(globalwpw.settings.obj.hello)+' '+shopperName+'! '+ ask_msg;
|
|
780
|
|
- wpwMsg.single(askEmail);
|
|
781
|
|
- //Now updating the support part as .
|
|
782
|
|
- globalwpw.supportStep='email';
|
|
783
|
|
- globalwpw.wildCard=1;
|
|
784
|
|
- //keeping value in localstorage
|
|
785
|
|
- localStorage.setItem("wildCard", globalwpw.wildCard);
|
|
786
|
|
- localStorage.setItem("supportStep", globalwpw.supportStep);
|
|
787
|
|
- }else if(userIntent=='faq'){
|
|
788
|
|
- globalwpw.wildCard=1;
|
|
789
|
|
- globalwpw.supportStep='welcome';
|
|
790
|
|
- wpwAction.bot('from wildcard support');
|
|
791
|
|
- //keeping value in localstorage
|
|
792
|
|
- /*localStorage.setItem("wildCard", globalwpw.wildCard);
|
|
793
|
|
- localStorage.setItem("supportStep", globalwpw.supportStep);*/
|
|
794
|
|
- }else if(userIntent=='Default Fallback Intent'){
|
|
795
|
|
-
|
|
796
|
|
- var data = {'action':'wpbo_search_response','name':globalwpw.hasNameCookie,'keyword':msg};
|
|
797
|
|
- wpwKits.ajax(data).done(function (respond) {
|
|
798
|
|
- var json=$.parseJSON(respond);
|
|
799
|
|
- if(json.status=='success'){
|
|
800
|
|
- if(typeof(json.category)!=="undefined" && json.category){
|
|
801
|
|
- var question='';
|
|
802
|
|
- $.each(json.data, function (i, obj) {
|
|
803
|
|
- question += '<span class="qcld-chatbot-wildcard qcld_simple_txt_response" data-strid="'+ obj.id +'">'+ obj.query +'</span>';
|
|
804
|
|
- });
|
|
805
|
|
- wpwMsg.single_nobg(question);
|
|
806
|
|
- }else if(json.multiple){
|
|
807
|
|
- var question='';
|
|
808
|
|
- $.each(json.data, function (i, obj) {
|
|
809
|
|
- question += '<span class="qcld-chatbot-wildcard qcld_simple_txt_response" data-strid="'+ obj.id +'">'+ obj.query +'</span>';
|
|
810
|
|
- });
|
|
811
|
|
- wpwMsg.double_nobg(wpwKits.randomMsg(globalwpw.settings.obj.did_you_mean),question);
|
|
812
|
|
- }else{
|
|
813
|
|
- wpwMsg.single(json.data[0].response);
|
|
814
|
|
- setTimeout(function(){
|
|
815
|
|
- wpwMsg.single_nobg('<span class="qcld-chatbot-wildcard" data-wildcart="back">' + wpwKits.randomMsg(globalwpw.settings.obj.back_to_start) + '</span>');
|
|
816
|
|
- },globalwpw.settings.preLoadingTime*2)
|
|
817
|
|
- }
|
|
818
|
|
- }if(wp_chatbot_obj.disable_site_search != 1){
|
|
819
|
|
-
|
|
820
|
|
- wpwTree.site_search(msg)
|
|
821
|
|
- }else{
|
|
822
|
|
- msg = wpwKits.filterStopWords(msg);
|
|
823
|
|
- if(globalwpw.counter == 2 ){
|
|
824
|
|
- wpwTree.df_reply(response);
|
|
825
|
|
- setTimeout(function(){
|
|
826
|
|
- var serviceOffer=wpwKits.randomMsg(globalwpw.settings.obj.support_option_again);
|
|
827
|
|
- wpwMsg.single_nobg('<span class="qcld-chatbot-wildcard qcld_back_to_start" data-wildcart="back">' + wpwKits.randomMsg(globalwpw.settings.obj.back_to_start) + '</span>');
|
|
828
|
|
- },globalwpw.settings.preLoadingTime)
|
|
829
|
|
- globalwpw.counter = 0;
|
|
830
|
|
- }else{
|
|
831
|
|
- globalwpw.counter++;
|
|
832
|
|
- wpwTree.df_reply(response);
|
|
833
|
|
- }
|
|
834
|
|
- }
|
|
835
|
|
- })
|
|
836
|
|
- }else if(wpwKits.getScore(response)!=0){ // checking is reponsing from dialogflow.
|
|
837
|
|
- var sTalkAction=wpwKits.getAction(response);
|
|
838
|
|
- if(sTalkAction!='' && sTalkAction.indexOf('smalltalk') != -1 ){
|
|
839
|
|
- var sMgs=wpwKits.getFulfillmentText(response);
|
|
840
|
|
- wpwMsg.single(sMgs);
|
|
841
|
|
- }else{
|
|
842
|
|
- var messages = wpwKits.getFulfillmentText(response);
|
|
843
|
|
- wpwTree.df_reply(response);
|
|
844
|
|
- }
|
|
845
|
|
- }else{
|
|
846
|
|
- console.log( globalwpw.wildcards);
|
|
847
|
|
- var dfDefaultMsg=globalwpw.settings.obj.df_defualt_reply;
|
|
848
|
|
- wpwMsg.double_nobg(dfDefaultMsg,globalwpw.wildcards);
|
|
849
|
|
- }
|
|
850
|
|
- }else{
|
|
851
|
|
- console.log( globalwpw.wildcards);
|
|
852
|
|
- //if bad request or limit cross then
|
|
853
|
|
- globalwpw.df_status_lock=0;
|
|
854
|
|
- var dfDefaultMsg=globalwpw.settings.obj.df_defualt_reply;
|
|
855
|
|
- wpwMsg.double_nobg(dfDefaultMsg,globalwpw.wildcards);
|
|
856
|
|
- }
|
|
857
|
|
- }).fail(function (error) {
|
|
858
|
|
- var dfDefaultMsg=globalwpw.settings.obj.df_defualt_reply;
|
|
859
|
|
- console.log( globalwpw.wildcards);
|
|
860
|
|
- wpwMsg.double_nobg(dfDefaultMsg,globalwpw.wildcards);
|
|
861
|
|
- });
|
|
862
|
|
- }
|
|
863
|
|
- }else{
|
|
864
|
|
- //When intialize 1 and don't have cookies then keep the name of shooper in in cookie
|
|
865
|
|
- if(globalwpw.initialize==1 && !localStorage.getItem('shopper') && globalwpw.wildCard==0){
|
|
866
|
|
- msg=wpwKits.toTitlecase(msg);
|
|
867
|
|
- msg1=wpwKits.toTitlecase(wpwKits.filterStopWords(msg));
|
|
868
|
|
- $.cookie("shopper", msg, { expires : 365 });
|
|
869
|
|
- localStorage.setItem('shopper',msg);
|
|
870
|
|
- globalwpw.hasNameCookie=msg;
|
|
871
|
|
- //Greeting with name and suggesting the wildcard.
|
|
872
|
|
- if((globalwpw.settings.obj.skip_wp_greetings=='1') || (globalwpw.settings.obj.skip_greetings_and_menu =='1') ){
|
|
873
|
|
-
|
|
874
|
|
- wpwAction.bot(msg)
|
|
875
|
|
- // var serviceOffer=wpwKits.randomMsg(globalwpw.settings.obj.wildcard_msg);
|
|
876
|
|
- // if(globalwpw.settings.obj.skip_greetings_and_menu != 0){
|
|
877
|
|
- // wpwMsg.single(serviceOffer);
|
|
878
|
|
- // }
|
|
879
|
|
- // if(globalwpw.settings.obj.skip_wp_greetings != 0){
|
|
880
|
|
- // wpwMsg.double_nobg(serviceOffer, globalwpw.wildcards);
|
|
881
|
|
- // }
|
|
882
|
|
-
|
|
883
|
|
-
|
|
884
|
|
- }else{
|
|
885
|
|
- var NameGreeting=wpwKits.randomMsg(globalwpw.settings.obj.i_am) +" <strong>"+wpwMsg.oncommand_filter(globalwpw.settings.obj.agent)+"</strong>! "+wpwKits.randomMsg(globalwpw.settings.obj.name_greeting);
|
|
886
|
|
- NameGreeting = NameGreeting.replace("%%username%%", msg1);
|
|
887
|
|
- var serviceOffer=wpwKits.randomMsg(globalwpw.settings.obj.wildcard_msg);
|
|
888
|
|
- //After completing two steps messaging showing wildcards.
|
|
889
|
|
- if( ( globalwpw.settings.obj.show_menu_after_greetings!=0 ) && ( globalwpw.wildcards !='' ) ){
|
|
890
|
|
- wpwMsg.triple_nobg( NameGreeting,serviceOffer, globalwpw.wildcards )
|
|
891
|
|
-
|
|
892
|
|
- }else{
|
|
893
|
|
- wpwMsg.double( NameGreeting,serviceOffer );
|
|
894
|
|
- }
|
|
895
|
|
-
|
|
896
|
|
- }
|
|
897
|
|
- }
|
|
898
|
|
- //When returning shopper then greeting with name and wildcards.
|
|
899
|
|
- else if(localStorage.getItem('shopper') && globalwpw.wildCard==0){
|
|
900
|
|
- //After asking service show the wildcards.
|
|
901
|
|
- var serviceOffer=wpwKits.randomMsg(globalwpw.settings.obj.wildcard_msg);
|
|
902
|
|
- console.log( globalwpw.wildcards);
|
|
903
|
|
- wpwMsg.double_nobg(serviceOffer,globalwpw.wildcards);
|
|
904
|
|
- }
|
|
905
|
|
- }
|
|
906
|
|
- },
|
|
907
|
|
- df_multi_handle:function(array){
|
|
908
|
|
- if(array.length>0){
|
|
909
|
|
- setTimeout(function(){
|
|
910
|
|
- wpwMsg.single(array[0]);
|
|
911
|
|
- array.splice(0, 1);
|
|
912
|
|
- setTimeout(function(){
|
|
913
|
|
- wpwTree.df_multi_handle(array);
|
|
914
|
|
- }, globalwpw.settings.preLoadingTime)
|
|
915
|
|
- }, globalwpw.settings.preLoadingTime)
|
|
916
|
|
- }
|
|
917
|
|
- },
|
|
918
|
|
- df_reply:function(response){
|
|
919
|
|
- //checking for facebook platform
|
|
920
|
|
- var i = 0;
|
|
921
|
|
- var html = '';
|
|
922
|
|
- var responses = [];
|
|
923
|
|
- if(globalwpw.settings.obj.df_api_version=='v1'){
|
|
924
|
|
- var messages = (response && response.result && response.result.fulfillment && response.result.fulfillment.messages) ? response.result.fulfillment.messages : [];
|
|
925
|
|
- var action = (response && response.result && typeof response.result.actionIncomplete !== 'undefined') ? response.result.actionIncomplete : false;
|
|
926
|
|
- jQuery.each( messages, function( key, message ) {
|
|
927
|
|
- html = '';
|
|
928
|
|
- i +=1;
|
|
929
|
|
- if(message.type==2){
|
|
930
|
|
- html += "<p>" + message.title + "</p>";
|
|
931
|
|
- var index = 0;
|
|
932
|
|
- for (index; index<message.replies.length; index++) {
|
|
933
|
|
- html += "<span class=\"wpb-quick-reply qcld-chat-common\">"+ message.replies[index] +"</span>";
|
|
934
|
|
- }
|
|
935
|
|
- }
|
|
936
|
|
- //check for default reply
|
|
937
|
|
- else if(message.type==0 && message.speech!=''){
|
|
938
|
|
- html += message.speech;
|
|
939
|
|
- }else if(message.type==1){
|
|
940
|
|
- html +='';
|
|
941
|
|
- }else if(message.type=='simple_response'){
|
|
942
|
|
- html += message.textToSpeech;
|
|
943
|
|
- }
|
|
944
|
|
- if(html!=''){
|
|
945
|
|
- responses.push(html);
|
|
946
|
|
- }
|
|
947
|
|
- })
|
|
948
|
|
- }else{
|
|
949
|
|
- var messages = (response && response.queryResult && response.queryResult.fulfillmentMessages) ? response.queryResult.fulfillmentMessages : [];
|
|
950
|
|
- var actioncomplete = (response && response.queryResult && typeof response.queryResult.allRequiredParamsPresent !== 'undefined') ? response.queryResult.allRequiredParamsPresent : false;
|
|
951
|
|
- jQuery.each( messages, function( key, message ) {
|
|
952
|
|
- html = '';
|
|
953
|
|
- i +=1;
|
|
954
|
|
- //handeling quickreplies
|
|
955
|
|
- if(typeof message.quickReplies !=="undefined"){
|
|
956
|
|
- if(typeof message.quickReplies.title !=="undefined"){
|
|
957
|
|
- html += "<p>" + message.quickReplies.title + "</p>";
|
|
958
|
|
- }
|
|
959
|
|
- if(typeof message.quickReplies.quickReplies !=="undefined" ){
|
|
960
|
|
- var index = 0;
|
|
961
|
|
- for (index; index<message.quickReplies.quickReplies.length; index++) {
|
|
962
|
|
- html += "<span class=\"wpb-quick-reply qcld-chat-common\">"+ message.quickReplies.quickReplies[index] +"</span>";
|
|
963
|
|
- }
|
|
964
|
|
- }
|
|
965
|
|
- }
|
|
966
|
|
- //handleing default response
|
|
967
|
|
- else if(typeof message.text !=="undefined"){
|
|
968
|
|
- if(typeof message.text.text !=="undefined" && message.text.text.length>0){
|
|
969
|
|
- html += message.text.text[0];
|
|
970
|
|
- }
|
|
971
|
|
- }
|
|
972
|
|
- if(html!=''){
|
|
973
|
|
- responses.push(html);
|
|
974
|
|
- }
|
|
975
|
|
- })
|
|
976
|
|
- }
|
|
977
|
|
- wpwTree.df_multi_handle(responses);
|
|
978
|
|
- },
|
|
979
|
|
- support:function (msg) {
|
|
980
|
|
- if(globalwpw.wildCard==1 && globalwpw.supportStep=='welcome'){
|
|
981
|
|
- var welcomeMsg= wpwKits.randomMsg(globalwpw.settings.obj.support_welcome);
|
|
982
|
|
- var orPhoneSuggest = '';
|
|
983
|
|
- if(globalwpw.settings.obj.support_query.length>0){
|
|
984
|
|
- var supportsItems = '';
|
|
985
|
|
- var messenger = '';
|
|
986
|
|
- if(globalwpw.settings.obj.enable_messenger==1) {
|
|
987
|
|
- messenger += '<span class="qcld-chatbot-wildcard" data-wildcart="messenger">'+wpwKits.randomMsg(globalwpw.settings.obj.messenger_label)+'</span>';
|
|
988
|
|
- }
|
|
989
|
|
- if(globalwpw.settings.obj.enable_whats==1) {
|
|
990
|
|
- messenger += '<span class="qcld-chatbot-wildcard" data-wildcart="whatsapp">'+wpwKits.randomMsg(globalwpw.settings.obj.whats_label)+'</span>';
|
|
991
|
|
- }
|
|
992
|
|
- if(globalwpw.settings.obj.disable_feedback=='') {
|
|
993
|
|
- messenger+= '<span class="qcld-chatbot-suggest-email" >'+wpwKits.randomMsg(globalwpw.settings.obj.feedback_label)+'</span>';
|
|
994
|
|
- }
|
|
995
|
|
- $.each(globalwpw.settings.obj.support_query, function (i, obj) {
|
|
996
|
|
- supportsItems += '<span class="qcld-chatbot-support-items" data-query-index="' + i + '">' + obj + '</span>';
|
|
997
|
|
- });
|
|
998
|
|
- var orEmailSuggest = '<span class="qcld-chatbot-suggest-email" >' + wpwKits.randomMsg(globalwpw.settings.obj.support_email) + '</span>';
|
|
999
|
|
- if(globalwpw.settings.obj.call_sup=="") {
|
|
1000
|
|
- orPhoneSuggest = '<span class="qcld-chatbot-suggest-phone" >' + wpwKits.randomMsg(globalwpw.settings.obj.support_phone) + '</span>';
|
|
1001
|
|
- }
|
|
1002
|
|
- var queryOrEmail=supportsItems/*+orEmailSuggest+orPhoneSuggest+messenger*/;
|
|
1003
|
|
- }else {
|
|
1004
|
|
- if(globalwpw.settings.obj.call_sup=="") {
|
|
1005
|
|
- orPhoneSuggest = '<span class="qcld-chatbot-suggest-phone" >' + wpwKits.randomMsg(globalwpw.settings.obj.support_phone) + '</span>';
|
|
1006
|
|
- }
|
|
1007
|
|
- var queryOrEmail='<span class="qcld-chatbot-suggest-email" >' + wpwKits.randomMsg(globalwpw.settings.obj.support_email) + '</span>'+orPhoneSuggest;
|
|
1008
|
|
- }
|
|
1009
|
|
- wpwMsg.double_nobg(welcomeMsg,queryOrEmail);
|
|
1010
|
|
- globalwpw.wildCard = 0;
|
|
1011
|
|
- } else if(globalwpw.wildCard==1 && globalwpw.supportStep=='email'){
|
|
1012
|
|
- globalwpw.shopperEmail=msg;
|
|
1013
|
|
- var validate = "";
|
|
1014
|
|
- var re = /^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i;
|
|
1015
|
|
- if( re.test(globalwpw.shopperEmail)!=true){
|
|
1016
|
|
- validate = validate+wpwKits.randomMsg(globalwpw.settings.obj.invalid_email) ;
|
|
1017
|
|
- }
|
|
1018
|
|
- if(validate == ""){
|
|
1019
|
|
- var askingMsg=wpwKits.randomMsg(globalwpw.settings.obj.asking_msg);
|
|
1020
|
|
- wpwMsg.single(askingMsg);
|
|
1021
|
|
- globalwpw.supportStep='message';
|
|
1022
|
|
- //keeping value in localstorage
|
|
1023
|
|
- localStorage.setItem("supportStep", globalwpw.supportStep);
|
|
1024
|
|
- }else{
|
|
1025
|
|
- wpwMsg.single(validate);
|
|
1026
|
|
- globalwpw.supportStep='email';
|
|
1027
|
|
- //keeping value in localstorage
|
|
1028
|
|
- localStorage.setItem("supportStep", globalwpw.supportStep);
|
|
1029
|
|
- }
|
|
1030
|
|
- }else if(globalwpw.wildCard==1 && globalwpw.supportStep=='message'){
|
|
1031
|
|
- var data = {'action':'qcld_wb_chatbot_support_email','name':globalwpw.hasNameCookie,'email':globalwpw.shopperEmail,'message':msg,'nonce':globalwpw.settings.obj.ajax_nonce};
|
|
1032
|
|
- wpwKits.ajax(data).done(function (response) {
|
|
1033
|
|
- var json=$.parseJSON(response);
|
|
1034
|
|
- var orPhoneSuggest='';
|
|
1035
|
|
- if(json.status=='success'){
|
|
1036
|
|
- var sucMsg=json.message;
|
|
1037
|
|
- wpwMsg.single(sucMsg);
|
|
1038
|
|
- //Asking email after showing answer.
|
|
1039
|
|
- setTimeout(function(){
|
|
1040
|
|
- if(globalwpw.settings.obj.call_sup=="") {
|
|
1041
|
|
- orPhoneSuggest = '<span class="qcld-chatbot-suggest-phone" >' + wpwKits.randomMsg(globalwpw.settings.obj.support_phone) + '</span>';
|
|
1042
|
|
- }
|
|
1043
|
|
- var orEmailSuggest='<span class="qcld-chatbot-suggest-email" >'+wpwKits.randomMsg(globalwpw.settings.obj.support_email)+'</span>';
|
|
1044
|
|
- wpwKits.suggestEmail(orEmailSuggest+orPhoneSuggest);
|
|
1045
|
|
- globalwpw.wildCard=0;
|
|
1046
|
|
- },globalwpw.settings.preLoadingTime);
|
|
1047
|
|
- }else{
|
|
1048
|
|
- var failMsg=json.message;
|
|
1049
|
|
- wpwMsg.single(failMsg);
|
|
1050
|
|
- //Asking email after showing answer.
|
|
1051
|
|
- setTimeout(function(){
|
|
1052
|
|
- if(globalwpw.settings.obj.call_sup=="") {
|
|
1053
|
|
- orPhoneSuggest = '<span class="qcld-chatbot-suggest-phone" >' + wpwKits.randomMsg(globalwpw.settings.obj.support_phone) + '</span>';
|
|
1054
|
|
- }
|
|
1055
|
|
- var orEmailSuggest='<span class="qcld-chatbot-suggest-email" >'+wpwKits.randomMsg(globalwpw.settings.obj.support_email)+'</span>';
|
|
1056
|
|
- wpwKits.suggestEmail(orEmailSuggest+orPhoneSuggest);
|
|
1057
|
|
- globalwpw.wildCard=0;
|
|
1058
|
|
- },globalwpw.settings.preLoadingTime);
|
|
1059
|
|
- }
|
|
1060
|
|
- });
|
|
1061
|
|
- }else if(globalwpw.wildCard==1 && globalwpw.supportStep=='phone'){
|
|
1062
|
|
- var data = {'action':'qcld_wb_chatbot_support_phone','name':globalwpw.hasNameCookie,'phone':msg,'nonce':globalwpw.settings.obj.ajax_nonce};
|
|
1063
|
|
- wpwKits.ajax(data).done(function (response) {
|
|
1064
|
|
- var json=$.parseJSON(response);
|
|
1065
|
|
- var orPhoneSuggest='';
|
|
1066
|
|
- if(json.status=='success'){
|
|
1067
|
|
- var sucMsg=json.message;
|
|
1068
|
|
- wpwMsg.single(sucMsg);
|
|
1069
|
|
- //Asking email after showing answer.
|
|
1070
|
|
- setTimeout(function(){
|
|
1071
|
|
- if(globalwpw.settings.obj.call_sup=="") {
|
|
1072
|
|
- orPhoneSuggest = '<span class="qcld-chatbot-suggest-phone" >' + wpwKits.randomMsg(globalwpw.settings.obj.support_phone) + '</span>';
|
|
1073
|
|
- }
|
|
1074
|
|
- var orEmailSuggest='<span class="qcld-chatbot-suggest-email" >'+wpwKits.randomMsg(globalwpw.settings.obj.support_email)+'</span>';
|
|
1075
|
|
- wpwKits.suggestEmail(orEmailSuggest+orPhoneSuggest);
|
|
1076
|
|
- globalwpw.wildCard=0;
|
|
1077
|
|
- },globalwpw.settings.preLoadingTime);
|
|
1078
|
|
- }else{
|
|
1079
|
|
- var failMsg=json.message;
|
|
1080
|
|
- wpwMsg.single(failMsg);
|
|
1081
|
|
- //Asking email after showing answer.
|
|
1082
|
|
- setTimeout(function(){
|
|
1083
|
|
- if(globalwpw.settings.obj.call_sup=="") {
|
|
1084
|
|
- orPhoneSuggest = '<span class="qcld-chatbot-suggest-phone" >' + wpwKits.randomMsg(globalwpw.settings.obj.support_phone) + '</span>';
|
|
1085
|
|
- }
|
|
1086
|
|
- var orEmailSuggest='<span class="qcld-chatbot-suggest-email" >'+wpwKits.randomMsg(globalwpw.settings.obj.support_email)+'</span>';
|
|
1087
|
|
- wpwKits.suggestEmail(orEmailSuggest+orPhoneSuggest);
|
|
1088
|
|
- globalwpw.wildCard=0;
|
|
1089
|
|
- },globalwpw.settings.preLoadingTime);
|
|
1090
|
|
- }
|
|
1091
|
|
- });
|
|
1092
|
|
- }else if(globalwpw.wildCard==1 && globalwpw.supportStep=='search'){
|
|
1093
|
|
- msg = wpwKits.filterStopWords(msg);
|
|
1094
|
|
- var data = {'action':'wpbo_search_site','name':globalwpw.hasNameCookie,'keyword':msg, 'security':wp_chatbot_obj.ajax_nonce };
|
|
1095
|
|
- wpwKits.ajax(data).done(function (response) {
|
|
1096
|
|
- var json=$.parseJSON(response);
|
|
1097
|
|
- if(json.status=='success'){
|
|
1098
|
|
- wpwMsg.double_nobg(wp_chatbot_obj.found_result_message,json.html);
|
|
1099
|
|
- }else{
|
|
1100
|
|
-
|
|
1101
|
|
- wpwMsg.single( wpwKits.randomMsg(wp_chatbot_obj.product_fail));
|
|
1102
|
|
-
|
|
1103
|
|
- // setTimeout(function(){
|
|
1104
|
|
- // var serviceOffer=wpwKits.randomMsg(globalwpw.settings.obj.support_option_again);
|
|
1105
|
|
- // wpwMsg.double_nobg(serviceOffer,globalwpw.wildcards);
|
|
1106
|
|
- // },globalwpw.settings.preLoadingTime)
|
|
1107
|
|
- }
|
|
1108
|
|
- });
|
|
1109
|
|
- }//
|
|
1110
|
|
- },
|
|
1111
|
|
- formbuilder:function(msg){
|
|
1112
|
|
- if(globalwpw.wildCard==7 && globalwpw.formStep=='welcome'){
|
|
1113
|
|
- var data = {'action':'wpbot_get_form','formid':msg};
|
|
1114
|
|
- wpwKits.ajax(data).done(function (response) {
|
|
1115
|
|
- if(response!=''){
|
|
1116
|
|
- var json=$.parseJSON(response);
|
|
1117
|
|
- globalwpw.prevform = json.ID;
|
|
1118
|
|
- globalwpw.formfieldid = json.ID;
|
|
1119
|
|
- localStorage.setItem("formfieldid", globalwpw.formfieldid);
|
|
1120
|
|
- globalwpw.formStep='field';
|
|
1121
|
|
- localStorage.setItem("formStep", globalwpw.formStep);
|
|
1122
|
|
- globalwpw.formid=msg;
|
|
1123
|
|
- localStorage.setItem("formid", globalwpw.formid);
|
|
1124
|
|
- localStorage.setItem("wildCard", globalwpw.wildCard);
|
|
1125
|
|
- var label = json.label;
|
|
1126
|
|
- if(json.type=='dropdown'){
|
|
1127
|
|
- var html = '';
|
|
1128
|
|
- jQuery.each(json.config.option, function(key, value){
|
|
1129
|
|
- html += '<span class="qcld-chatbot-wildcard qcld-chatbot-formanswer" data-form-value="'+value.value+'" >'+value.label+'</span>';
|
|
1130
|
|
- })
|
|
1131
|
|
- wpwMsg.double(label, html);
|
|
1132
|
|
- }else if(json.type=='checkbox'){
|
|
1133
|
|
- var html = '';
|
|
1134
|
|
- jQuery.each(json.config.option, function(key, value){
|
|
1135
|
|
- html += '<input type="checkbox" class="qcld-chatbot-checkbox" value="'+value.value+'">'+value.label+'<br>';
|
|
1136
|
|
- })
|
|
1137
|
|
- wpwMsg.double(label, html);
|
|
1138
|
|
- }else if(json.type=='html'){
|
|
1139
|
|
- wpwMsg.single(json.config.default);
|
|
1140
|
|
- globalwpw.formfieldid = json.ID;
|
|
1141
|
|
- localStorage.setItem("formfieldid", globalwpw.formfieldid);
|
|
1142
|
|
- globalwpw.formentry = json.entry;
|
|
1143
|
|
- localStorage.setItem("formentry", globalwpw.formentry);
|
|
1144
|
|
- setTimeout(function(){
|
|
1145
|
|
- wpwTree.formbuilder();
|
|
1146
|
|
- }, globalwpw.settings.preLoadingTime)
|
|
1147
|
|
- }else{
|
|
1148
|
|
- wpwMsg.single(label);
|
|
1149
|
|
- }
|
|
1150
|
|
- }
|
|
1151
|
|
- })
|
|
1152
|
|
- }else if(globalwpw.wildCard==7 && globalwpw.formStep=='field'){
|
|
1153
|
|
- var data = {'action':'wpbot_capture_form_value','formid':globalwpw.formid, 'fieldid': globalwpw.formfieldid, 'answer': msg, 'entry':globalwpw.formentry,'session': localStorage.getItem('botsessionid'), 'name': globalwpw.hasNameCookie,'email':localStorage.getItem('shopperemail'), 'url': window.location.href};
|
|
1154
|
|
- wpwKits.ajax(data).done(function (response) {
|
|
1155
|
|
- var json=$.parseJSON(response);
|
|
1156
|
|
- if(json.status=='incomplete'){
|
|
1157
|
|
- if( json.type !='html' ){
|
|
1158
|
|
- if($('.chatbot_intent_reload').length > 0){
|
|
1159
|
|
- $('.chatbot_intent_reload').remove();
|
|
1160
|
|
- }
|
|
1161
|
|
- $('#wp-chatbot-editor-container').append('<span class="chatbot_intent_reload" title="Click to go back." data-wildcard="7" data-step="welcome" data-intent-type="formbuilder" data-intent="'+globalwpw.prevform+'"><i class="dashicons dashicons-controls-repeat"></i></span>');
|
|
1162
|
|
- globalwpw.prevform = globalwpw.formfieldid;
|
|
1163
|
|
- }
|
|
1164
|
|
- globalwpw.formStep='field';
|
|
1165
|
|
- localStorage.setItem("formStep", globalwpw.formStep);
|
|
1166
|
|
- globalwpw.formfieldid = json.ID;
|
|
1167
|
|
- localStorage.setItem("formfieldid", globalwpw.formfieldid);
|
|
1168
|
|
- globalwpw.formentry = json.entry;
|
|
1169
|
|
- localStorage.setItem("formentry", globalwpw.formentry);
|
|
1170
|
|
- var label = json.label;
|
|
1171
|
|
- if(json.type=='dropdown'){
|
|
1172
|
|
- var html = '';
|
|
1173
|
|
- jQuery.each(json.config.option, function(key, value){
|
|
1174
|
|
- html += '<span class="qcld-chatbot-wildcard qcld-chatbot-formanswer" data-form-value="'+value.value+'" >'+value.label+'</span>';
|
|
1175
|
|
- })
|
|
1176
|
|
- wpwMsg.double(label, html);
|
|
1177
|
|
- }else if(json.type=='html'){
|
|
1178
|
|
- wpwMsg.single(json.config.default);
|
|
1179
|
|
- globalwpw.formfieldid = json.ID;
|
|
1180
|
|
- localStorage.setItem("formfieldid", globalwpw.formfieldid);
|
|
1181
|
|
- globalwpw.formentry = json.entry;
|
|
1182
|
|
- localStorage.setItem("formentry", globalwpw.formentry);
|
|
1183
|
|
- setTimeout(function(){
|
|
1184
|
|
- wpwTree.formbuilder();
|
|
1185
|
|
- }, 500)
|
|
1186
|
|
- }else if(json.type=='checkbox'){
|
|
1187
|
|
- jQuery('.qcld-chatbot-checkbox').val('');
|
|
1188
|
|
- var html = '';
|
|
1189
|
|
- jQuery.each(json.config.option, function(key, value){
|
|
1190
|
|
- html += '<input type="checkbox" class="qcld-chatbot-checkbox" value="'+value.value+'">'+value.label+'<br>';
|
|
1191
|
|
- })
|
|
1192
|
|
- wpwMsg.double(label, html);
|
|
1193
|
|
- }else if(json.type=='date_picker'){
|
|
1194
|
|
- if(json.hasOwnProperty("additional") && json.additional!=''){
|
|
1195
|
|
- label +='<i class="wpbot_addition_label">'+json.additional+'</i>';
|
|
1196
|
|
- }
|
|
1197
|
|
- wpwMsg.single(label);
|
|
1198
|
|
- jQuery('#wp-chatbot-editor').blur();
|
|
1199
|
|
- jQuery('#wp-chatbot-editor').datetimepicker();
|
|
1200
|
|
- }else if(json.type=='number'){
|
|
1201
|
|
- if(json.hasOwnProperty("additional") && json.additional!=''){
|
|
1202
|
|
- label +='<i class="wpbot_addition_label">'+json.additional+'</i>';
|
|
1203
|
|
- }
|
|
1204
|
|
- wpwMsg.single(label);
|
|
1205
|
|
- jQuery('#wp-chatbot-editor').addClass("qcnumberfield");
|
|
1206
|
|
- if(json.hasOwnProperty("config") && json.config.hasOwnProperty("min") && json.config.min>0){
|
|
1207
|
|
- jQuery('#wp-chatbot-editor').attr("minlength", json.config.min);
|
|
1208
|
|
- }
|
|
1209
|
|
- if(json.hasOwnProperty("config") && json.config.hasOwnProperty("max") && json.config.max>0){
|
|
1210
|
|
- jQuery('#wp-chatbot-editor').attr("maxlength", json.config.max);
|
|
1211
|
|
- }
|
|
1212
|
|
- }else if(json.type=='email'){
|
|
1213
|
|
- if(json.hasOwnProperty("additional") && json.additional!=''){
|
|
1214
|
|
- label +='<i class="wpbot_addition_label">'+json.additional+'</i>';
|
|
1215
|
|
- }
|
|
1216
|
|
- wpwMsg.single(label);
|
|
1217
|
|
- jQuery('#wp-chatbot-editor').attr("type", "email");
|
|
1218
|
|
- }else if(json.type=='url'){
|
|
1219
|
|
- if(json.hasOwnProperty("additional") && json.additional!=''){
|
|
1220
|
|
- label +='<i class="wpbot_addition_label">'+json.additional+'</i>';
|
|
1221
|
|
- }
|
|
1222
|
|
- wpwMsg.single(label);
|
|
1223
|
|
- jQuery('#wp-chatbot-editor').attr("type", "url");
|
|
1224
|
|
- }else if(json.type=='phone'){
|
|
1225
|
|
- wpwMsg.single(label);
|
|
1226
|
|
- jQuery('#wp-chatbot-editor').addClass('qcphonebasicus');
|
|
1227
|
|
- }else if(json.type=='calculation'){
|
|
1228
|
|
- let calresult = json.calresult;
|
|
1229
|
|
- calresult = eval(calresult);
|
|
1230
|
|
- setTimeout(function(){
|
|
1231
|
|
- var cal = (json.calbefore +' '+ calresult.toFixed(2) +' '+ json.calafter)
|
|
1232
|
|
- wpwTree.formbuilder(cal);
|
|
1233
|
|
- wpwMsg.single(cal);
|
|
1234
|
|
- }, globalwpw.settings.preLoadingTime)
|
|
1235
|
|
- }else if(json.type=='hidden'){
|
|
1236
|
|
- var email = json.config.default;
|
|
1237
|
|
- if( globalwpw.settings.obj.order_login == 1 && json.slug=='email' ){
|
|
1238
|
|
- email = globalwpw.settings.obj.order_email;
|
|
1239
|
|
- }
|
|
1240
|
|
- wpwTree.formbuilder(email);
|
|
1241
|
|
- }else if(json.type=='text'){
|
|
1242
|
|
- wpwMsg.single(label);
|
|
1243
|
|
- }else{
|
|
1244
|
|
- // wpwMsg.single(label);
|
|
1245
|
|
- }
|
|
1246
|
|
- }else{
|
|
1247
|
|
- if($('.chatbot_intent_reload').length > 0){
|
|
1248
|
|
- $('.chatbot_intent_reload').attr('data-step', 'complete');
|
|
1249
|
|
- }
|
|
1250
|
|
- globalwpw.formfieldid = '';
|
|
1251
|
|
- localStorage.setItem("formfieldid", globalwpw.formfieldid);
|
|
1252
|
|
- globalwpw.formStep='welcome';
|
|
1253
|
|
- localStorage.setItem("formStep", globalwpw.formStep);
|
|
1254
|
|
- globalwpw.formid='';
|
|
1255
|
|
- localStorage.setItem("formid", globalwpw.formid);
|
|
1256
|
|
- globalwpw.wildCard = 0;
|
|
1257
|
|
- localStorage.setItem("wildCard", globalwpw.wildCard);
|
|
1258
|
|
- globalwpw.formentry = 0;
|
|
1259
|
|
- localStorage.setItem("formentry", globalwpw.formentry);
|
|
1260
|
|
- var serviceOffer=wpwKits.randomMsg(globalwpw.settings.obj.wildcard_msg);
|
|
1261
|
|
- setTimeout(function(){
|
|
1262
|
|
- wpwMsg.single_nobg('<span class="qcld-chatbot-wildcard qcld_back_to_start" data-wildcart="back">' + wpwKits.randomMsg(globalwpw.settings.obj.back_to_start) + '</span>');
|
|
1263
|
|
- }, globalwpw.settings.preLoadingTime);
|
|
1264
|
|
- if(jQuery('.chatbot_intent_reload').length>0){
|
|
1265
|
|
- jQuery('.chatbot_intent_reload').remove();
|
|
1266
|
|
- }
|
|
1267
|
|
- }
|
|
1268
|
|
- })
|
|
1269
|
|
- }
|
|
1270
|
|
- },
|
|
1271
|
|
- formbuilder_force_complete:function(msg){
|
|
1272
|
|
- //destroy date picker
|
|
1273
|
|
- //if ( jQuery.isFunction(jQuery.fn.datetimepicker) ) {
|
|
1274
|
|
- if ( typeof jQuery.fn.datetimepicker === 'function' ) {
|
|
1275
|
|
- jQuery('#wp-chatbot-editor').datetimepicker('destroy');
|
|
1276
|
|
- }
|
|
1277
|
|
- jQuery('#wp-chatbot-editor').attr("type", "text");
|
|
1278
|
|
- jQuery('#wp-chatbot-editor').prop("disabled", false);
|
|
1279
|
|
- jQuery('#wp-chatbot-editor').removeAttr("multiple");
|
|
1280
|
|
- jQuery('#wp-chatbot-editor').removeClass('qcphonebasicus');
|
|
1281
|
|
- jQuery('#wp-chatbot-editor').removeClass("qcnumberfield");
|
|
1282
|
|
- jQuery('#wp-chatbot-editor').removeAttr("minlength");
|
|
1283
|
|
- jQuery('#wp-chatbot-editor').removeAttr("maxlength");
|
|
1284
|
|
- if(globalwpw.wildCard==7 && globalwpw.formStep=='field'){
|
|
1285
|
|
- var data = {'action':'wpbot_capture_form_value','formid':globalwpw.formid, 'fieldid': globalwpw.formfieldid, 'answer': msg, 'entry':globalwpw.formentry, 'session': localStorage.getItem('botsessionid'), 'name':globalwpw.hasNameCookie, 'email':localStorage.getItem('shopperemail'), 'url': window.location.href, 'do_complete': 1};
|
|
1286
|
|
- globalwpw.formfieldid = '';
|
|
1287
|
|
- localStorage.setItem("formfieldid", globalwpw.formfieldid);
|
|
1288
|
|
- globalwpw.formStep='welcome';
|
|
1289
|
|
- localStorage.setItem("formStep", globalwpw.formStep);
|
|
1290
|
|
- globalwpw.formid='';
|
|
1291
|
|
- localStorage.setItem("formid", globalwpw.formid);
|
|
1292
|
|
- globalwpw.wildCard = 0;
|
|
1293
|
|
- localStorage.setItem("wildCard", globalwpw.wildCard);
|
|
1294
|
|
- globalwpw.formentry = 0;
|
|
1295
|
|
- localStorage.setItem("formentry", globalwpw.formentry);
|
|
1296
|
|
- wpwKits.ajax(data).done(function (response) {
|
|
1297
|
|
- var json=$.parseJSON(response);
|
|
1298
|
|
- if( json.status == 'complete' ){
|
|
1299
|
|
- //
|
|
1300
|
|
- }
|
|
1301
|
|
- })
|
|
1302
|
|
- }
|
|
1303
|
|
- },
|
|
1304
|
|
- reset: function( msg ){
|
|
1305
|
|
- if( globalwpw.wildCard == 25 && globalwpw.resetStep == 'welcome' ){
|
|
1306
|
|
- var restWarning= globalwpw.settings.obj.reset;
|
|
1307
|
|
- var confirmBtn='<span class="qcld-chatbot-reset-btn" reset-data="yes" >'+globalwpw.settings.obj.yes+'</span> <span> '+globalwpw.settings.obj.or+' </span><span class="qcld-chatbot-reset-btn" reset-data="no">'+globalwpw.settings.obj.no+'</span>';
|
|
1308
|
|
- globalwpw.resetStep = 'answer'
|
|
1309
|
|
- wpwMsg.double_nobg(restWarning,confirmBtn);
|
|
1310
|
|
- setTimeout(function(){
|
|
1311
|
|
- // wpwKits.disableEditor('');
|
|
1312
|
|
- }, 1500)
|
|
1313
|
|
- }else if( globalwpw.wildCard == 25 && globalwpw.resetStep == 'answer' ){
|
|
1314
|
|
- if( msg.toLowerCase() == globalwpw.settings.obj.yes.toLowerCase() ){
|
|
1315
|
|
- wpwKits.reset();
|
|
1316
|
|
- var number = Math.random() // 0.9394456857981651
|
|
1317
|
|
- number.toString(36); // '0.xtis06h6'
|
|
1318
|
|
- var id = number.toString(36).substr(2); // 'xtis06h6'
|
|
1319
|
|
- localStorage.setItem('botsessionid', id);
|
|
1320
|
|
- wpwWelcome.greeting();
|
|
1321
|
|
- wpwKits.enableEditor(wpwKits.randomMsg(globalwpw.settings.obj.send_a_msg));
|
|
1322
|
|
- }else if( msg.toLowerCase() == globalwpw.settings.obj.no.toLowerCase() ){
|
|
1323
|
|
-
|
|
1324
|
|
- wpwAction.bot(globalwpw.settings.obj.sys_key_help.toLowerCase());
|
|
1325
|
|
- wpwKits.enableEditor(wpwKits.randomMsg(globalwpw.settings.obj.send_a_msg));
|
|
1326
|
|
- }
|
|
1327
|
|
- globalwpw.wildCard = 0;
|
|
1328
|
|
- globalwpw.resetStep = 'welcome'
|
|
1329
|
|
- }
|
|
1330
|
|
- },
|
|
1331
|
|
- formatResponse: function(response) {
|
|
1332
|
|
- let cleanResponse = response.replace(/(\w+)\n/g,'');
|
|
1333
|
|
- cleanResponse = cleanResponse.replace(/(.*?)/gs, '<pre>$1</pre>');
|
|
1334
|
|
- cleanResponse = cleanResponse.replace(/(.*?)/g, '<code>$1</code>');
|
|
1335
|
|
- return cleanResponse;
|
|
1336
|
|
- },
|
|
1337
|
|
- openai_reply:function(msg){
|
|
1338
|
|
-
|
|
1339
|
|
- if(globalwpw.settings.obj.openai_enabled == 1){
|
|
1340
|
|
-
|
|
1341
|
|
- var customAappend = globalwpw.settings.obj.qcld_openai_append_content;
|
|
1342
|
|
- var customMessage = customAappend ? msg + ' ' + customAappend : msg;
|
|
1343
|
|
-
|
|
1344
|
|
- if(wp_chatbot_obj.is_stream_enabled == '1'){
|
|
1345
|
|
- // Callers already append botPreloader before calling openai_reply
|
|
1346
|
|
- var streamData = {
|
|
1347
|
|
- action: 'qcld_stream_openai',
|
|
1348
|
|
- name: globalwpw.hasNameCookie,
|
|
1349
|
|
- keyword: customMessage,
|
|
1350
|
|
- nonce: qcld_chatbot_obj.nonce
|
|
1351
|
|
- };
|
|
1352
|
|
- qcldStreamOpenAI(streamData);
|
|
1353
|
|
- } else {
|
|
1354
|
|
- var data = {'action':'qcld_openai_response','name':globalwpw.hasNameCookie,'keyword':customMessage,nonce: qcld_chatbot_obj.nonce};
|
|
1355
|
|
-
|
|
1356
|
|
- wpwKits.ajax(data).done(function (res) {
|
|
1357
|
|
- if( res == '' || typeof res === 'object' ){
|
|
1358
|
|
- var json = res;
|
|
1359
|
|
- }if(typeof res === 'string'){
|
|
1360
|
|
- var json = $.parseJSON(res);
|
|
1361
|
|
- }
|
|
1362
|
|
-
|
|
1363
|
|
- if(json.status=='success'){
|
|
1364
|
|
- var serviceOffer=wpwKits.randomMsg(globalwpw.settings.obj.support_option_again);
|
|
1365
|
|
-
|
|
1366
|
|
- setTimeout(function(){
|
|
1367
|
|
- wpwMsg.single(json.message);
|
|
1368
|
|
-
|
|
1369
|
|
- if((globalwpw.settings.obj.qcld_disable_repited_startmenu != "1")){
|
|
1370
|
|
- if(globalwpw.settings.obj.disable_repeatative!=1){
|
|
1371
|
|
- setTimeout(function(){
|
|
1372
|
|
- var serviceOffer=wpwKits.randomMsg(globalwpw.settings.obj.support_option_again);
|
|
1373
|
|
- if((globalwpw.settings.obj.qcld_disable_start_menu != "1")){
|
|
1374
|
|
- wpwMsg.single_nobg('<span class="qcld-chatbot-wildcard qcld_back_to_start" data-wildcart="back">' + wpwKits.randomMsg(globalwpw.settings.obj.back_to_start) + '</span>');
|
|
1375
|
|
- }
|
|
1376
|
|
- },globalwpw.settings.preLoadingTime)
|
|
1377
|
|
- }else{
|
|
1378
|
|
- setTimeout(function(){
|
|
1379
|
|
- if((globalwpw.settings.obj.qcld_disable_repited_startmenu != "1") && ((globalwpw.settings.obj.disable_back_to_start != '1' && globalwpw.settings.obj.skip_greetings_and_menu != 1))){
|
|
1380
|
|
- wpwMsg.single_nobg('<span class="qcld-chatbot-wildcard qcld_back_to_start" data-wildcart="back">' + wpwKits.randomMsg(globalwpw.settings.obj.back_to_start) + '</span>');
|
|
1381
|
|
- }
|
|
1382
|
|
- }, globalwpw.settings.preLoadingTime*2);
|
|
1383
|
|
- }
|
|
1384
|
|
- }
|
|
1385
|
|
- $(globalwpw.settings.messageContainer).find('.wp-chatbot-msg:last .qcld-like-dislike-icon').css('display', 'block');
|
|
1386
|
|
-
|
|
1387
|
|
- },globalwpw.settings.preLoadingTime)
|
|
1388
|
|
- }
|
|
1389
|
|
- })
|
|
1390
|
|
- }
|
|
1391
|
|
- }
|
|
1392
|
|
- if(globalwpw.settings.obj.openrouter_enabled == 1){
|
|
1393
|
|
-
|
|
1394
|
|
- var customAappend = globalwpw.settings.obj.qcld_openrouter_append_content;
|
|
1395
|
|
- var customprepend = globalwpw.settings.obj.qcld_openrouter_prepend_content;
|
|
1396
|
|
- var customMessage = customprepend ? customprepend + ' ' + msg : msg;
|
|
1397
|
|
- customMessage = customAappend ? customMessage + ' ' + customAappend : customMessage;
|
|
1398
|
|
-
|
|
1399
|
|
- var data = {'action':'openrouter_response','name':globalwpw.hasNameCookie,'keyword':customMessage};
|
|
1400
|
|
- wpwKits.ajax(data).done(function (res) {
|
|
1401
|
|
- if( res == '' || typeof res === 'object' ){
|
|
1402
|
|
- var json = res;
|
|
1403
|
|
- }if(typeof res === 'string'){
|
|
1404
|
|
- var json = $.parseJSON(res);
|
|
1405
|
|
- }
|
|
1406
|
|
- if(json.status=='success'){
|
|
1407
|
|
- var serviceOffer=wpwKits.randomMsg(globalwpw.settings.obj.support_option_again);
|
|
1408
|
|
-
|
|
1409
|
|
- setTimeout(function(){
|
|
1410
|
|
- wpwMsg.single(json.message);
|
|
1411
|
|
-
|
|
1412
|
|
- if((globalwpw.settings.obj.qcld_disable_repited_startmenu != "1" && (globalwpw.settings.obj.disable_back_to_start != '1' && globalwpw.settings.obj.skip_greetings_and_menu != 1))){
|
|
1413
|
|
- if(globalwpw.settings.obj.disable_repeatative!=1){
|
|
1414
|
|
- setTimeout(function(){
|
|
1415
|
|
- var serviceOffer=wpwKits.randomMsg(globalwpw.settings.obj.support_option_again);
|
|
1416
|
|
- if((globalwpw.settings.obj.qcld_disable_start_menu != "1")){
|
|
1417
|
|
- wpwMsg.single_nobg('<span class="qcld-chatbot-wildcard qcld_back_to_start" data-wildcart="back">' + wpwKits.randomMsg(globalwpw.settings.obj.back_to_start) + '</span>');
|
|
1418
|
|
- }
|
|
1419
|
|
- },globalwpw.settings.preLoadingTime)
|
|
1420
|
|
- }else{
|
|
1421
|
|
- setTimeout(function(){
|
|
1422
|
|
- if((globalwpw.settings.obj.qcld_disable_repited_startmenu != "1")){
|
|
1423
|
|
- wpwMsg.single_nobg('<span class="qcld-chatbot-wildcard qcld_back_to_start" data-wildcart="back">' + wpwKits.randomMsg(globalwpw.settings.obj.back_to_start) + '</span>');
|
|
1424
|
|
- }
|
|
1425
|
|
- }, globalwpw.settings.preLoadingTime*2);
|
|
1426
|
|
- }
|
|
1427
|
|
- }
|
|
1428
|
|
- },globalwpw.settings.preLoadingTime)
|
|
1429
|
|
- }else{
|
|
1430
|
|
- wpwMsg.single_nobg('<span class="qcld-chatbot-wildcard qcld_back_to_start" data-wildcart="back">' + 'Sorry, I encountered an error processing your AI request. Please check api key and try again later.' + '</span>');
|
|
1431
|
|
- }
|
|
1432
|
|
- })
|
|
1433
|
|
- }
|
|
1434
|
|
- if(globalwpw.settings.obj.gemini_enabled == 1){
|
|
1435
|
|
- var customAappend = globalwpw.settings.obj.qcld_openrouter_append_content;
|
|
1436
|
|
- var customprepend = globalwpw.settings.obj.qcld_openrouter_prepend_content;
|
|
1437
|
|
- var customMessage = customprepend ? customprepend + ' ' + msg : msg;
|
|
1438
|
|
- customMessage = customAappend ? customMessage + ' ' + customAappend : customMessage;
|
|
1439
|
|
-
|
|
1440
|
|
- var data = {'action':'qcld_gemini_response','name':globalwpw.hasNameCookie,'keyword':customMessage, nonce: qcld_chatbot_obj.nonce};
|
|
1441
|
|
- wpwKits.ajax(data).done(function (res) {
|
|
1442
|
|
- if( res == '' || typeof res === 'object' ){
|
|
1443
|
|
- var json = res;
|
|
1444
|
|
- }if(typeof res === 'string'){
|
|
1445
|
|
- var json = $.parseJSON(res);
|
|
1446
|
|
- }
|
|
1447
|
|
-
|
|
1448
|
|
- if(json.status=='success'){
|
|
1449
|
|
- var serviceOffer=wpwKits.randomMsg(globalwpw.settings.obj.support_option_again);
|
|
1450
|
|
-
|
|
1451
|
|
- setTimeout(function(){
|
|
1452
|
|
- wpwMsg.single(json.message);
|
|
1453
|
|
-
|
|
1454
|
|
- if((globalwpw.settings.obj.qcld_disable_repited_startmenu != "1")){
|
|
1455
|
|
- if(globalwpw.settings.obj.disable_repeatative!=1){
|
|
1456
|
|
- setTimeout(function(){
|
|
1457
|
|
- var serviceOffer=wpwKits.randomMsg(globalwpw.settings.obj.support_option_again);
|
|
1458
|
|
- if((globalwpw.settings.obj.qcld_disable_start_menu != "1" && (globalwpw.settings.obj.disable_back_to_start != '1' && globalwpw.settings.obj.skip_greetings_and_menu != 1))){
|
|
1459
|
|
- wpwMsg.single_nobg('<span class="qcld-chatbot-wildcard qcld_back_to_start" data-wildcart="back">' + wpwKits.randomMsg(globalwpw.settings.obj.back_to_start) + '</span>');
|
|
1460
|
|
- }
|
|
1461
|
|
- },globalwpw.settings.preLoadingTime)
|
|
1462
|
|
- }else{
|
|
1463
|
|
- setTimeout(function(){
|
|
1464
|
|
- if((globalwpw.settings.obj.qcld_disable_repited_startmenu != "1" && (globalwpw.settings.obj.disable_back_to_start != '1' && globalwpw.settings.obj.skip_greetings_and_menu != 1))){
|
|
1465
|
|
- wpwMsg.single_nobg('<span class="qcld-chatbot-wildcard qcld_back_to_start" data-wildcart="back">' + wpwKits.randomMsg(globalwpw.settings.obj.back_to_start) + '</span>');
|
|
1466
|
|
- }
|
|
1467
|
|
- }, globalwpw.settings.preLoadingTime*2);
|
|
1468
|
|
- }
|
|
1469
|
|
- }
|
|
1470
|
|
- },globalwpw.settings.preLoadingTime)
|
|
1471
|
|
- }else{
|
|
1472
|
|
- wpwMsg.single_nobg('<span class="qcld-chatbot-wildcard qcld_back_to_start" data-wildcart="back">' + 'Sorry, I encountered an error processing your AI request. Please check api key and try again later.' + '</span>');
|
|
1473
|
|
- }
|
|
1474
|
|
- })
|
|
1475
|
|
- }
|
|
1476
|
|
- if(globalwpw.settings.obj.grok_enabled == 1){
|
|
1477
|
|
- var customMessage = msg;
|
|
1478
|
|
- customMessage = customAappend ? customMessage + ' ' + customAappend : customMessage;
|
|
1479
|
|
- var data = {'action':'qcld_grok_response','name':globalwpw.hasNameCookie,'keyword':customMessage};
|
|
1480
|
|
- wpwKits.ajax(data).done(function (res) {
|
|
1481
|
|
- if( res == '' || typeof res === 'object' ){
|
|
1482
|
|
- var json = res;
|
|
1483
|
|
- }if(typeof res === 'string'){
|
|
1484
|
|
- var json = $.parseJSON(res);
|
|
1485
|
|
- }
|
|
1486
|
|
-
|
|
1487
|
|
- if(json.status=='success'){
|
|
1488
|
|
- var serviceOffer=wpwKits.randomMsg(globalwpw.settings.obj.support_option_again);
|
|
1489
|
|
-
|
|
1490
|
|
- setTimeout(function(){
|
|
1491
|
|
- wpwMsg.single(json.message);
|
|
1492
|
|
-
|
|
1493
|
|
- if((globalwpw.settings.obj.qcld_disable_repited_startmenu != "1")){
|
|
1494
|
|
- if(globalwpw.settings.obj.disable_repeatative!=1){
|
|
1495
|
|
- setTimeout(function(){
|
|
1496
|
|
- var serviceOffer=wpwKits.randomMsg(globalwpw.settings.obj.support_option_again);
|
|
1497
|
|
- if((globalwpw.settings.obj.qcld_disable_start_menu != "1" && (globalwpw.settings.obj.disable_back_to_start != '1' && globalwpw.settings.obj.skip_greetings_and_menu != 1))){
|
|
1498
|
|
- wpwMsg.single_nobg('<span class="qcld-chatbot-wildcard qcld_back_to_start" data-wildcart="back">' + wpwKits.randomMsg(globalwpw.settings.obj.back_to_start) + '</span>');
|
|
1499
|
|
- }
|
|
1500
|
|
- },globalwpw.settings.preLoadingTime)
|
|
1501
|
|
- }else{
|
|
1502
|
|
- setTimeout(function(){
|
|
1503
|
|
- if((globalwpw.settings.obj.qcld_disable_repited_startmenu != "1" && (globalwpw.settings.obj.disable_back_to_start != '1' && globalwpw.settings.obj.skip_greetings_and_menu != 1))){
|
|
1504
|
|
- wpwMsg.single_nobg('<span class="qcld-chatbot-wildcard qcld_back_to_start" data-wildcart="back">' + wpwKits.randomMsg(globalwpw.settings.obj.back_to_start) + '</span>');
|
|
1505
|
|
- }
|
|
1506
|
|
- }, globalwpw.settings.preLoadingTime*2);
|
|
1507
|
|
- }
|
|
1508
|
|
- }
|
|
1509
|
|
- },globalwpw.settings.preLoadingTime)
|
|
1510
|
|
- }else{
|
|
1511
|
|
- wpwMsg.single_nobg('<span class="qcld-chatbot-wildcard qcld_back_to_start" data-wildcart="back">' + 'Sorry, I encountered an error processing your AI request. Please check api key and try again later.' + '</span>');
|
|
1512
|
|
- }
|
|
1513
|
|
- })
|
|
1514
|
|
- }
|
|
1515
|
|
- },
|
|
1516
|
|
- site_search:function(msg){
|
|
1517
|
|
- msg1 = wpwKits.filterStopWords(msg);
|
|
1518
|
|
- var data = {'action':'wpbo_search_site','name':globalwpw.hasNameCookie,'keyword':msg1, 'security':wp_chatbot_obj.ajax_nonce};
|
|
1519
|
|
- wpwKits.ajax(data).done(function (res) {
|
|
1520
|
|
- var json=$.parseJSON(res);
|
|
1521
|
|
- $(globalwpw.settings.messageContainer).find('.wp-chatbot-msg:last .qcld-like-dislike-icon').css('display', 'block');
|
|
1522
|
|
-
|
|
1523
|
|
- if(json.status=='success'){
|
|
1524
|
|
- if((globalwpw.settings.obj.disable_back_to_start != '1' && globalwpw.settings.obj.skip_greetings_and_menu != 1)){
|
|
1525
|
|
- wpwMsg.triple_nobg( wp_chatbot_obj.found_result_message,json.html,'<span class="qcld-chatbot-wildcard" data-wildcart="back">' + wpwKits.randomMsg(globalwpw.settings.obj.back_to_start) + '</span>' );
|
|
1526
|
|
- }else{
|
|
1527
|
|
- wpwMsg.double_nobg( wp_chatbot_obj.found_result_message,json.html);
|
|
1528
|
|
- }
|
|
1529
|
|
- }else if( (globalwpw.settings.obj.openai_enabled == 1) || (wp_chatbot_obj.openai_enabled == 1) || (globalwpw.settings.obj.openrouter_enabled == 1) || (wp_chatbot_obj.openrouter_enabled == 1) || (globalwpw.settings.obj.gemini_enabled == 1) || (wp_chatbot_obj.gemini_enabled == 1) || (globalwpw.settings.obj.grok_enabled == 1) || (wp_chatbot_obj.grok_enabled == 1) ){
|
|
1530
|
|
- if($(globalwpw.settings.messageLastChild+' .wp-chatbot-comment-loader').length==0){
|
|
1531
|
|
- $(globalwpw.settings.messageContainer).append(wpwKits.botPreloader());
|
|
1532
|
|
- }
|
|
1533
|
|
- wpwTree.openai_reply(msg);
|
|
1534
|
|
- }else{
|
|
1535
|
|
- if((globalwpw.settings.obj.disable_back_to_start != '1' && globalwpw.settings.obj.skip_greetings_and_menu != 1)){
|
|
1536
|
|
- wpwMsg.double_nobg( wpwKits.randomMsg(wp_chatbot_obj.product_fail ),'<span class="qcld-chatbot-wildcard qcld_back_to_start" data-wildcart="back">' + wpwKits.randomMsg(globalwpw.settings.obj.back_to_start) + '</span>');
|
|
1537
|
|
- }else{
|
|
1538
|
|
- wpwMsg.single( wpwKits.randomMsg(wp_chatbot_obj.product_fail ));
|
|
1539
|
|
- }
|
|
1540
|
|
- }
|
|
1541
|
|
- })
|
|
1542
|
|
- }
|
|
1543
|
|
- };
|
|
1544
|
|
- /*
|
|
1545
|
|
- * wpwbot Actions are divided into two part
|
|
1546
|
|
- * shopper will response after initialize message,
|
|
1547
|
|
- * then based on shopper activities shopper will act.
|
|
1548
|
|
- */
|
|
1549
|
|
- var wpwAction={
|
|
1550
|
|
- findkey:function(array, msg){
|
|
1551
|
|
- var index = -1;
|
|
1552
|
|
- $.each( array, function( key, value ) {
|
|
1553
|
|
- value = jQuery.map(value, function(n,i){return n.toLowerCase();});
|
|
1554
|
|
- if(value.indexOf(msg.toLowerCase()) > -1){
|
|
1555
|
|
- index = key;
|
|
1556
|
|
- return false;
|
|
1557
|
|
- }
|
|
1558
|
|
- });
|
|
1559
|
|
- return index;
|
|
1560
|
|
- },
|
|
1561
|
|
- bot:function(msg){
|
|
1562
|
|
- var simple_response_intent = globalwpw.settings.obj.simple_response_intent;
|
|
1563
|
|
- if(simple_response_intent.length>0){
|
|
1564
|
|
- simple_response_intent = jQuery.map(simple_response_intent, function(n,i){return n.toLowerCase();});
|
|
1565
|
|
- }
|
|
1566
|
|
- var allformname = jQuery.map(globalwpw.settings.obj.forms, function(n,i){return n.toLowerCase();});
|
|
1567
|
|
- var allformcommand = globalwpw.settings.obj.form_commands;
|
|
1568
|
|
- if(globalwpw.wildcardsHelp.indexOf(msg.toLowerCase())>-1){
|
|
1569
|
|
-
|
|
1570
|
|
- if(globalwpw.wildCard==7){
|
|
1571
|
|
- wpwTree.formbuilder_force_complete( msg );
|
|
1572
|
|
- }
|
|
1573
|
|
- if(msg.toLowerCase()==globalwpw.settings.obj.sys_key_help.toLowerCase()){
|
|
1574
|
|
-
|
|
1575
|
|
- globalwpw.wildCard=0;
|
|
1576
|
|
- var serviceOffer=wpwKits.randomMsg(globalwpw.settings.obj.wildcard_msg);
|
|
1577
|
|
- wpwMsg.double_nobg(serviceOffer,globalwpw.wildcards);
|
|
1578
|
|
- }
|
|
1579
|
|
- if(msg.toLowerCase()==globalwpw.settings.obj.sys_key_support.toLowerCase()){
|
|
1580
|
|
- globalwpw.wildCard=1;
|
|
1581
|
|
- globalwpw.supportStep='welcome';
|
|
1582
|
|
- wpwTree.support(msg);
|
|
1583
|
|
- }
|
|
1584
|
|
- // if(msg.toLowerCase()==globalwpw.settings.obj.sys_key_product.toLowerCase()){
|
|
1585
|
|
- // globalwpw.wildCard=20;
|
|
1586
|
|
- // globalwpw.productStep='asking';
|
|
1587
|
|
- // // wpwTree.product(msg);
|
|
1588
|
|
- // }
|
|
1589
|
|
- if(globalwpw.settings.obj.woocommerce){
|
|
1590
|
|
- if(msg.toLowerCase()==globalwpw.settings.obj.sys_key_catalog.toLowerCase()){
|
|
1591
|
|
- globalwpw.wildCard=20;
|
|
1592
|
|
- globalwpw.productStep='search';
|
|
1593
|
|
- wpwKits.sugestCat();
|
|
1594
|
|
- }
|
|
1595
|
|
- if(msg.toLowerCase()==globalwpw.settings.obj.sys_key_order.toLowerCase()){
|
|
1596
|
|
- globalwpw.wildCard=21;
|
|
1597
|
|
- globalwpw.orderStep='welcome';
|
|
1598
|
|
- wpwTree.order(msg);
|
|
1599
|
|
- }
|
|
1600
|
|
- }
|
|
1601
|
|
- if( globalwpw.settings.obj.open_a_ticket && msg.toLowerCase()==globalwpw.settings.obj.open_a_ticket.toLowerCase() && globalwpw.settings.obj.ticket_url!=''){
|
|
1602
|
|
- //comming
|
|
1603
|
|
- window.open(globalwpw.settings.obj.ticket_url, '_blank');
|
|
1604
|
|
- wpwKits.enableEditor(wpwKits.randomMsg(globalwpw.settings.obj.send_a_msg));
|
|
1605
|
|
- }
|
|
1606
|
|
- if(msg.toLowerCase()==globalwpw.settings.obj.sys_key_reset.toLowerCase()){
|
|
1607
|
|
- globalwpw.wildCard=25;
|
|
1608
|
|
- globalwpw.resetStep='welcome';
|
|
1609
|
|
- wpwTree.reset(msg);
|
|
1610
|
|
- }
|
|
1611
|
|
- if(msg.toLowerCase()==globalwpw.settings.obj.sys_key_email.toLowerCase()){
|
|
1612
|
|
- // var shopperChoice=$(this).text();
|
|
1613
|
|
- wpwMsg.shopper_choice(globalwpw.settings.obj.sys_key_email.toLowerCase());
|
|
1614
|
|
- //Then ask email address
|
|
1615
|
|
- if(typeof(globalwpw.hasNameCookie)=='undefined'|| globalwpw.hasNameCookie==''){
|
|
1616
|
|
- var shopperName= globalwpw.settings.obj.shopper_demo_name;
|
|
1617
|
|
- }else{
|
|
1618
|
|
- var shopperName=globalwpw.hasNameCookie;
|
|
1619
|
|
- }
|
|
1620
|
|
- var ask_msg = wpwKits.randomMsg(globalwpw.settings.obj.asking_email);
|
|
1621
|
|
- var askEmail = (globalwpw.settings.obj.skip_wp_greetings=='1' || globalwpw.settings.obj.skip_greetings_and_menu =='1') ? wpwKits.randomMsg(globalwpw.settings.obj.hello)+' '+ ask_msg : wpwKits.randomMsg(globalwpw.settings.obj.hello)+' '+shopperName+'! '+ ask_msg;
|
|
1622
|
|
- wpwMsg.single(askEmail);
|
|
1623
|
|
- globalwpw.supportStep='email';
|
|
1624
|
|
- globalwpw.wildCard=1;
|
|
1625
|
|
- localStorage.setItem("wildCard", globalwpw.wildCard);
|
|
1626
|
|
- localStorage.setItem("supportStep", globalwpw.supportStep);
|
|
1627
|
|
- }
|
|
1628
|
|
- if( globalwpw.settings.obj.sys_key_livechat && msg.toLowerCase()==globalwpw.settings.obj.sys_key_livechat.toLowerCase()){
|
|
1629
|
|
- wpwKits.enableEditor(wpwKits.randomMsg(globalwpw.settings.obj.send_a_msg));
|
|
1630
|
|
- if(globalwpw.settings.obj.is_livechat_active){
|
|
1631
|
|
- if(globalwpw.settings.obj.disable_livechat_operator_offline==1){
|
|
1632
|
|
- if(globalwpw.settings.obj.is_operator_online==1){
|
|
1633
|
|
- $(globalwpw.settings.messageWrapper).html(localStorage.getItem("wpwHitory"));
|
|
1634
|
|
- if($('#wbca_signup_fullname').length>0){
|
|
1635
|
|
- if(localStorage.getItem('shopper')!==null){
|
|
1636
|
|
- $('#wbca_signup_fullname').val(localStorage.getItem('shopper'));
|
|
1637
|
|
- }
|
|
1638
|
|
- if(localStorage.getItem('shopperemail')!==null){
|
|
1639
|
|
- $('#wbca_signup_email').val(localStorage.getItem('shopperemail'));
|
|
1640
|
|
- }
|
|
1641
|
|
- }
|
|
1642
|
|
- $("#wp-chatbot-board-container").removeClass('active-chat-board');
|
|
1643
|
|
- $('.wp-chatbot-container').hide();
|
|
1644
|
|
- $('.wpbot-saas-live-chat').show();
|
|
1645
|
|
- }
|
|
1646
|
|
- }else{
|
|
1647
|
|
- $(globalwpw.settings.messageWrapper).html(localStorage.getItem("wpwHitory"));
|
|
1648
|
|
- if($('#wbca_signup_fullname').length>0){
|
|
1649
|
|
- if(localStorage.getItem('shopper')!==null){
|
|
1650
|
|
- $('#wbca_signup_fullname').val(localStorage.getItem('shopper'));
|
|
1651
|
|
- }
|
|
1652
|
|
- if(localStorage.getItem('shopperemail')!==null){
|
|
1653
|
|
- $('#wbca_signup_email').val(localStorage.getItem('shopperemail'));
|
|
1654
|
|
- }
|
|
1655
|
|
- }
|
|
1656
|
|
- $("#wp-chatbot-board-container").removeClass('active-chat-board');
|
|
1657
|
|
- $('.wp-chatbot-container').hide();
|
|
1658
|
|
- $('.wpbot-saas-live-chat').show();
|
|
1659
|
|
- }
|
|
1660
|
|
- }
|
|
1661
|
|
- }
|
|
1662
|
|
- }else if(allformname.indexOf(msg.toLowerCase()) > -1 || this.findkey(allformcommand, msg)> -1){
|
|
1663
|
|
- //Form builder commands form name
|
|
1664
|
|
- if(globalwpw.wildCard==7){
|
|
1665
|
|
- wpwTree.formbuilder_force_complete( msg );
|
|
1666
|
|
- }
|
|
1667
|
|
- var index = (allformname.indexOf(msg.toLowerCase()) > -1?allformname.indexOf(msg.toLowerCase()):this.findkey(allformcommand, msg));
|
|
1668
|
|
- var formid=globalwpw.settings.obj.form_ids[index];
|
|
1669
|
|
- globalwpw.wildCard=7;
|
|
1670
|
|
- globalwpw.formStep='welcome';
|
|
1671
|
|
- wpwTree.formbuilder(formid);
|
|
1672
|
|
- }else if(simple_response_intent.indexOf(msg.toLowerCase()) > -1){
|
|
1673
|
|
- if(globalwpw.wildCard==7){
|
|
1674
|
|
- wpwTree.formbuilder_force_complete( msg );
|
|
1675
|
|
- }
|
|
1676
|
|
- var data = {'action':'wpbo_search_responseby_intent','name':globalwpw.hasNameCookie,'keyword':msg, 'language':globalwpw.settings.obj.language};
|
|
1677
|
|
- if($(globalwpw.settings.messageLastChild+' .wp-chatbot-comment-loader').length==0){
|
|
1678
|
|
- $(globalwpw.settings.messageContainer).append(wpwKits.botPreloader());
|
|
1679
|
|
- }
|
|
1680
|
|
- wpwKits.ajax(data).done(function (response) {
|
|
1681
|
|
- var json=$.parseJSON(response);
|
|
1682
|
|
- if(json.status=='success'){
|
|
1683
|
|
- wpwMsg.single(json.html);
|
|
1684
|
|
- var serviceOffer=wpwKits.randomMsg(globalwpw.settings.obj.wildcard_msg);
|
|
1685
|
|
- if( typeof(json.followup)!=="undefined" && json.followup!='' ){
|
|
1686
|
|
- setTimeout(function(){
|
|
1687
|
|
- wpwMsg.single(json.followup);
|
|
1688
|
|
- }, globalwpw.settings.preLoadingTime*2);
|
|
1689
|
|
- }else{
|
|
1690
|
|
-
|
|
1691
|
|
- setTimeout(function(){
|
|
1692
|
|
- $(globalwpw.settings.messageContainer).find('.wp-chatbot-msg:last .qcld-like-dislike-icon').css('display', 'block');
|
|
1693
|
|
- if((globalwpw.settings.obj.disable_back_to_start != '1' && globalwpw.settings.obj.skip_greetings_and_menu != 1)){
|
|
1694
|
|
- wpwMsg.single_nobg('<span class="qcld-chatbot-wildcard qcld_back_to_start" data-wildcart="back">' + wpwKits.randomMsg(globalwpw.settings.obj.back_to_start) + '</span>');
|
|
1695
|
|
- }
|
|
1696
|
|
- }, globalwpw.settings.preLoadingTime*2);
|
|
1697
|
|
- }
|
|
1698
|
|
- }
|
|
1699
|
|
- })
|
|
1700
|
|
- }else{
|
|
1701
|
|
- /*
|
|
1702
|
|
- * Greeting part
|
|
1703
|
|
- * bot action
|
|
1704
|
|
- */
|
|
1705
|
|
- if(globalwpw.wildCard==0){
|
|
1706
|
|
- //When intialize 1 and don't have cookies then keep the name of shooper in in cookie
|
|
1707
|
|
- if(globalwpw.initialize==1 && !localStorage.getItem('shopper') && globalwpw.wildCard==0){
|
|
1708
|
|
- wpwTree.greeting(msg);
|
|
1709
|
|
- }else if(globalwpw.settings.obj.ai_df_enable==1 && globalwpw.df_status_lock==0){
|
|
1710
|
|
- wpwTree.greeting(msg);
|
|
1711
|
|
- }else if(localStorage.getItem('default_asking_email')){
|
|
1712
|
|
- wpwTree.greeting(msg);
|
|
1713
|
|
- }else if(localStorage.getItem('default_asking_phone')){
|
|
1714
|
|
- wpwTree.greeting(msg);
|
|
1715
|
|
- }else{
|
|
1716
|
|
- //simple text response wrapper
|
|
1717
|
|
-
|
|
1718
|
|
- var data = {'action':'wpbo_search_response','name':globalwpw.hasNameCookie,'keyword':msg, 'language':globalwpw.settings.obj.language};
|
|
1719
|
|
- if(wp_chatbot_obj.disable_site_search == 1){
|
|
1720
|
|
- if($(globalwpw.settings.messageLastChild+' .wp-chatbot-comment-loader').length==0){
|
|
1721
|
|
- $(globalwpw.settings.messageContainer).append(wpwKits.botPreloader());
|
|
1722
|
|
- }
|
|
1723
|
|
- }
|
|
1724
|
|
- wpwKits.ajax(data).done(function (response) {
|
|
1725
|
|
- var json=$.parseJSON(response);
|
|
1726
|
|
-
|
|
1727
|
|
- if(json.status=='fail' && json.data !==''){
|
|
1728
|
|
-
|
|
1729
|
|
- if(wp_chatbot_obj.disable_site_search != 1){
|
|
1730
|
|
- wpwTree.site_search(msg)
|
|
1731
|
|
- }
|
|
1732
|
|
- else if( (globalwpw.settings.obj.openai_enabled == 1) || (wp_chatbot_obj.openai_enabled == 1) || (globalwpw.settings.obj.openrouter_enabled == 1) || (wp_chatbot_obj.openrouter_enabled == 1) || (globalwpw.settings.obj.gemini_enabled == 1) || (wp_chatbot_obj.gemini_enabled == 1) || (globalwpw.settings.obj.grok_enabled == 1) || (wp_chatbot_obj.grok_enabled == 1) ){
|
|
1733
|
|
- wpwTree.openai_reply(msg)
|
|
1734
|
|
- }else{
|
|
1735
|
|
- wpwMsg.single(globalwpw.settings.obj.empty_filter_msg);
|
|
1736
|
|
- }
|
|
1737
|
|
- }else if(json.status=='success'){
|
|
1738
|
|
- if(typeof(json.category)!=="undefined" && json.category){
|
|
1739
|
|
- var question='';
|
|
1740
|
|
- $.each(json.data, function (i, obj) {
|
|
1741
|
|
- question += '<span class="qcld-chatbot-wildcard qcld_simple_txt_response" data-strid="'+ obj.id +'">'+ obj.query +'</span>';
|
|
1742
|
|
- });
|
|
1743
|
|
- wpwMsg.single_nobg(question);
|
|
1744
|
|
- }
|
|
1745
|
|
- else if(json.multiple){
|
|
1746
|
|
- var question='';
|
|
1747
|
|
- $.each(json.data, function (i, obj) {
|
|
1748
|
|
- question += '<span class="qcld-chatbot-wildcard qcld_simple_txt_response" data-strid="'+ obj.id +'">'+ obj.query +'</span>';
|
|
1749
|
|
- });
|
|
1750
|
|
- wpwMsg.double_nobg(wpwKits.randomMsg(globalwpw.settings.obj.did_you_mean),question);
|
|
1751
|
|
- }else{
|
|
1752
|
|
- wpwMsg.single(json.data[0].response);
|
|
1753
|
|
- var serviceOffer=wpwKits.randomMsg(globalwpw.settings.obj.wildcard_msg);
|
|
1754
|
|
- if( typeof(json.data[0].followup)!=="undefined" && json.data[0].followup!='' ){
|
|
1755
|
|
- setTimeout(function(){
|
|
1756
|
|
- wpwMsg.single(json.data[0].followup);
|
|
1757
|
|
- }, globalwpw.settings.preLoadingTime*2);
|
|
1758
|
|
- }else{
|
|
1759
|
|
- // if(globalwpw.settings.obj.disable_repeatative!=1){
|
|
1760
|
|
- // setTimeout(function(){
|
|
1761
|
|
- // wpwMsg.double_nobg(serviceOffer, globalwpw.wildcards);
|
|
1762
|
|
- // }, globalwpw.settings.preLoadingTime*2);
|
|
1763
|
|
- // }else{
|
|
1764
|
|
- setTimeout(function(){
|
|
1765
|
|
- $(globalwpw.settings.messageContainer).find('.wp-chatbot-msg:last .qcld-like-dislike-icon').css('display', 'block');
|
|
1766
|
|
- if( (globalwpw.settings.obj.disable_back_to_start != '1' && globalwpw.settings.obj.skip_greetings_and_menu != 1)){
|
|
1767
|
|
- wpwMsg.single_nobg('<span class="qcld-chatbot-wildcard qcld_back_to_start" data-wildcart="back">' + wpwKits.randomMsg(globalwpw.settings.obj.back_to_start) + '</span>');
|
|
1768
|
|
- }
|
|
1769
|
|
- }, globalwpw.settings.preLoadingTime*2);
|
|
1770
|
|
- // }
|
|
1771
|
|
- }
|
|
1772
|
|
- }
|
|
1773
|
|
- }else{
|
|
1774
|
|
- //Default intents site search
|
|
1775
|
|
- msg = wpwKits.filterStopWords(msg);
|
|
1776
|
|
- if(globalwpw.settings.obj.woocommerce){
|
|
1777
|
|
- var data = {'action':'qcld_wb_chatbot_keyword', 'keyword':msg};
|
|
1778
|
|
- //Products by string search ajax handler.
|
|
1779
|
|
- if($(globalwpw.settings.messageLastChild+' .wp-chatbot-comment-loader').length==0){
|
|
1780
|
|
- $(globalwpw.settings.messageContainer).append(wpwKits.botPreloader());
|
|
1781
|
|
- }
|
|
1782
|
|
- wpwKits.ajax(data).done(function( response ) {
|
|
1783
|
|
- if(response.product_num==0){
|
|
1784
|
|
- if(msg!='' && globalwpw.settings.obj.disable_sitesearch==''){
|
|
1785
|
|
- msg = wpwKits.filterStopWords(msg);
|
|
1786
|
|
- var data = {'action':'wpbo_search_site','name':globalwpw.hasNameCookie,'keyword':msg, 'security':wp_chatbot_obj.ajax_nonce};
|
|
1787
|
|
- if($(globalwpw.settings.messageLastChild+' .wp-chatbot-comment-loader').length==0){
|
|
1788
|
|
- $(globalwpw.settings.messageContainer).append(wpwKits.botPreloader());
|
|
1789
|
|
- }
|
|
1790
|
|
- wpwKits.ajax(data).done(function (response) {
|
|
1791
|
|
- var json=$.parseJSON(response);
|
|
1792
|
|
- if(json.status=='success'){
|
|
1793
|
|
- // wpwMsg.single(wp_chatbot_obj.found_result_message);
|
|
1794
|
|
- $('span[data-wildcart="back"]').remove();
|
|
1795
|
|
- if((globalwpw.settings.obj.disable_back_to_start != '1' && globalwpw.settings.obj.skip_greetings_and_menu != 1)){
|
|
1796
|
|
- wpwMsg.triple_nobg(wp_chatbot_obj.found_result_message,json.html,'<span class="qcld-chatbot-wildcard" data-wildcart="back">' + wpwKits.randomMsg(globalwpw.settings.obj.back_to_start) + '</span>');
|
|
1797
|
|
- }else{
|
|
1798
|
|
- wpwMsg.double_nobg(wp_chatbot_obj.found_result_message,json.html);
|
|
1799
|
|
- }
|
|
1800
|
|
- }else{
|
|
1801
|
|
- var data = {'action':'wpbo_failed_response','name':globalwpw.hasNameCookie,'keyword':msg};
|
|
1802
|
|
- wpwKits.ajax(data).done(function (res) {
|
|
1803
|
|
- //
|
|
1804
|
|
- })
|
|
1805
|
|
- if(globalwpw.counter == globalwpw.settings.obj.no_result_attempt_count || globalwpw.settings.obj.no_result_attempt_count == 0 ){
|
|
1806
|
|
- wpwMsg.single(wpwKits.randomMsg(json.html));
|
|
1807
|
|
- setTimeout(function(){
|
|
1808
|
|
- var serviceOffer=wpwKits.randomMsg(globalwpw.settings.obj.support_option_again);
|
|
1809
|
|
- if((globalwpw.settings.obj.disable_back_to_start != '1' && globalwpw.settings.obj.skip_greetings_and_menu != 1)){
|
|
1810
|
|
- wpwMsg.single_nobg('<span class="qcld-chatbot-wildcard qcld_back_to_start" data-wildcart="back">' + wpwKits.randomMsg(globalwpw.settings.obj.back_to_start) + '</span>');
|
|
1811
|
|
- }
|
|
1812
|
|
- },globalwpw.settings.preLoadingTime)
|
|
1813
|
|
- globalwpw.counter = 0;
|
|
1814
|
|
- }else{
|
|
1815
|
|
- globalwpw.counter++;
|
|
1816
|
|
- wpwMsg.single(wpwKits.randomMsg(json.html));
|
|
1817
|
|
- }
|
|
1818
|
|
- }
|
|
1819
|
|
- globalwpw.wildCard=0;
|
|
1820
|
|
- });
|
|
1821
|
|
- }else{
|
|
1822
|
|
- globalwpw.wildCard=0;
|
|
1823
|
|
- wpwMsg.single(wpwKits.randomMsg(globalwpw.settings.obj.empty_filter_msg));
|
|
1824
|
|
- // if(globalwpw.settings.obj.disable_repeatative!=1){
|
|
1825
|
|
- // setTimeout(function(){
|
|
1826
|
|
- // var serviceOffer=wpwKits.randomMsg(globalwpw.settings.obj.support_option_again);
|
|
1827
|
|
- // wpwMsg.double_nobg(serviceOffer,globalwpw.wildcards);
|
|
1828
|
|
- // },globalwpw.settings.preLoadingTime)
|
|
1829
|
|
- // }else{
|
|
1830
|
|
- setTimeout(function(){
|
|
1831
|
|
- $(globalwpw.settings.messageContainer).find('.wp-chatbot-msg:last .qcld-like-dislike-icon').css('display', 'block');
|
|
1832
|
|
- if((globalwpw.settings.obj.disable_back_to_start != '1' && globalwpw.settings.obj.skip_greetings_and_menu != 1)){
|
|
1833
|
|
- wpwMsg.single_nobg('<span class="qcld-chatbot-wildcard qcld_back_to_start" data-wildcart="back">' + wpwKits.randomMsg(globalwpw.settings.obj.back_to_start) + '</span>');
|
|
1834
|
|
- }
|
|
1835
|
|
- }, globalwpw.settings.preLoadingTime*2);
|
|
1836
|
|
- // }
|
|
1837
|
|
- }
|
|
1838
|
|
- }else {
|
|
1839
|
|
- var productSucces= wpwKits.randomMsg(globalwpw.settings.obj.product_success)+" <strong>"+msg+"</strong>!";
|
|
1840
|
|
- console.log(globalwpw.wildcards);
|
|
1841
|
|
- wpwMsg.double_nobg(productSucces,response.html);
|
|
1842
|
|
- if(response.per_page >= response.product_num){
|
|
1843
|
|
- setTimeout(function () {
|
|
1844
|
|
- var searchAgain = wpwKits.randomMsg(globalwpw.settings.obj.product_infinite);
|
|
1845
|
|
- wpwMsg.single(searchAgain);
|
|
1846
|
|
- //keeping value in localstorage
|
|
1847
|
|
- globalwpw.wildCard=20;
|
|
1848
|
|
- globalwpw.productStep='search';
|
|
1849
|
|
- localStorage.setItem("productStep", globalwpw.productStep);
|
|
1850
|
|
- },globalwpw.settings.wildcardsShowTime);
|
|
1851
|
|
- }
|
|
1852
|
|
- }
|
|
1853
|
|
- });
|
|
1854
|
|
- }else{
|
|
1855
|
|
- if(msg!='' && globalwpw.settings.obj.disable_sitesearch==''){
|
|
1856
|
|
- msg = wpwKits.filterStopWords(msg);
|
|
1857
|
|
- var data = {'action':'wpbo_search_site','name':globalwpw.hasNameCookie,'keyword':msg, 'security':wp_chatbot_obj.ajax_nonce};
|
|
1858
|
|
- if($(globalwpw.settings.messageLastChild+' .wp-chatbot-comment-loader').length==0){
|
|
1859
|
|
- $(globalwpw.settings.messageContainer).append(wpwKits.botPreloader());
|
|
1860
|
|
- }
|
|
1861
|
|
- wpwKits.ajax(data).done(function (response) {
|
|
1862
|
|
- var json=$.parseJSON(response);
|
|
1863
|
|
- if(json.status=='success'){
|
|
1864
|
|
- //wpwMsg.single();
|
|
1865
|
|
- $('span[data-wildcart="back"]').remove();
|
|
1866
|
|
- if((globalwpw.settings.obj.disable_back_to_start != '1' && globalwpw.settings.obj.skip_greetings_and_menu != 1)){
|
|
1867
|
|
- wpwMsg.triple_nobg(wp_chatbot_obj.found_result_message,json.html,'<span class="qcld-chatbot-wildcard" data-wildcart="back">' + wpwKits.randomMsg(globalwpw.settings.obj.back_to_start) + '</span>');
|
|
1868
|
|
- }else{
|
|
1869
|
|
- wpwMsg.double_nobg(wp_chatbot_obj.found_result_message,json.html);
|
|
1870
|
|
- }
|
|
1871
|
|
- }else{
|
|
1872
|
|
- var data = {'action':'wpbo_failed_response','name':globalwpw.hasNameCookie,'keyword':msg};
|
|
1873
|
|
- wpwKits.ajax(data).done(function (res) {
|
|
1874
|
|
- //
|
|
1875
|
|
- })
|
|
1876
|
|
- if(globalwpw.counter == globalwpw.settings.obj.no_result_attempt_count || globalwpw.settings.obj.no_result_attempt_count == 0 ){
|
|
1877
|
|
- wpwMsg.single(wpwKits.randomMsg(json.html));
|
|
1878
|
|
- setTimeout(function(){
|
|
1879
|
|
- var serviceOffer=wpwKits.randomMsg(globalwpw.settings.obj.support_option_again);
|
|
1880
|
|
- if((globalwpw.settings.obj.disable_back_to_start != '1' && globalwpw.settings.obj.skip_greetings_and_menu != 1)){
|
|
1881
|
|
- wpwMsg.single_nobg('<span class="qcld-chatbot-wildcard qcld_back_to_start" data-wildcart="back">' + wpwKits.randomMsg(globalwpw.settings.obj.back_to_start) + '</span>');
|
|
1882
|
|
- }
|
|
1883
|
|
- },globalwpw.settings.preLoadingTime)
|
|
1884
|
|
- globalwpw.counter = 0;
|
|
1885
|
|
- }else{
|
|
1886
|
|
- globalwpw.counter++;
|
|
1887
|
|
- wpwMsg.single(wpwKits.randomMsg(json.html));
|
|
1888
|
|
- }
|
|
1889
|
|
- }
|
|
1890
|
|
- globalwpw.wildCard=0;
|
|
1891
|
|
- });
|
|
1892
|
|
- }else{
|
|
1893
|
|
- globalwpw.wildCard=0;
|
|
1894
|
|
- wpwMsg.single(wpwKits.randomMsg(globalwpw.settings.obj.empty_filter_msg));
|
|
1895
|
|
- // if(globalwpw.settings.obj.disable_repeatative!=1){
|
|
1896
|
|
- // setTimeout(function(){
|
|
1897
|
|
- // var serviceOffer=wpwKits.randomMsg(globalwpw.settings.obj.support_option_again);
|
|
1898
|
|
- // wpwMsg.double_nobg(serviceOffer,globalwpw.wildcards);
|
|
1899
|
|
- // },globalwpw.settings.preLoadingTime)
|
|
1900
|
|
- // }else{
|
|
1901
|
|
- setTimeout(function(){
|
|
1902
|
|
- $(globalwpw.settings.messageContainer).find('.wp-chatbot-msg:last .qcld-like-dislike-icon').css('display', 'block');
|
|
1903
|
|
- if((globalwpw.settings.obj.disable_back_to_start != '1' && globalwpw.settings.obj.skip_greetings_and_menu != 1)){
|
|
1904
|
|
- wpwMsg.single_nobg('<span class="qcld-chatbot-wildcard qcld_back_to_start" data-wildcart="back">' + wpwKits.randomMsg(globalwpw.settings.obj.back_to_start) + '</span>');
|
|
1905
|
|
- }
|
|
1906
|
|
- }, globalwpw.settings.preLoadingTime*2);
|
|
1907
|
|
- // }
|
|
1908
|
|
- }
|
|
1909
|
|
- }
|
|
1910
|
|
- }
|
|
1911
|
|
- })
|
|
1912
|
|
-
|
|
1913
|
|
- } //
|
|
1914
|
|
- }
|
|
1915
|
|
- if(globalwpw.settings.obj.woocommerce){
|
|
1916
|
|
- //Product
|
|
1917
|
|
- if(globalwpw.wildCard==20){
|
|
1918
|
|
- wpwTree.product(msg);
|
|
1919
|
|
- }
|
|
1920
|
|
- /*
|
|
1921
|
|
- * order status part
|
|
1922
|
|
- * bot action
|
|
1923
|
|
- */
|
|
1924
|
|
- if(globalwpw.wildCard==21){
|
|
1925
|
|
- wpwTree.order(msg);
|
|
1926
|
|
- }
|
|
1927
|
|
- }
|
|
1928
|
|
- if(globalwpw.wildCard==1){
|
|
1929
|
|
- wpwTree.support(msg);
|
|
1930
|
|
- }
|
|
1931
|
|
- if(globalwpw.wildCard==3){
|
|
1932
|
|
- wpwTree.subscription(msg);
|
|
1933
|
|
- }
|
|
1934
|
|
- if(globalwpw.wildCard==6){
|
|
1935
|
|
- wpwTree.unsubscription(msg);
|
|
1936
|
|
- }
|
|
1937
|
|
- if(globalwpw.wildCard==7){
|
|
1938
|
|
- wpwTree.formbuilder(msg);
|
|
1939
|
|
- }
|
|
1940
|
|
- if(globalwpw.wildCard==9){
|
|
1941
|
|
- wpwTree.bargain(msg);
|
|
1942
|
|
- }
|
|
1943
|
|
- if(globalwpw.wildCard==25){
|
|
1944
|
|
- wpwTree.reset(msg);
|
|
1945
|
|
- }
|
|
1946
|
|
- if(globalwpw.wildCard==26){
|
|
1947
|
|
- wpwTree.dfcx(msg);
|
|
1948
|
|
- }
|
|
1949
|
|
- if(globalwpw.wildCard==30){
|
|
1950
|
|
- wpwTree.ldsuggestion();
|
|
1951
|
|
- }
|
|
1952
|
|
- }
|
|
1953
|
|
- },
|
|
1954
|
|
- clickstr: function(id){
|
|
1955
|
|
- var data = {'action':'wpbo_search_response','name':globalwpw.hasNameCookie,'strid':id, 'language':globalwpw.settings.obj.language};
|
|
1956
|
|
-
|
|
1957
|
|
- wpwKits.ajax(data).done(function (response) {
|
|
1958
|
|
- var json=$.parseJSON(response);
|
|
1959
|
|
- if(json.status=='success'){
|
|
1960
|
|
- if(typeof(json.data)!=="undefined" && json.data){
|
|
1961
|
|
- var question='';
|
|
1962
|
|
- $.each(json.data, function (i, obj) {
|
|
1963
|
|
-
|
|
1964
|
|
- question += obj.response;
|
|
1965
|
|
- });
|
|
1966
|
|
- wpwMsg.single(question);
|
|
1967
|
|
- }
|
|
1968
|
|
- }
|
|
1969
|
|
- })
|
|
1970
|
|
- },
|
|
1971
|
|
- shopper:function (msg) {
|
|
1972
|
|
- wpwMsg.shopper(msg);
|
|
1973
|
|
- if(globalwpw.wildCard==1) {
|
|
1974
|
|
- this.bot(msg);
|
|
1975
|
|
- }else if(globalwpw.settings.obj.ai_df_enable==1 && globalwpw.wildCard==0 && globalwpw.ai_step==1 && globalwpw.df_status_lock==0){
|
|
1976
|
|
- this.bot(msg);
|
|
1977
|
|
- } else{
|
|
1978
|
|
- //Filtering the user given messages by stopwords
|
|
1979
|
|
- var filterMsg=(msg);
|
|
1980
|
|
- //handle empty filterMsg as repeat the message.
|
|
1981
|
|
- if(filterMsg=="") {
|
|
1982
|
|
- //if(globalwpw.emptymsghandler==0){
|
|
1983
|
|
- globalwpw.repeatQueryEmpty=wpwKits.randomMsg(globalwpw.settings.obj.empty_filter_msg);
|
|
1984
|
|
- globalwpw.emptymsghandler++;
|
|
1985
|
|
- //}
|
|
1986
|
|
- wpwMsg.single(globalwpw.repeatQueryEmpty);
|
|
1987
|
|
- setTimeout(function(){
|
|
1988
|
|
- var serviceOffer=wpwKits.randomMsg(globalwpw.settings.obj.support_option_again);
|
|
1989
|
|
- if((globalwpw.settings.obj.disable_back_to_start != '1' && globalwpw.settings.obj.skip_greetings_and_menu != 1)){
|
|
1990
|
|
- wpwMsg.single_nobg('<span class="qcld-chatbot-wildcard qcld_back_to_start" data-wildcart="back">' + wpwKits.randomMsg(globalwpw.settings.obj.back_to_start) + '</span>');
|
|
1991
|
|
- }
|
|
1992
|
|
- },globalwpw.settings.preLoadingTime)
|
|
1993
|
|
- }else {
|
|
1994
|
|
- globalwpw.emptymsghandler=0;
|
|
1995
|
|
- this.bot(filterMsg);
|
|
1996
|
|
- }
|
|
1997
|
|
- }
|
|
1998
|
|
- }
|
|
1999
|
|
- };
|
|
2000
|
|
- /*
|
|
2001
|
|
- * wpwBot Plugin Creation without selector and
|
|
2002
|
|
- * wpwbot and shoppers all activities will be handled.
|
|
2003
|
|
- */
|
|
2004
|
|
- $.wpwbot = function(options) {
|
|
2005
|
|
- //Using plugins defualts values or overwrite by options.
|
|
2006
|
|
-
|
|
2007
|
|
- var settings = $.extend({}, $.wpwbot.defaults, options);
|
|
2008
|
|
- //Updating global settings
|
|
2009
|
|
- globalwpw.settings=settings;
|
|
2010
|
|
- //updating the helpkeywords
|
|
2011
|
|
- globalwpw.wildcardsHelp=[globalwpw.settings.obj.sys_key_help.toLowerCase(),globalwpw.settings.obj.sys_key_product.toLowerCase(),globalwpw.settings.obj.sys_key_catalog.toLowerCase(),globalwpw.settings.obj.sys_key_support.toLowerCase(),globalwpw.settings.obj.sys_key_order.toLowerCase(),globalwpw.settings.obj.sys_key_reset.toLowerCase(),globalwpw.settings.obj.sys_key_email.toLowerCase()]
|
|
2012
|
|
- //updating wildcards
|
|
2013
|
|
- globalwpw.wildcards='';
|
|
2014
|
|
- if(globalwpw.settings.obj.start_menu!=''){
|
|
2015
|
|
- var menu_html = '';
|
|
2016
|
|
- var menu_items = $.parseHTML($.trim(globalwpw.settings.obj.start_menu));
|
|
2017
|
|
- $(menu_items).each(function(){
|
|
2018
|
|
- if( $(this).prop('tagName') == 'SPAN' ){
|
|
2019
|
|
- if( $(this).hasClass('qcld-chatbot-suggest-email') ){
|
|
2020
|
|
- if( globalwpw.settings.obj.disable_feedback=='' ){
|
|
2021
|
|
- menu_html += $(this).prop('outerHTML');
|
|
2022
|
|
- }
|
|
2023
|
|
- }else if( $(this).hasClass('qcld-chatbot-suggest-phone') ){
|
|
2024
|
|
- if( globalwpw.settings.obj.call_gen=="" ){
|
|
2025
|
|
- menu_html += $(this).prop('outerHTML');
|
|
2026
|
|
- }
|
|
2027
|
|
- }else if( $(this).hasClass('qcld-chatbot-wildcard') && $(this).attr('data-wildcart') == 'support' ){
|
|
2028
|
|
- if( globalwpw.settings.obj.disable_faq=='' ){
|
|
2029
|
|
- menu_html += $(this).prop('outerHTML');
|
|
2030
|
|
- }
|
|
2031
|
|
- }else if( $(this).hasClass('qcld-chatbot-wildcard') && $(this).attr('data-wildcart') == 'messenger' ){
|
|
2032
|
|
- if( globalwpw.settings.obj.enable_messenger==1 ){
|
|
2033
|
|
- menu_html += $(this).prop('outerHTML');
|
|
2034
|
|
- }
|
|
2035
|
|
- }else if( $(this).hasClass('qcld-chatbot-wildcard') && $(this).attr('data-wildcart') == 'whatspp' ){
|
|
2036
|
|
- if( globalwpw.settings.obj.enable_whats==1 ){
|
|
2037
|
|
- menu_html += $(this).prop('outerHTML');
|
|
2038
|
|
- }
|
|
2039
|
|
- }else{
|
|
2040
|
|
- menu_html += $(this).prop('outerHTML');
|
|
2041
|
|
- }
|
|
2042
|
|
- }
|
|
2043
|
|
- })
|
|
2044
|
|
- if( menu_html != '' ){
|
|
2045
|
|
- globalwpw.wildcards = menu_html;
|
|
2046
|
|
- }else{
|
|
2047
|
|
- globalwpw.wildcards = globalwpw.settings.obj.start_menu;
|
|
2048
|
|
- }
|
|
2049
|
|
- }
|
|
2050
|
|
- //Initialize the wpwBot with greeting and if already initialize and given name then return greeting..
|
|
2051
|
|
- if(localStorage.getItem("wpwHitory") && globalwpw.initialize==0 ){
|
|
2052
|
|
- var wpwHistory=localStorage.getItem("wpwHitory");
|
|
2053
|
|
- $(globalwpw.settings.messageWrapper).html(wpwHistory);
|
|
2054
|
|
- //Scroll to the last element.
|
|
2055
|
|
- wpwKits.scrollTo();
|
|
2056
|
|
- //Now mainting the current stages tokens
|
|
2057
|
|
- globalwpw.initialize=1;
|
|
2058
|
|
- if(localStorage.getItem("wildCard")){
|
|
2059
|
|
- globalwpw.wildCard=localStorage.getItem("wildCard");
|
|
2060
|
|
- }
|
|
2061
|
|
- if(localStorage.getItem("productStep")){
|
|
2062
|
|
- globalwpw.productStep=localStorage.getItem("productStep");
|
|
2063
|
|
- }
|
|
2064
|
|
- if(localStorage.getItem("orderStep")){
|
|
2065
|
|
- globalwpw.orderStep=localStorage.getItem("orderStep");
|
|
2066
|
|
- }
|
|
2067
|
|
- if(localStorage.getItem("supportStep")){
|
|
2068
|
|
- globalwpw.supportStep=localStorage.getItem("supportStep");
|
|
2069
|
|
- }
|
|
2070
|
|
- if(localStorage.getItem("aiStep")){
|
|
2071
|
|
- globalwpw.ai_step=localStorage.getItem("aiStep");
|
|
2072
|
|
- }
|
|
2073
|
|
- if(localStorage.getItem("formfieldid")){
|
|
2074
|
|
- globalwpw.formfieldid=localStorage.getItem("formfieldid");
|
|
2075
|
|
- }
|
|
2076
|
|
- if(localStorage.getItem("formentry")){
|
|
2077
|
|
- globalwpw.formentry=localStorage.getItem("formentry");
|
|
2078
|
|
- }
|
|
2079
|
|
- if(localStorage.getItem("formStep")){
|
|
2080
|
|
- globalwpw.formStep=localStorage.getItem("formStep");
|
|
2081
|
|
- }
|
|
2082
|
|
- if(localStorage.getItem("formid")){
|
|
2083
|
|
- globalwpw.formid=localStorage.getItem("formid");
|
|
2084
|
|
- }
|
|
2085
|
|
- //update the value for initializing.
|
|
2086
|
|
- globalwpw.initialize=1;
|
|
2087
|
|
- } else {
|
|
2088
|
|
- if(globalwpw.initialize==0 && globalwpw.wildCard==0 && globalwpw.settings.obj.re_target_handler==0){
|
|
2089
|
|
- wpwWelcome.greeting();
|
|
2090
|
|
- //update the value for initializing.
|
|
2091
|
|
- globalwpw.initialize=1;
|
|
2092
|
|
- }else{ // re targeting part .
|
|
2093
|
|
- setTimeout(function (e) {
|
|
2094
|
|
- wpwWelcome.greeting();
|
|
2095
|
|
- },8500);
|
|
2096
|
|
- globalwpw.initialize=1;
|
|
2097
|
|
- }
|
|
2098
|
|
- }
|
|
2099
|
|
- function wpbotResetSendMessageClasses() {
|
|
2100
|
|
- $(settings.sendButton).removeClass('wp-chatbot-send-message-active wp-chatbot-send-message-typing');
|
|
2101
|
|
- }
|
|
2102
|
|
-
|
|
2103
|
|
- // Typing state only: add active class while editor has content.
|
|
2104
|
|
- $(document).on('input keyup', settings.messageEditor, function () {
|
|
2105
|
|
- var hasValue = $.trim($(settings.messageEditor).val()).length > 0;
|
|
2106
|
|
- $(settings.sendButton).toggleClass('wp-chatbot-send-message-active', hasValue);
|
|
2107
|
|
- });
|
|
2108
|
|
-
|
|
2109
|
|
- // Blur state: clean both classes if no input value.
|
|
2110
|
|
- $(document).on('blur', settings.messageEditor, function () {
|
|
2111
|
|
- var hasValue = $.trim($(settings.messageEditor).val()).length > 0;
|
|
2112
|
|
- if (!hasValue) {
|
|
2113
|
|
- wpbotResetSendMessageClasses();
|
|
2114
|
|
- }
|
|
2115
|
|
- });
|
|
2116
|
|
-
|
|
2117
|
|
- //When shopper click on send button
|
|
2118
|
|
- $(document).on('click',settings.sendButton,function (e) {
|
|
2119
|
|
- var shopperMsg =$(settings.messageEditor).val();
|
|
2120
|
|
- if(shopperMsg != ""){
|
|
2121
|
|
- wpwAction.shopper(wpwKits.htmlTagsScape(shopperMsg));
|
|
2122
|
|
- $(settings.messageEditor).val('');
|
|
2123
|
|
- wpbotResetSendMessageClasses();
|
|
2124
|
|
- }
|
|
2125
|
|
- });
|
|
2126
|
|
- $(document).on('click', '.chatbot_intent_reload', function(e){
|
|
2127
|
|
- e.preventDefault();
|
|
2128
|
|
- var obj = $(this);
|
|
2129
|
|
- if(obj.attr('data-intent-type')=='formbuilder'){
|
|
2130
|
|
- if( obj.attr('data-step')=='complete' ){
|
|
2131
|
|
- globalwpw.formStep='field';
|
|
2132
|
|
- localStorage.setItem("formStep", globalwpw.formStep);
|
|
2133
|
|
- }
|
|
2134
|
|
- globalwpw.wildCard=obj.attr('data-wildcard');
|
|
2135
|
|
- globalwpw.formfieldid = obj.attr('data-intent');
|
|
2136
|
|
- wpwTree.formbuilder();
|
|
2137
|
|
- }
|
|
2138
|
|
- })
|
|
2139
|
|
- /*
|
|
2140
|
|
- * Or when shopper press the ENTER key
|
|
2141
|
|
- * Then chatting functionality will be started.
|
|
2142
|
|
- */
|
|
2143
|
|
- $(document).on('click', '.wpb-quick-reply', function(e){
|
|
2144
|
|
- e.preventDefault();
|
|
2145
|
|
- $('#wp-chatbot-editor').val($(this).html());
|
|
2146
|
|
- $('#wp-chatbot-send-message').trigger( "click" );
|
|
2147
|
|
- })
|
|
2148
|
|
- $(document).on('keypress',settings.messageEditor,function (e) {
|
|
2149
|
|
- if (e.which == 13||e.keyCode==13) {
|
|
2150
|
|
- e.preventDefault();
|
|
2151
|
|
- var shopperMsg =$(settings.messageEditor).val();
|
|
2152
|
|
- if(shopperMsg != ""){
|
|
2153
|
|
- wpwAction.shopper(wpwKits.htmlTagsScape(shopperMsg));
|
|
2154
|
|
- $(settings.messageEditor).val('');
|
|
2155
|
|
- wpbotResetSendMessageClasses();
|
|
2156
|
|
- }
|
|
2157
|
|
- }
|
|
2158
|
|
- });
|
|
2159
|
|
- $(document).on('click', '.qcld-chatbot-checkbox', function(){
|
|
2160
|
|
-
|
|
2161
|
|
- var value = [];
|
|
2162
|
|
- $('.qcld-chatbot-checkbox').each(function(){
|
|
2163
|
|
- if($(this).prop("checked") == true){
|
|
2164
|
|
- value.push($(this).val());
|
|
2165
|
|
- }
|
|
2166
|
|
- })
|
|
2167
|
|
- $('#wp-chatbot-editor').val(value.join());
|
|
2168
|
|
- if ($.trim($('#wp-chatbot-editor').val()).length > 0) {
|
|
2169
|
|
- $(settings.sendButton).addClass('wp-chatbot-send-message-active');
|
|
2170
|
|
- } else {
|
|
2171
|
|
- wpbotResetSendMessageClasses();
|
|
2172
|
|
- }
|
|
2173
|
|
- })
|
|
2174
|
|
- //Click on the wildcards to select a service
|
|
2175
|
|
- $(document).on('click','.qcld-chatbot-wildcard',function(){
|
|
2176
|
|
- var wildcardData=$(this).attr('data-form');
|
|
2177
|
|
- var shooperChoice=$(this).text();
|
|
2178
|
|
- wpwMsg.shopper_choice(shooperChoice);
|
|
2179
|
|
- if(typeof wildcardData === "undefined"){
|
|
2180
|
|
- var wildcardData=$(this).attr('data-wildcart');
|
|
2181
|
|
- }
|
|
2182
|
|
- //Wild cards handling for bot.
|
|
2183
|
|
- if(wildcardData=='product'){
|
|
2184
|
|
- globalwpw.wildCard=1;
|
|
2185
|
|
- globalwpw.productStep='asking'
|
|
2186
|
|
- wpwAction.bot('from wildcard product');
|
|
2187
|
|
- //keeping value in localstorage
|
|
2188
|
|
- localStorage.setItem("wildCard", globalwpw.wildCard);
|
|
2189
|
|
- localStorage.setItem("productStep", globalwpw.productStep);
|
|
2190
|
|
- }
|
|
2191
|
|
- if(wildcardData=='catalog'){
|
|
2192
|
|
- wpwAction.bot(globalwpw.settings.obj.sys_key_catalog.toLowerCase());
|
|
2193
|
|
- }
|
|
2194
|
|
- if(wildcardData=='featured'){
|
|
2195
|
|
- globalwpw.wildCard=1;
|
|
2196
|
|
- globalwpw.productStep='featured'
|
|
2197
|
|
- wpwAction.bot('from wildcard product');
|
|
2198
|
|
- //keeping value in localstorage
|
|
2199
|
|
- localStorage.setItem("wildCard", globalwpw.wildCard);
|
|
2200
|
|
- localStorage.setItem("productStep", globalwpw.productStep);
|
|
2201
|
|
- }
|
|
2202
|
|
- if(wildcardData=='sale'){
|
|
2203
|
|
- globalwpw.wildCard=1;
|
|
2204
|
|
- globalwpw.productStep='sale'
|
|
2205
|
|
- wpwAction.bot('from wildcard product');
|
|
2206
|
|
- //keeping value in localstorage
|
|
2207
|
|
- localStorage.setItem("wildCard", globalwpw.wildCard);
|
|
2208
|
|
- localStorage.setItem("productStep", globalwpw.productStep);
|
|
2209
|
|
- }
|
|
2210
|
|
- if(wildcardData=='order'){
|
|
2211
|
|
- globalwpw.wildCard=2;
|
|
2212
|
|
- globalwpw.orderStep='welcome';
|
|
2213
|
|
- wpwAction.bot('from wildcard order');
|
|
2214
|
|
- //keeping value in localstorage
|
|
2215
|
|
- localStorage.setItem("wildCard", globalwpw.wildCard);
|
|
2216
|
|
- localStorage.setItem("orderStep", globalwpw.orderStep);
|
|
2217
|
|
- }
|
|
2218
|
|
- if((wildcardData=='support ui-sortable-handle') || (wildcardData=='support')) {
|
|
2219
|
|
- globalwpw.wildCard=1;
|
|
2220
|
|
- globalwpw.supportStep='welcome';
|
|
2221
|
|
- wpwAction.bot('from wildcard support');
|
|
2222
|
|
- //keeping value in localstorage
|
|
2223
|
|
- localStorage.setItem("wildCard", globalwpw.wildCard);
|
|
2224
|
|
- localStorage.setItem("supportStep", globalwpw.supportStep);
|
|
2225
|
|
- }
|
|
2226
|
|
- if(wildcardData=='back'){
|
|
2227
|
|
- globalwpw.wildCard=0;
|
|
2228
|
|
- //wpwAction.bot('start');
|
|
2229
|
|
- wpwAction.bot(wp_chatbot_obj.sys_key_help.toLowerCase());
|
|
2230
|
|
- //keeping value in localstorage
|
|
2231
|
|
- localStorage.setItem("wildCard", globalwpw.wildCard);
|
|
2232
|
|
- }
|
|
2233
|
|
- if(wildcardData=='messenger'){
|
|
2234
|
|
- var url='https://www.messenger.com/t/'+globalwpw.settings.obj.fb_page_id;
|
|
2235
|
|
- var win = window.open(url, '_blank');
|
|
2236
|
|
- win.focus();
|
|
2237
|
|
- }
|
|
2238
|
|
- if(wildcardData=='whatsapp'){
|
|
2239
|
|
- var url='https://api.whatsapp.com/send?phone='+globalwpw.settings.obj.whats_num;
|
|
2240
|
|
- var win = window.open(url, '_blank');
|
|
2241
|
|
- win.focus();
|
|
2242
|
|
- }
|
|
2243
|
|
- });
|
|
2244
|
|
- $(document).on('click','.qcld-chatbot-form',function(e){
|
|
2245
|
|
- e.preventDefault();
|
|
2246
|
|
- var formid=$(this).attr('data-form');
|
|
2247
|
|
- globalwpw.wildCard=7;
|
|
2248
|
|
- globalwpw.formStep='welcome';
|
|
2249
|
|
- wpwTree.formbuilder(formid);
|
|
2250
|
|
- })
|
|
2251
|
|
- $(document).on('click','.qcld_simple_txt_response',function(e){
|
|
2252
|
|
- e.preventDefault();
|
|
2253
|
|
- var text=$(this).text();
|
|
2254
|
|
- var id = $(this).data('strid');
|
|
2255
|
|
- globalwpw.wildCard=0;
|
|
2256
|
|
- wpwAction.clickstr(id);
|
|
2257
|
|
- })
|
|
2258
|
|
- $(document).on('click','#wp-chatbot-desktop-reload',function (e) {
|
|
2259
|
|
- e.preventDefault();
|
|
2260
|
|
- var actionType=$(this).attr('reset-data');
|
|
2261
|
|
- $('#wp-chatbot-messages-container').html('');
|
|
2262
|
|
- localStorage.removeItem('shopper');
|
|
2263
|
|
- globalwpw.wildCard=0;
|
|
2264
|
|
- globalwpw.ai_step=0;
|
|
2265
|
|
- localStorage.setItem("wildCard", globalwpw.wildCard);
|
|
2266
|
|
- localStorage.setItem("aiStep", globalwpw.ai_step);
|
|
2267
|
|
- globalwpw.formfieldid = '';
|
|
2268
|
|
- localStorage.setItem("formfieldid", globalwpw.formfieldid);
|
|
2269
|
|
- globalwpw.formStep='welcome';
|
|
2270
|
|
- localStorage.setItem("formStep", globalwpw.formStep);
|
|
2271
|
|
- globalwpw.formid='';
|
|
2272
|
|
- localStorage.setItem("formid", globalwpw.formid);
|
|
2273
|
|
- globalwpw.formentry = 0;
|
|
2274
|
|
- localStorage.setItem("formentry", globalwpw.formentry);
|
|
2275
|
|
- localStorage.removeItem("cx-name" );
|
|
2276
|
|
- localStorage.removeItem("cx-diaplayname" );
|
|
2277
|
|
- localStorage.removeItem("cx-languagecode" );
|
|
2278
|
|
- localStorage.removeItem("cx-timezone" );
|
|
2279
|
|
- var number = Math.random() // 0.9394456857981651
|
|
2280
|
|
- number.toString(36); // '0.xtis06h6'
|
|
2281
|
|
- var id = number.toString(36).substr(2); // 'xtis06h6'
|
|
2282
|
|
- localStorage.setItem('botsessionid', id);
|
|
2283
|
|
- wpwWelcome.greeting();
|
|
2284
|
|
- });
|
|
2285
|
|
- $(document).on('click','.qcld-chatbot-formanswer',function(e){
|
|
2286
|
|
- e.preventDefault();
|
|
2287
|
|
- var answer=$(this).attr('data-form-value');
|
|
2288
|
|
- wpwAction.bot(answer);
|
|
2289
|
|
- })
|
|
2290
|
|
- //
|
|
2291
|
|
- $(document).on('click','.qcld-chatbot-product-category',function(){
|
|
2292
|
|
- var catType=$(this).attr('data-category-type');
|
|
2293
|
|
- var shopperChoiceCatId=$(this).text()+'#'+$(this).attr('data-category-id');
|
|
2294
|
|
- var shopperChoiceCategory=$(this).text();
|
|
2295
|
|
- if(catType=='hasChilds'){
|
|
2296
|
|
- //Now hide all categories but shopper choice.
|
|
2297
|
|
- wpwMsg.shopper_choice(shopperChoiceCategory);
|
|
2298
|
|
- //updating the product steps and bringing the product by category.
|
|
2299
|
|
- wpwKits.subCats($(this).attr('data-category-id'));
|
|
2300
|
|
- globalwpw.productStep='search';
|
|
2301
|
|
- globalwpw.wildCard=1;
|
|
2302
|
|
- }else{
|
|
2303
|
|
- //Now hide all categories but shopper choice.
|
|
2304
|
|
- wpwMsg.shopper_choice(shopperChoiceCategory);
|
|
2305
|
|
- //updating the product steps and bringing the product by category.
|
|
2306
|
|
- globalwpw.productStep='category';
|
|
2307
|
|
- globalwpw.wildCard=1;
|
|
2308
|
|
- //keeping value in localstorage
|
|
2309
|
|
- localStorage.setItem("productStep", globalwpw.productStep);
|
|
2310
|
|
- wpwAction.bot(shopperChoiceCatId);
|
|
2311
|
|
- }
|
|
2312
|
|
- });
|
|
2313
|
|
- //Product Load More features for product search or category products
|
|
2314
|
|
- $(document).on('click','#wp-chatbot-loadmore',function (e) {
|
|
2315
|
|
- $('#wp-chatbot-loadmore-loader').html('<img class="wp-chatbot-comment-loader" src="'+globalwpw.settings.obj.image_path+'loadmore.gif" alt="..." />');
|
|
2316
|
|
- var loadMoreDom=$(this);
|
|
2317
|
|
- var productOffest=loadMoreDom.attr('data-offset');
|
|
2318
|
|
- var searchType=loadMoreDom.attr('data-search-type');
|
|
2319
|
|
- var searchTerm=loadMoreDom.attr('data-search-term');
|
|
2320
|
|
- var data = { 'action': 'qcld_wb_chatbot_load_more','offset': productOffest,'search_type': searchType,'search_term': searchTerm};
|
|
2321
|
|
- //Load more ajax handler.
|
|
2322
|
|
- wpwKits.ajax(data).done(function (response) {
|
|
2323
|
|
- //Change button text
|
|
2324
|
|
- $('#wp-chatbot-loadmore-loader').html('');
|
|
2325
|
|
- $('.wp-chatbot-products').append(response.html);
|
|
2326
|
|
- loadMoreDom.attr('data-search-term',response.search_term);
|
|
2327
|
|
- wpwKits.wpwHistorySave();
|
|
2328
|
|
- loadMoreDom.attr('data-offset',response.offset);
|
|
2329
|
|
- if(response.product_num <= response.per_page){
|
|
2330
|
|
- loadMoreDom.hide();
|
|
2331
|
|
- //Now show the user infinite.
|
|
2332
|
|
- setTimeout(function () {
|
|
2333
|
|
- var searchAgain = wpwKits.randomMsg(globalwpw.settings.obj.product_infinite);
|
|
2334
|
|
- wpwMsg.single(searchAgain);
|
|
2335
|
|
- globalwpw.productStep='search';
|
|
2336
|
|
- //keeping value in localstorage
|
|
2337
|
|
- localStorage.setItem("productStep", globalwpw.productStep);
|
|
2338
|
|
- },globalwpw.settings.wildcardsShowTime);
|
|
2339
|
|
- }
|
|
2340
|
|
- //scroll to the last message
|
|
2341
|
|
- wpwKits.scrollTo();
|
|
2342
|
|
- });
|
|
2343
|
|
- });
|
|
2344
|
|
- //search load more
|
|
2345
|
|
- $(document).on('click', '.wp-chatbot-loadmore', function(e){
|
|
2346
|
|
- e.preventDefault();
|
|
2347
|
|
- var obj = $(this);
|
|
2348
|
|
-
|
|
2349
|
|
- var keyword = obj.attr('data-keyword');
|
|
2350
|
|
- var post_type = obj.attr('data-post_type');
|
|
2351
|
|
- var page = obj.attr('data-page');
|
|
2352
|
|
- obj.text('Loading...');
|
|
2353
|
|
- var data = {'action':'wpbo_search_site_pagination','name':globalwpw.hasNameCookie,'keyword':keyword,'language': globalwpw.settings.obj.language,'type': post_type, 'page': page, 'nonce': qcld_chatbot_obj.nonce};
|
|
2354
|
|
- if($(globalwpw.settings.messageLastChild+' .wp-chatbot-comment-loader').length==0){
|
|
2355
|
|
- $(globalwpw.settings.messageContainer).append(wpwKits.botPreloader());
|
|
2356
|
|
- }
|
|
2357
|
|
- wpwKits.ajax(data).done(function (res) {
|
|
2358
|
|
- var json = (res);
|
|
2359
|
|
- if(json.status=='success'){
|
|
2360
|
|
- $('span[data-wildcart="back"]').remove();
|
|
2361
|
|
- wpwMsg.single(json.html);
|
|
2362
|
|
- // Hide the comment loader after response inside parent .wp-chatbot-paragraph
|
|
2363
|
|
- // Hide the entire li.wp-chatbot-msg if its .wp-chatbot-paragraph only contains the loader image (and is hidden)
|
|
2364
|
|
-
|
|
2365
|
|
- setTimeout(function(){
|
|
2366
|
|
- if((globalwpw.settings.obj.qcld_disable_repited_startmenu != "1") && (globalwpw.settings.obj.disable_back_to_start != '1' && globalwpw.settings.obj.skip_greetings_and_menu != 1)){
|
|
2367
|
|
- wpwMsg.single_nobg('<span class="qcld-chatbot-wildcard qcld_back_to_start" data-wildcart="back">' + wpwKits.randomMsg(globalwpw.settings.obj.back_to_start) + '</span>');
|
|
2368
|
|
- }
|
|
2369
|
|
- },globalwpw.settings.preLoadingTime)
|
|
2370
|
|
-
|
|
2371
|
|
- obj.remove();
|
|
2372
|
|
- }else{
|
|
2373
|
|
-
|
|
2374
|
|
- if(globalwpw.counter == globalwpw.settings.obj.no_result_attempt_count || globalwpw.settings.obj.no_result_attempt_count == 0 ){
|
|
2375
|
|
-
|
|
2376
|
|
- wpwMsg.single(json.html);
|
|
2377
|
|
- if(globalwpw.settings.obj.disable_repeatative!=1){
|
|
2378
|
|
- if ( wpwKits.render( globalwpw.settings.obj.no_result_attempt_message ) != '' ) {
|
|
2379
|
|
- setTimeout(function(){
|
|
2380
|
|
- wpwMsg.single(wpwKits.render( globalwpw.settings.obj.no_result_attempt_message ));
|
|
2381
|
|
- },globalwpw.settings.preLoadingTime)
|
|
2382
|
|
- } else {
|
|
2383
|
|
- setTimeout(function(){
|
|
2384
|
|
- var serviceOffer=wpwKits.randomMsg(globalwpw.settings.obj.support_option_again);
|
|
2385
|
|
- if((globalwpw.settings.obj.qcld_disable_start_menu != "1")){
|
|
2386
|
|
- if(typeof(globalwpw.wildcards) != 'undefined' && (globalwpw.wildcards != '')){
|
|
2387
|
|
- console.log(globalwpw.wildcards);
|
|
2388
|
|
- wpwMsg.double_nobg(serviceOffer,globalwpw.wildcards);
|
|
2389
|
|
- }else{
|
|
2390
|
|
- wpwMsg.single(serviceOffer);
|
|
2391
|
|
- }
|
|
2392
|
|
-
|
|
2393
|
|
- }
|
|
2394
|
|
-
|
|
2395
|
|
- },globalwpw.settings.preLoadingTime)
|
|
2396
|
|
- }
|
|
2397
|
|
- }
|
|
2398
|
|
- globalwpw.counter = 0;
|
|
2399
|
|
-
|
|
2400
|
|
- }else{
|
|
2401
|
|
- globalwpw.counter++;
|
|
2402
|
|
- wpwTree.df_reply(res);
|
|
2403
|
|
- }
|
|
2404
|
|
-
|
|
2405
|
|
- }
|
|
2406
|
|
- globalwpw.wildCard=0;
|
|
2407
|
|
-
|
|
2408
|
|
- });
|
|
2409
|
|
-
|
|
2410
|
|
-
|
|
2411
|
|
- })
|
|
2412
|
|
-
|
|
2413
|
|
- //search load more
|
|
2414
|
|
- $(document).on('click', '.wp-chatbot-loadmore2', function(e){
|
|
2415
|
|
- e.preventDefault();
|
|
2416
|
|
- var obj = $(this);
|
|
2417
|
|
-
|
|
2418
|
|
- var keyword = obj.attr('data-keyword');
|
|
2419
|
|
-
|
|
2420
|
|
- var page = obj.attr('data-page');
|
|
2421
|
|
-
|
|
2422
|
|
- var search_type = obj.attr('data-search-type');
|
|
2423
|
|
- obj.text(globalwpw.settings.obj.loading.en_US);
|
|
2424
|
|
-
|
|
2425
|
|
- if( search_type == 'default-wp-search' ){
|
|
2426
|
|
- var data = {'action':'wpbo_default_search_pagination2','name':globalwpw.hasNameCookie,'keyword':keyword, 'page': page, search_type:'default-wp-search'};
|
|
2427
|
|
- }else{
|
|
2428
|
|
- var data = {'action':'wpbo_search_site_pagination2','name':globalwpw.hasNameCookie,'keyword':keyword, 'page': page,'nonce': qcld_chatbot_obj.nonce};
|
|
2429
|
|
- }
|
|
2430
|
|
- if($(globalwpw.settings.messageLastChild+' .wp-chatbot-comment-loader').length==0){
|
|
2431
|
|
- $(globalwpw.settings.messageContainer).append(wpwKits.botPreloader());
|
|
2432
|
|
- }
|
|
2433
|
|
- wpwKits.ajax(data).done(function (res) {
|
|
2434
|
|
- var json=$.parseJSON(res);
|
|
2435
|
|
- if(json.status=='success'){
|
|
2436
|
|
- $('span[data-wildcart="back"]').remove();
|
|
2437
|
|
-
|
|
2438
|
|
- wpwMsg.single_nobg(json.html);
|
|
2439
|
|
-
|
|
2440
|
|
- setTimeout(function(){
|
|
2441
|
|
- if((globalwpw.settings.obj.qcld_disable_repited_startmenu != "1") && (globalwpw.settings.obj.disable_back_to_start != '1' && globalwpw.settings.obj.skip_greetings_and_menu != 1)){
|
|
2442
|
|
- wpwMsg.single_nobg('<span class="qcld-chatbot-wildcard qcld_back_to_start" data-wildcart="back">' + wpwKits.randomMsg(globalwpw.settings.obj.back_to_start) + '</span>');
|
|
2443
|
|
- }
|
|
2444
|
|
- },globalwpw.settings.preLoadingTime)
|
|
2445
|
|
-
|
|
2446
|
|
- obj.remove();
|
|
2447
|
|
- }else{
|
|
2448
|
|
-
|
|
2449
|
|
- if(globalwpw.counter == globalwpw.settings.obj.no_result_attempt_count || globalwpw.settings.obj.no_result_attempt_count == 0 ){
|
|
2450
|
|
-
|
|
2451
|
|
- wpwMsg.single(json.html);
|
|
2452
|
|
- wpwTree.start_menu_settings();
|
|
2453
|
|
- globalwpw.counter = 0;
|
|
2454
|
|
-
|
|
2455
|
|
- }else{
|
|
2456
|
|
- globalwpw.counter++;
|
|
2457
|
|
- wpwTree.df_reply(res);
|
|
2458
|
|
- }
|
|
2459
|
|
-
|
|
2460
|
|
- }
|
|
2461
|
|
- globalwpw.wildCard=0;
|
|
2462
|
|
- });
|
|
2463
|
|
-
|
|
2464
|
|
-
|
|
2465
|
|
- });
|
|
2466
|
|
- /*Products details part **/
|
|
2467
|
|
- // if(globalwpw.settings.obj.open_product_detail!=1){
|
|
2468
|
|
- // $(document).on('click','.wp-chatbot-product a',function (e) {
|
|
2469
|
|
- // e.preventDefault();
|
|
2470
|
|
- // $('.wp-chatbot-product-container').addClass('active-chatbot-product-details');
|
|
2471
|
|
- // $('.wp-chatbot-product-reload').addClass('wp-chatbot-product-loading').html('<img class="wp-chatbot-product-loader" src="'+globalwpw.settings.obj.image_path+'comment.gif" alt="Loading..." />');
|
|
2472
|
|
- // var productId=$(this).attr('wp-chatbot-pid');
|
|
2473
|
|
- // var data = { 'action':'qcld_wb_chatbot_product_details', 'wp_chatbot_pid':productId};
|
|
2474
|
|
- // //product details ajax handler.
|
|
2475
|
|
- // wpwKits.ajax(data).done(function (response) {
|
|
2476
|
|
- // $('.wp-chatbot-product-reload').removeClass('wp-chatbot-product-loading').html('');
|
|
2477
|
|
- // $('#wp-chatbot-product-title').html(response.title);
|
|
2478
|
|
- // $('#wp-chatbot-product-description').html(response.description);
|
|
2479
|
|
- // $('#wp-chatbot-product-image').html(response.image);
|
|
2480
|
|
- // $('#wp-chatbot-product-price').html(response.price);
|
|
2481
|
|
- // $('#wp-chatbot-product-quantity').html(response.quantity);
|
|
2482
|
|
- // $('#wp-chatbot-product-variable').html(response.variation);
|
|
2483
|
|
- // $('#wp-chatbot-product-cart-button').html(response.buttton);
|
|
2484
|
|
- // //Load gallery magnify
|
|
2485
|
|
- // setTimeout(function () {
|
|
2486
|
|
- // $('#wp-chatbot-product-image-large-path').magnificPopup({type:'image'});
|
|
2487
|
|
- // },1000);
|
|
2488
|
|
- // //For shortcode handle recenlty view product by ajax as
|
|
2489
|
|
- // if($('#wp-chatbot-shortcode-template-container').length > 0){
|
|
2490
|
|
- // var data = {'action':'qcld_wb_chatbot_recently_viewed_products'};
|
|
2491
|
|
- // wpwKits.ajax(data).done(function (response) {
|
|
2492
|
|
- // $('.wp-chatbot-product-shortcode-container').html(response);
|
|
2493
|
|
- // $('.chatbot-sidebar .wp-chatbot-products').slimScroll({height: '435px', start: 'top'});
|
|
2494
|
|
- // });
|
|
2495
|
|
- // }
|
|
2496
|
|
- // });
|
|
2497
|
|
- // });
|
|
2498
|
|
- // }
|
|
2499
|
|
- //Image gallery.
|
|
2500
|
|
- $(document).on('click','.wp-chatbot-product-image-thumbs-path',function (e) {
|
|
2501
|
|
- e.preventDefault();
|
|
2502
|
|
- var imagePath=$(this).attr('href');
|
|
2503
|
|
- $('#wp-chatbot-product-image-large-path').attr('href',imagePath);
|
|
2504
|
|
- $('#wp-chatbot-product-image-large-src').attr('src',imagePath);
|
|
2505
|
|
- //handle thumb active one
|
|
2506
|
|
- $('.wp-chatbot-product-image-thumbs-path').parent().removeClass('wp-chatbot-product-active-image-thumbs');
|
|
2507
|
|
- $(this).parent().addClass('wp-chatbot-product-active-image-thumbs');
|
|
2508
|
|
- });
|
|
2509
|
|
- //Product details close
|
|
2510
|
|
- $(document).on('click', '.wp-chatbot-product-close', function (e) {
|
|
2511
|
|
- $('.wp-chatbot-product-container').removeClass('active-chatbot-product-details');
|
|
2512
|
|
- });
|
|
2513
|
|
- /*add to cart part **/
|
|
2514
|
|
- $(document).on("click","#wp-chatbot-add-cart-button",function (e) {
|
|
2515
|
|
- var pId=$(this).attr('wp-chatbot-product-id');
|
|
2516
|
|
- var qnty=$("#vPQuantity").val();
|
|
2517
|
|
- var data = {'action': 'qcld_wb_chatbot_add_to_cart','product_id': pId,'quantity': qnty };
|
|
2518
|
|
- //add to cart ajax handler.
|
|
2519
|
|
- wpwKits.ajax(data).done(function (response) {
|
|
2520
|
|
- //Change button text
|
|
2521
|
|
- if(response=="simple"){
|
|
2522
|
|
- //Showing cart.
|
|
2523
|
|
- wpwKits.showCart();
|
|
2524
|
|
- //handle the active tab on chat board.
|
|
2525
|
|
- $('.wp-chatbot-operation-option').each(function(){
|
|
2526
|
|
- if($(this).attr('data-option')=='cart'){
|
|
2527
|
|
- $(this).parent().addClass('wp-chatbot-operation-active');
|
|
2528
|
|
- }else{
|
|
2529
|
|
- $(this).parent().removeClass('wp-chatbot-operation-active');
|
|
2530
|
|
- }
|
|
2531
|
|
- });
|
|
2532
|
|
- }
|
|
2533
|
|
- //Hide the shortcode and chat ui product details.
|
|
2534
|
|
- $('.wp-chatbot-product-container').removeClass('active-chatbot-product-details');
|
|
2535
|
|
- });
|
|
2536
|
|
- });
|
|
2537
|
|
- //Add to cart operation for variable product.
|
|
2538
|
|
- $(document).on('click','#wp-chatbot-variation-add-to-cart',function(event) {
|
|
2539
|
|
- event.preventDefault();
|
|
2540
|
|
- var pId=$(this).attr('wp-chatbot-product-id');
|
|
2541
|
|
- var quanity=$('#vPQuantity').val();
|
|
2542
|
|
- var variation_id=$(this).attr('variation_id');
|
|
2543
|
|
- var attributes=new Array();
|
|
2544
|
|
- $.each($("#wp-chatbot-variation-data select"), function(){
|
|
2545
|
|
- var attribute = $(this).attr('name')+'#'+ $(this).find('option:selected').text();
|
|
2546
|
|
- attributes.push(attribute);
|
|
2547
|
|
- });
|
|
2548
|
|
- var data = {
|
|
2549
|
|
- 'action': 'qcld_variable_add_to_cart',
|
|
2550
|
|
- 'p_id': pId,
|
|
2551
|
|
- 'quantity': quanity,
|
|
2552
|
|
- 'variations_id':variation_id,
|
|
2553
|
|
- 'attributes':attributes
|
|
2554
|
|
- };
|
|
2555
|
|
- //add to cart ajax handler.
|
|
2556
|
|
- wpwKits.ajax(data).done(function (response) {
|
|
2557
|
|
- //Change button text
|
|
2558
|
|
- if(response=="variable"){
|
|
2559
|
|
- //Showing cart.
|
|
2560
|
|
- wpwKits.showCart();
|
|
2561
|
|
- //handle the active tab on chat board.
|
|
2562
|
|
- //handle the active tab on chat board.
|
|
2563
|
|
- $('.wp-chatbot-operation-option').each(function(){
|
|
2564
|
|
- if($(this).attr('data-option')=='cart'){
|
|
2565
|
|
- $(this).parent().addClass('wp-chatbot-operation-active');
|
|
2566
|
|
- }else{
|
|
2567
|
|
- $(this).parent().removeClass('wp-chatbot-operation-active');
|
|
2568
|
|
- }
|
|
2569
|
|
- });
|
|
2570
|
|
- }
|
|
2571
|
|
- //Hide the shortcode and chat ui product details.
|
|
2572
|
|
- $('.wp-chatbot-product-container').removeClass('active-chatbot-product-details');
|
|
2573
|
|
- });
|
|
2574
|
|
- });
|
|
2575
|
|
- //Update cart.
|
|
2576
|
|
- $(document).on("change", ".qcld-wp-chatbot-cart-item-qnty", function () {
|
|
2577
|
|
- //Update editor only for chat ui
|
|
2578
|
|
- if($('#wp-chatbot-shortcode-template-container').length == 0) {
|
|
2579
|
|
- wpwKits.disableEditor(wpwKits.randomMsg(globalwpw.settings.obj.cart_updating));
|
|
2580
|
|
- }
|
|
2581
|
|
- var currentItem=$(this);
|
|
2582
|
|
- setTimeout(function () {
|
|
2583
|
|
- var item_key=currentItem.attr('data-cart-item');
|
|
2584
|
|
- var qnty=currentItem.val();
|
|
2585
|
|
- var data = {'action': 'qcld_wb_chatbot_update_cart_item_number','cart_item_key':item_key,'qnty':qnty};
|
|
2586
|
|
- wpwKits.ajax(data).done(function () {
|
|
2587
|
|
- //Showing cart.
|
|
2588
|
|
- wpwKits.showCart();
|
|
2589
|
|
- });
|
|
2590
|
|
- }, globalwpw.settings.preLoadingTime);
|
|
2591
|
|
- });
|
|
2592
|
|
- //remove the cart item from global cart.
|
|
2593
|
|
- $(document).on("click", ".wp-chatbot-remove-cart-item", function () {
|
|
2594
|
|
- //Update editor only for chat ui
|
|
2595
|
|
- if($('#wp-chatbot-shortcode-template-container').length == 0) {
|
|
2596
|
|
- wpwKits.disableEditor(wpwKits.randomMsg(globalwpw.settings.obj.cart_removing));
|
|
2597
|
|
- }
|
|
2598
|
|
- var item=$(this).attr('data-cart-item');
|
|
2599
|
|
- var data = {'action': 'qcld_wb_chatbot_cart_item_remove', 'cart_item':item };
|
|
2600
|
|
- wpwKits.ajax(data).done(function () {
|
|
2601
|
|
- //Showing cart.
|
|
2602
|
|
- wpwKits.showCart();
|
|
2603
|
|
- })
|
|
2604
|
|
- });
|
|
2605
|
|
- /*Support query answering.. **/
|
|
2606
|
|
- $(document).on('click','.qcld-chatbot-support-items',function (e) {
|
|
2607
|
|
- var shopperChoose=$(this).text();
|
|
2608
|
|
- var queryIndex=$(this).attr('data-query-index');
|
|
2609
|
|
- wpwMsg.shopper_choice(shopperChoose);
|
|
2610
|
|
- //Now answering the query.
|
|
2611
|
|
- var queryAns=globalwpw.settings.obj.support_ans[queryIndex];
|
|
2612
|
|
- wpwMsg.single(queryAns);
|
|
2613
|
|
- //Asking email after showing answer.
|
|
2614
|
|
- var orPhoneSuggest='';
|
|
2615
|
|
- setTimeout(function(){
|
|
2616
|
|
- if(globalwpw.settings.obj.call_sup!=1) {
|
|
2617
|
|
- orPhoneSuggest = '<span class="qcld-chatbot-suggest-phone" >' + wpwKits.randomMsg(globalwpw.settings.obj.support_phone) + '</span>';
|
|
2618
|
|
- }
|
|
2619
|
|
- var orEmailSuggest='<span class="qcld-chatbot-suggest-email">'+wpwKits.randomMsg(globalwpw.settings.obj.support_email)+'</span>';
|
|
2620
|
|
- wpwKits.suggestEmail(orPhoneSuggest+orEmailSuggest);
|
|
2621
|
|
- },globalwpw.settings.wildcardsShowTime);
|
|
2622
|
|
- });
|
|
2623
|
|
- /*Support Email **/
|
|
2624
|
|
- $(document).on('click','.qcld-chatbot-suggest-email',function (e) {
|
|
2625
|
|
- var shopperChoice=$(this).text();
|
|
2626
|
|
- wpwMsg.shopper_choice(shopperChoice);
|
|
2627
|
|
- //Then ask email address
|
|
2628
|
|
- if(typeof(globalwpw.hasNameCookie)=='undefined'|| globalwpw.hasNameCookie==''){
|
|
2629
|
|
- var shopperName= globalwpw.settings.obj.shopper_demo_name;
|
|
2630
|
|
- }else{
|
|
2631
|
|
- var shopperName=globalwpw.hasNameCookie;
|
|
2632
|
|
- }
|
|
2633
|
|
- var ask_msg = wpwKits.randomMsg(globalwpw.settings.obj.asking_email);
|
|
2634
|
|
- var askEmail = (globalwpw.settings.obj.skip_wp_greetings=='1' || globalwpw.settings.obj.skip_greetings_and_menu =='1') ? wpwKits.randomMsg(globalwpw.settings.obj.hello)+' '+ ask_msg : wpwKits.randomMsg(globalwpw.settings.obj.hello) + ' '+shopperName+'! '+ ask_msg;
|
|
2635
|
|
- wpwMsg.single(askEmail);
|
|
2636
|
|
- //Now updating the support part as .
|
|
2637
|
|
- globalwpw.supportStep='email';
|
|
2638
|
|
- globalwpw.wildCard=1;
|
|
2639
|
|
- //keeping value in localstorage
|
|
2640
|
|
- localStorage.setItem("wildCard", globalwpw.wildCard);
|
|
2641
|
|
- localStorage.setItem("supportStep", globalwpw.supportStep);
|
|
2642
|
|
- });
|
|
2643
|
|
- /*site Search*/
|
|
2644
|
|
- $(document).on('click','.qcld-chatbot-site-search',function (e) {
|
|
2645
|
|
- var shopperChoice=$(this).text();
|
|
2646
|
|
- wpwMsg.shopper_choice(shopperChoice);
|
|
2647
|
|
- //Then ask email address
|
|
2648
|
|
- if(typeof(globalwpw.hasNameCookie)=='undefined'|| globalwpw.hasNameCookie==''){
|
|
2649
|
|
- var shopperName= globalwpw.settings.obj.shopper_demo_name;
|
|
2650
|
|
- }else{
|
|
2651
|
|
- var shopperName=globalwpw.hasNameCookie;
|
|
2652
|
|
- }
|
|
2653
|
|
- var ask_msg = wp_chatbot_obj.search_keyword;
|
|
2654
|
|
- var askEmail = (globalwpw.settings.obj.skip_wp_greetings=='1' || globalwpw.settings.obj.skip_greetings_and_menu =='1') ? 'Hello ' + ask_msg : 'Hello '+shopperName+'! '+ ask_msg;
|
|
2655
|
|
- wpwMsg.single(askEmail);
|
|
2656
|
|
- //Now updating the support part as .
|
|
2657
|
|
- globalwpw.supportStep='search';
|
|
2658
|
|
- globalwpw.wildCard=1;
|
|
2659
|
|
- //keeping value in localstorage
|
|
2660
|
|
- localStorage.setItem("wildCard", globalwpw.wildCard);
|
|
2661
|
|
- localStorage.setItem("supportStep", globalwpw.supportStep);
|
|
2662
|
|
- });
|
|
2663
|
|
- /*Support Phone **/
|
|
2664
|
|
- $(document).on('click','.qcld-chatbot-suggest-phone',function (e) {
|
|
2665
|
|
- var shopperChoice=$(this).text();
|
|
2666
|
|
- wpwMsg.shopper_choice(shopperChoice);
|
|
2667
|
|
- //Then ask email address
|
|
2668
|
|
- if(typeof(globalwpw.hasNameCookie)=='undefined'|| globalwpw.hasNameCookie==''){
|
|
2669
|
|
- var shopperName= globalwpw.settings.obj.shopper_demo_name;
|
|
2670
|
|
- }else{
|
|
2671
|
|
- var shopperName=globalwpw.hasNameCookie;
|
|
2672
|
|
- }
|
|
2673
|
|
- var ask_msg = wpwKits.randomMsg(globalwpw.settings.obj.asking_phone);
|
|
2674
|
|
- var askEmail = (globalwpw.settings.obj.skip_wp_greetings=='1' || globalwpw.settings.obj.skip_greetings_and_menu =='1') ? 'Hello ' + ask_msg : 'Hello '+shopperName+'! '+ ask_msg;
|
|
2675
|
|
- wpwMsg.single(askEmail);
|
|
2676
|
|
- //Now updating the support part as .
|
|
2677
|
|
- globalwpw.supportStep='phone';
|
|
2678
|
|
- globalwpw.wildCard=1;
|
|
2679
|
|
- //keeping value in localstorage
|
|
2680
|
|
- localStorage.setItem("wildCard", globalwpw.wildCard);
|
|
2681
|
|
- localStorage.setItem("supportStep", globalwpw.supportStep);
|
|
2682
|
|
- });
|
|
2683
|
|
- //Show chat,cart and recently view products by click event.
|
|
2684
|
|
- $(document).on('click','.wp-chatbot-operation-option',function (e) {
|
|
2685
|
|
- e.preventDefault();
|
|
2686
|
|
- var oppt=$(this).attr('data-option');
|
|
2687
|
|
- if(oppt=='recent' && globalwpw.wpwIsWorking==0){
|
|
2688
|
|
- wpwKits.disableEditor(globalwpw.settings.obj.sys_key_product);
|
|
2689
|
|
- var data = {'action':'qcld_wb_chatbot_recently_viewed_products'};
|
|
2690
|
|
- wpwKits.ajax(data).done(function (response) {
|
|
2691
|
|
- $(globalwpw.settings.messageWrapper).html(response);
|
|
2692
|
|
- });
|
|
2693
|
|
- //First remove wp-chatbot-operation-active class from all selector
|
|
2694
|
|
- $('.wp-chatbot-operation-option').parent().removeClass('wp-chatbot-operation-active');
|
|
2695
|
|
- //then add the active class to current element.
|
|
2696
|
|
- $(this).parent().addClass('wp-chatbot-operation-active');
|
|
2697
|
|
- }else if(oppt=='chat' && globalwpw.wpwIsWorking==0){
|
|
2698
|
|
- $(globalwpw.settings.messageWrapper).html(localStorage.getItem("wpwHitory"));
|
|
2699
|
|
- wpwKits.scrollTo();
|
|
2700
|
|
- wpwKits.enableEditor(wpwKits.randomMsg(globalwpw.settings.obj.send_a_msg));
|
|
2701
|
|
- //First remove wp-chatbot-operation-active class from all selector
|
|
2702
|
|
- $('.wp-chatbot-operation-option').parent().removeClass('wp-chatbot-operation-active');
|
|
2703
|
|
- //then add the active class to current element.
|
|
2704
|
|
- $(this).parent().addClass('wp-chatbot-operation-active');
|
|
2705
|
|
- } else if(oppt=='cart' && globalwpw.wpwIsWorking==0){
|
|
2706
|
|
- wpwKits.showCart();
|
|
2707
|
|
- //First remove wp-chatbot-operation-active class from all selector
|
|
2708
|
|
- $('.wp-chatbot-operation-option').parent().removeClass('wp-chatbot-operation-active');
|
|
2709
|
|
- //then add the active class to current element.
|
|
2710
|
|
- $(this).parent().addClass('wp-chatbot-operation-active');
|
|
2711
|
|
- } else if(oppt=='help' && globalwpw.wpwIsWorking==0){
|
|
2712
|
|
- if( $('.wp-chatbot-messages-container').length==0) {
|
|
2713
|
|
- //if from other nob then goo to the chat window
|
|
2714
|
|
- $(globalwpw.settings.messageWrapper).html(localStorage.getItem("wpwHitory"));
|
|
2715
|
|
- //Showing help message
|
|
2716
|
|
- setTimeout(function () {
|
|
2717
|
|
- wpwKits.scrollTo();
|
|
2718
|
|
- var helpWelcome = wpwKits.randomMsg(globalwpw.settings.obj.help_welcome);
|
|
2719
|
|
- var helpMsg = wpwKits.decodehtml(wpwKits.randomMsg(globalwpw.settings.obj.help_msg));
|
|
2720
|
|
- wpwMsg.double(helpWelcome,helpMsg);
|
|
2721
|
|
- //dialogflow
|
|
2722
|
|
- if(globalwpw.settings.obj.ai_df_enable==1 && globalwpw.df_status_lock==0){
|
|
2723
|
|
- globalwpw.wildCard=0;
|
|
2724
|
|
- globalwpw.ai_step=1;
|
|
2725
|
|
- localStorage.setItem("wildCard", globalwpw.wildCard);
|
|
2726
|
|
- localStorage.setItem("aiStep", globalwpw.ai_step);
|
|
2727
|
|
- }
|
|
2728
|
|
- },globalwpw.settings.preLoadingTime);
|
|
2729
|
|
- }else{
|
|
2730
|
|
- //Showing help message on chat self window.
|
|
2731
|
|
- var helpWelcome = wpwKits.randomMsg(globalwpw.settings.obj.help_welcome);
|
|
2732
|
|
- var helpMsg = wpwKits.randomMsg(globalwpw.settings.obj.help_msg);
|
|
2733
|
|
- wpwMsg.double(helpWelcome,helpMsg);
|
|
2734
|
|
- //dialogflow
|
|
2735
|
|
- if(globalwpw.settings.obj.ai_df_enable==1 && globalwpw.df_status_lock==0){
|
|
2736
|
|
- globalwpw.wildCard=0;
|
|
2737
|
|
- globalwpw.ai_step=1;
|
|
2738
|
|
- localStorage.setItem("wildCard", globalwpw.wildCard);
|
|
2739
|
|
- localStorage.setItem("aiStep", globalwpw.ai_step);
|
|
2740
|
|
- }
|
|
2741
|
|
- }
|
|
2742
|
|
- //First remove wp-chatbot-operation-active class from all selector
|
|
2743
|
|
- $('.wp-chatbot-operation-option').parent().removeClass('wp-chatbot-operation-active');
|
|
2744
|
|
- //then add the active class to current element.
|
|
2745
|
|
- $(this).parent().addClass('wp-chatbot-operation-active');
|
|
2746
|
|
- } else if(oppt=='support' && globalwpw.wpwIsWorking==0){
|
|
2747
|
|
- if( $('.wp-chatbot-messages-container').length==0) {
|
|
2748
|
|
- //if from other nob then goo to the chat window
|
|
2749
|
|
- $(globalwpw.settings.messageWrapper).html(localStorage.getItem("wpwHitory"));
|
|
2750
|
|
- //Showing help message
|
|
2751
|
|
- setTimeout(function () {
|
|
2752
|
|
- wpwKits.scrollTo();
|
|
2753
|
|
- globalwpw.wildCard=1;
|
|
2754
|
|
- globalwpw.supportStep='welcome';
|
|
2755
|
|
- wpwTree.support(globalwpw.settings.obj.sys_key_support.toLowerCase());
|
|
2756
|
|
- },globalwpw.settings.preLoadingTime);
|
|
2757
|
|
- }else{
|
|
2758
|
|
- //Showing help message on chat self window.
|
|
2759
|
|
- globalwpw.wildCard=1;
|
|
2760
|
|
- globalwpw.supportStep='welcome';
|
|
2761
|
|
- wpwTree.support(globalwpw.settings.obj.sys_key_support.toLowerCase());
|
|
2762
|
|
- }
|
|
2763
|
|
- //First remove wp-chatbot-operation-active class from all selector
|
|
2764
|
|
- $('.wp-chatbot-operation-option').parent().removeClass('wp-chatbot-operation-active');
|
|
2765
|
|
- //then add the active class to current element.
|
|
2766
|
|
- $(this).parent().addClass('wp-chatbot-operation-active');
|
|
2767
|
|
- }
|
|
2768
|
|
- //show chat wrapper and hide cart-checkout wrapper
|
|
2769
|
|
- $(globalwpw.settings.messageWrapper).show();
|
|
2770
|
|
- $('#wp-chatbot-checkout-short-code').hide();
|
|
2771
|
|
- $('#wp-chatbot-cart-short-code').hide();
|
|
2772
|
|
- });
|
|
2773
|
|
- $(document).on('click','.qcld-chatbot-reset-btn',function (e) {
|
|
2774
|
|
- e.preventDefault();
|
|
2775
|
|
- var actionType=$(this).attr('reset-data');
|
|
2776
|
|
- if(actionType=='yes'){
|
|
2777
|
|
-
|
|
2778
|
|
- $('#wp-chatbot-messages-container').html('');
|
|
2779
|
|
- localStorage.removeItem('shopper');
|
|
2780
|
|
- globalwpw.wildCard=0;
|
|
2781
|
|
- globalwpw.ai_step=0;
|
|
2782
|
|
- localStorage.setItem("wildCard", globalwpw.wildCard);
|
|
2783
|
|
- localStorage.setItem("aiStep", globalwpw.ai_step);
|
|
2784
|
|
- globalwpw.formfieldid = '';
|
|
2785
|
|
- localStorage.setItem("formfieldid", globalwpw.formfieldid);
|
|
2786
|
|
- globalwpw.formStep='welcome';
|
|
2787
|
|
- localStorage.setItem("formStep", globalwpw.formStep);
|
|
2788
|
|
- globalwpw.formid='';
|
|
2789
|
|
- localStorage.setItem("formid", globalwpw.formid);
|
|
2790
|
|
- globalwpw.formentry = 0;
|
|
2791
|
|
- localStorage.setItem("formentry", globalwpw.formentry);
|
|
2792
|
|
- localStorage.removeItem("cx-name" );
|
|
2793
|
|
- localStorage.removeItem("cx-diaplayname" );
|
|
2794
|
|
- localStorage.removeItem("cx-languagecode" );
|
|
2795
|
|
- localStorage.removeItem("cx-timezone" );
|
|
2796
|
|
- var number = Math.random() // 0.9394456857981651
|
|
2797
|
|
- number.toString(36); // '0.xtis06h6'
|
|
2798
|
|
- var id = number.toString(36).substr(2); // 'xtis06h6'
|
|
2799
|
|
- localStorage.setItem('botsessionid', id);
|
|
2800
|
|
- wpwWelcome.greeting();
|
|
2801
|
|
- } else if(actionType=='no'){
|
|
2802
|
|
- wpwAction.bot(globalwpw.settings.obj.sys_key_help.toLowerCase());
|
|
2803
|
|
- }
|
|
2804
|
|
- });
|
|
2805
|
|
- return this;
|
|
2806
|
|
- };
|
|
2807
|
|
- //Deafault value for wpwbot.If nothing passes from the work station
|
|
2808
|
|
- //Then defaults value will be used.
|
|
2809
|
|
- $.wpwbot.defaults={
|
|
2810
|
|
- obj:{},
|
|
2811
|
|
- editor_handler:0,
|
|
2812
|
|
- sendButton:'#wp-chatbot-send-message',
|
|
2813
|
|
- messageEditor:'#wp-chatbot-editor',
|
|
2814
|
|
- messageContainer:'#wp-chatbot-messages-container',
|
|
2815
|
|
- messageWrapper:'.wp-chatbot-messages-wrapper',
|
|
2816
|
|
- botContainer:'.wp-chatbot-ball-inner',
|
|
2817
|
|
- messageLastChild:'#wp-chatbot-messages-container li:last',
|
|
2818
|
|
- messageLastBot:'#wp-chatbot-messages-container .wp-chatbot-msg:last .wp-chatbot-paragraph',
|
|
2819
|
|
- preLoadingTime:0,
|
|
2820
|
|
- wildcardsShowTime:5000,
|
|
2821
|
|
- }
|
|
2822
|
|
-
|
|
2823
|
|
- document.addEventListener("click", function(e) {
|
|
2824
|
|
- // Toggle share menu
|
|
2825
|
|
- if (e.target.closest(".share-toggle")) {
|
|
2826
|
|
- e.preventDefault();
|
|
2827
|
|
- let menu = e.target.closest(".qcld-share").querySelector(".share-menu");
|
|
2828
|
|
- menu.style.display = menu.style.display === "none" ? "block" : "none";
|
|
2829
|
|
- }
|
|
2830
|
|
-
|
|
2831
|
|
- // Find message content dynamically
|
|
2832
|
|
- let msgItem = e.target.closest(".wp-chatbot-msg");
|
|
2833
|
|
- if (!msgItem) return;
|
|
2834
|
|
-
|
|
2835
|
|
- let msgContent = msgItem.querySelector(".wp-chatbot-paragraph");
|
|
2836
|
|
- if (!msgContent) return;
|
|
2837
|
|
-
|
|
2838
|
|
- // Extract plain text
|
|
2839
|
|
- let msgText = msgContent.innerText.trim();
|
|
2840
|
|
- let shareSite = window.location.origin; // Get the site URL dynamically (e.g., "https://www.example.com")
|
|
2841
|
|
- // Ensure a trailing slash if it's meant to represent the root of the site
|
|
2842
|
|
- if (!shareSite.endsWith('/')) {
|
|
2843
|
|
- shareSite += '/';
|
|
2844
|
|
- }
|
|
2845
|
|
- let fullMsg = `${msgText}\n-- ${shareSite}`;
|
|
2846
|
|
- let encodedMsg = encodeURIComponent(fullMsg);
|
|
2847
|
|
-
|
|
2848
|
|
- // Facebook (requires App ID)
|
|
2849
|
|
- if (e.target.closest(".share-fb")) {
|
|
2850
|
|
- e.preventDefault();
|
|
2851
|
|
-
|
|
2852
|
|
- // You must include a URL even if you're just sharing text
|
|
2853
|
|
- const shareURL = encodeURIComponent(window.location.href); // or your chatbot page URL
|
|
2854
|
|
- const fbShareURL = "https://www.facebook.com/sharer/sharer.php?u=" + shareURL + ""e=" + encodedMsg;
|
|
2855
|
|
-
|
|
2856
|
|
- window.open(fbShareURL, "_blank", "width=600,height=400");
|
|
2857
|
|
- }
|
|
2858
|
|
-
|
|
2859
|
|
- // WhatsApp
|
|
2860
|
|
- if (e.target.closest(".share-wa")) {
|
|
2861
|
|
- e.preventDefault();
|
|
2862
|
|
- window.open("https://wa.me/?text=" + encodedMsg, "_blank");
|
|
2863
|
|
- }
|
|
2864
|
|
-
|
|
2865
|
|
- // X (Twitter)
|
|
2866
|
|
- if (e.target.closest(".share-x")) {
|
|
2867
|
|
- e.preventDefault();
|
|
2868
|
|
- window.open("https://twitter.com/intent/tweet?text=" + encodedMsg, "_blank");
|
|
2869
|
|
- }
|
|
2870
|
|
-
|
|
2871
|
|
- // Email
|
|
2872
|
|
- if (e.target.closest(".share-email")) {
|
|
2873
|
|
- e.preventDefault();
|
|
2874
|
|
- window.location.href = "mailto:?subject=Chatbot Message&body=" + encodedMsg;
|
|
2875
|
|
- }
|
|
2876
|
|
-});
|
|
2877
|
|
-jQuery(document).ready(function($) {
|
|
2878
|
|
-
|
|
2879
|
|
- let reportedMessage = "";
|
|
2880
|
|
- let modalElements = {}; // Store references to modal elements
|
|
2881
|
|
- let isModalInitialized = false; // Flag to prevent re-attaching listeners
|
|
2882
|
|
-
|
|
2883
|
|
- /**
|
|
2884
|
|
- * Initializes the report modal by finding its elements and attaching event listeners.
|
|
2885
|
|
- * This function is designed to be called only once, the first time the report icon is clicked,
|
|
2886
|
|
- * to ensure all DOM elements are available.
|
|
2887
|
|
- * @returns {boolean} True if initialization was successful, false otherwise.
|
|
2888
|
|
- */
|
|
2889
|
|
- function setupReportModal() {
|
|
2890
|
|
- if (isModalInitialized) {
|
|
2891
|
|
- return true; // Already initialized
|
|
2892
|
|
- }
|
|
2893
|
|
-
|
|
2894
|
|
- const modal = document.getElementById("wpbot-report-modal");
|
|
2895
|
|
- const emailInput = document.getElementById("wpbot-report-email");
|
|
2896
|
|
- const textInput = document.getElementById("wpbot-report-text");
|
|
2897
|
|
- const cancelBtn = document.getElementById("wpbot-report-cancel");
|
|
2898
|
|
- const reportForm = document.getElementById("wpbot-report-form");
|
|
2899
|
|
-
|
|
2900
|
|
- if (!modal || !emailInput || !textInput || !cancelBtn || !reportForm) {
|
|
2901
|
|
- console.error("❌ One or more modal elements missing in DOM. Cannot initialize report modal.");
|
|
2902
|
|
- return false; // Initialization failed
|
|
2903
|
|
- }
|
|
2904
|
|
-
|
|
2905
|
|
- // Store references to the elements
|
|
2906
|
|
- modalElements = { modal, emailInput, textInput, cancelBtn, reportForm };
|
|
2907
|
|
-
|
|
2908
|
|
- // Attach event listener for the cancel button
|
|
2909
|
|
- modalElements.cancelBtn.addEventListener("click", function() {
|
|
2910
|
|
- modalElements.modal.style.display = "none";
|
|
2911
|
|
- });
|
|
2912
|
|
-
|
|
2913
|
|
- // Attach event listener for the form submission
|
|
2914
|
|
- modalElements.reportForm.addEventListener("submit", function(e) {
|
|
2915
|
|
- e.preventDefault();
|
|
2916
|
|
-
|
|
2917
|
|
- let email = modalElements.emailInput.value.trim();
|
|
2918
|
|
- let reportText = modalElements.textInput.value.trim();
|
|
2919
|
|
-
|
|
2920
|
|
- if (!email || !reportText) {
|
|
2921
|
|
- alert("Please fill in both fields.");
|
|
2922
|
|
- return;
|
|
2923
|
|
- }
|
|
2924
|
|
-
|
|
2925
|
|
- // Save email to localStorage
|
|
2926
|
|
- localStorage.setItem("shopperemail", email);
|
|
2927
|
|
-
|
|
2928
|
|
- // Build meta info for the report
|
|
2929
|
|
- let meta = "Source URL: " + window.location.href + " | User Agent: " + navigator.userAgent;
|
|
2930
|
|
-
|
|
2931
|
|
- // Send report via AJAX
|
|
2932
|
|
- $.post(wp_chatbot_obj.ajax_url, {
|
|
2933
|
|
- action: "wpbot_save_report",
|
|
2934
|
|
- user_id: globalwpw.settings.obj.current_user_id,
|
|
2935
|
|
- conversation_id: 3,
|
|
2936
|
|
- message: reportedMessage, // Use the message captured when the icon was clicked
|
|
2937
|
|
- report_text: reportText,
|
|
2938
|
|
- email: email,
|
|
2939
|
|
- meta_info: meta
|
|
2940
|
|
- }, function(response) {
|
|
2941
|
|
- if (response.success) {
|
|
2942
|
|
- console.log("Report sent successfully.");
|
|
2943
|
|
- // The original line `jQuery(e.target.closest(".fa fa-commenting-o")).addClass("submitted");`
|
|
2944
|
|
- // was incorrect as `e.target` here refers to the form, not the original icon.
|
|
2945
|
|
- // To mark the icon, a reference to it would need to be stored when it was clicked.
|
|
2946
|
|
- } else {
|
|
2947
|
|
- console.log("Failed to send report.");
|
|
2948
|
|
- }
|
|
2949
|
|
- modalElements.modal.style.display = "none"; // Hide modal after submission
|
|
2950
|
|
- });
|
|
2951
|
|
- });
|
|
2952
|
|
-
|
|
2953
|
|
- isModalInitialized = true; // Mark as initialized
|
|
2954
|
|
- return true; // Initialization successful
|
|
2955
|
|
- }
|
|
2956
|
|
-
|
|
2957
|
|
- // Event listener for clicks on the document to detect report icon clicks
|
|
2958
|
|
- document.addEventListener("click", function(e) {
|
|
2959
|
|
- if (e.target.closest(".fa-commenting-o")) {
|
|
2960
|
|
- e.preventDefault();
|
|
2961
|
|
- console.log("Report icon clicked");
|
|
2962
|
|
-
|
|
2963
|
|
- // Attempt to initialize the modal elements and listeners if not already done.
|
|
2964
|
|
- // This ensures elements are looked up only when needed, making it more robust
|
|
2965
|
|
- // against timing issues if the modal HTML is loaded asynchronously or late.
|
|
2966
|
|
- if (!setupReportModal()) {
|
|
2967
|
|
- return; // If initialization failed (elements not found), stop here.
|
|
2968
|
|
- }
|
|
2969
|
|
-
|
|
2970
|
|
- // Now that we are sure modal elements are available, proceed to open the modal.
|
|
2971
|
|
- let msgItem = e.target.closest(".wp-chatbot-msg");
|
|
2972
|
|
- if (msgItem) {
|
|
2973
|
|
- reportedMessage = msgItem.querySelector(".wp-chatbot-paragraph").innerText.trim();
|
|
2974
|
|
- } else {
|
|
2975
|
|
- reportedMessage = ""; // Fallback if message item not found
|
|
2976
|
|
- }
|
|
2977
|
|
-
|
|
2978
|
|
- // Prefill email from localStorage if available
|
|
2979
|
|
- let shopperEmail = localStorage.getItem("shopperemail");
|
|
2980
|
|
- modalElements.emailInput.value = shopperEmail ? shopperEmail : "";
|
|
2981
|
|
-
|
|
2982
|
|
- // Clear previous report text
|
|
2983
|
|
- modalElements.textInput.value = "";
|
|
2984
|
|
-
|
|
2985
|
|
- // Display the modal
|
|
2986
|
|
- modalElements.modal.style.display = "block";
|
|
2987
|
|
- }
|
|
2988
|
|
- });
|
|
2989
|
|
-});
|
|
2990
|
|
-jQuery(document).on('click', '.qc_wpbot_chat_link', function (e) {
|
|
2991
|
|
- console.log("Chat link clicked");
|
|
2992
|
|
- e.preventDefault();
|
|
2993
|
|
- jQuery("#wp-chatbot-ball").trigger("click");
|
|
2994
|
|
- jQuery("#wp-chatbot-chat-container").show();
|
|
2995
|
|
-});
|
|
2996
|
|
-document.addEventListener("click", function (e) {
|
|
2997
|
|
- const likeIcon = e.target.closest(".dashicons-thumbs-up");
|
|
2998
|
|
- const dislikeIcon = e.target.closest(".dashicons-thumbs-down");
|
|
2999
|
|
-
|
|
3000
|
|
- if (!likeIcon && !dislikeIcon) return; // only handle like/dislike clicks
|
|
3001
|
|
- e.preventDefault();
|
|
3002
|
|
-
|
|
3003
|
|
- const msgItem = e.target.closest(".wp-chatbot-msg");
|
|
3004
|
|
- const feedbackContainer = jQuery(msgItem).find(".qcld-like-dislike-icon");
|
|
3005
|
|
- const likeAnchor = jQuery(msgItem).find(".dashicons-thumbs-up").parent("a");
|
|
3006
|
|
- const dislikeAnchor = jQuery(msgItem).find(".dashicons-thumbs-down").parent("a");
|
|
3007
|
|
-
|
|
3008
|
|
- let feedbackType = "";
|
|
3009
|
|
- let isToggleOff = false;
|
|
3010
|
|
-
|
|
3011
|
|
- if (likeIcon) {
|
|
3012
|
|
- // If like is already active → toggle it off
|
|
3013
|
|
- if (likeAnchor.hasClass("liked")) {
|
|
3014
|
|
- likeAnchor.removeClass("liked");
|
|
3015
|
|
- likeIcon.classList.remove("liked");
|
|
3016
|
|
- isToggleOff = true;
|
|
3017
|
|
- } else {
|
|
3018
|
|
- // Activate like, deactivate dislike
|
|
3019
|
|
- likeAnchor.addClass("liked");
|
|
3020
|
|
- likeIcon.classList.add("liked");
|
|
3021
|
|
- dislikeAnchor.removeClass("disliked");
|
|
3022
|
|
- jQuery(msgItem).find(".dashicons-thumbs-down").removeClass("disliked");
|
|
3023
|
|
- feedbackType = "like";
|
|
3024
|
|
- }
|
|
3025
|
|
- } else if (dislikeIcon) {
|
|
3026
|
|
- // If dislike is already active → toggle it off
|
|
3027
|
|
- if (dislikeAnchor.hasClass("disliked")) {
|
|
3028
|
|
- dislikeAnchor.removeClass("disliked");
|
|
3029
|
|
- dislikeIcon.classList.remove("disliked");
|
|
3030
|
|
- isToggleOff = true;
|
|
3031
|
|
- } else {
|
|
3032
|
|
- // Activate dislike, deactivate like
|
|
3033
|
|
- dislikeAnchor.addClass("disliked");
|
|
3034
|
|
- dislikeIcon.classList.add("disliked");
|
|
3035
|
|
- likeAnchor.removeClass("liked");
|
|
3036
|
|
- jQuery(msgItem).find(".fa-thumbs-o-up").removeClass("liked");
|
|
3037
|
|
- feedbackType = "dislike";
|
|
3038
|
|
- }
|
|
3039
|
|
- }
|
|
3040
|
|
-
|
|
3041
|
|
- // 🔹 Only send feedback if toggled ON
|
|
3042
|
|
- if (!isToggleOff && feedbackType) {
|
|
3043
|
|
- let message = msgItem.querySelector(".wp-chatbot-paragraph").innerText.trim();
|
|
3044
|
|
- let meta =
|
|
3045
|
|
- "Source URL: " +
|
|
3046
|
|
- window.location.href +
|
|
3047
|
|
- " | User Agent: " +
|
|
3048
|
|
- navigator.userAgent;
|
|
3049
|
|
-
|
|
3050
|
|
- jQuery.post(
|
|
3051
|
|
- wp_chatbot_obj.ajax_url,
|
|
3052
|
|
- {
|
|
3053
|
|
- action: "wpbot_save_feedback",
|
|
3054
|
|
- user_id: globalwpw.settings.obj.current_user_id,
|
|
3055
|
|
- conversation_id: 3,
|
|
3056
|
|
- message: message,
|
|
3057
|
|
- feedback: feedbackType,
|
|
3058
|
|
- meta_info: meta,
|
|
3059
|
|
- },
|
|
3060
|
|
- function (response) {
|
|
3061
|
|
- if (response.success) {
|
|
3062
|
|
- console.log("Feedback saved:", feedbackType);
|
|
3063
|
|
- } else {
|
|
3064
|
|
- console.log("Failed to save feedback.");
|
|
3065
|
|
- }
|
|
3066
|
|
- }
|
|
3067
|
|
- );
|
|
3068
|
|
- } else {
|
|
3069
|
|
- console.log("Feedback toggled off, not saving.");
|
|
3070
|
|
- }
|
|
3071
|
|
-});
|
|
3072
|
|
-
|
|
3073
|
|
-// ---------------------------------------------------------------------------
|
|
3074
|
|
-// Streaming helpers
|
|
3075
|
|
-// ---------------------------------------------------------------------------
|
|
3076
|
|
-
|
|
3077
|
|
-function qcldInlineMarkdown(text) {
|
|
3078
|
|
- text = text.replace(/`([^`]+)`/g, '<code>$1</code>');
|
|
3079
|
|
- text = text.replace(/\*\*([^*]+)\*\*/g, '<strong>$1</strong>');
|
|
3080
|
|
- text = text.replace(/__([^_]+)__/g, '<strong>$1</strong>');
|
|
3081
|
|
- text = text.replace(/\*([^*\n]+)\*/g, '<em>$1</em>');
|
|
3082
|
|
- text = text.replace(/_([^_\n]+)_/g, '<em>$1</em>');
|
|
3083
|
|
- text = text.replace(/\[([^\]]+)\]\((https?:\/\/[^\s)]+)\)/g,
|
|
3084
|
|
- '<a href="$2" target="_blank" rel="noopener noreferrer">$1</a>');
|
|
3085
|
|
- return text;
|
|
3086
|
|
-}
|
|
3087
|
|
-
|
|
3088
|
|
-function qcldParseMarkdown(text) {
|
|
3089
|
|
- if (!text) { return ''; }
|
|
3090
|
|
- var lines = text.split('\n');
|
|
3091
|
|
- var html = '';
|
|
3092
|
|
- var inCode = false;
|
|
3093
|
|
- var inUL = false;
|
|
3094
|
|
- var inOL = false;
|
|
3095
|
|
- var codeLines = [];
|
|
3096
|
|
-
|
|
3097
|
|
- function closeList() {
|
|
3098
|
|
- if (inUL) { html += '</ul>'; inUL = false; }
|
|
3099
|
|
- if (inOL) { html += '</ol>'; inOL = false; }
|
|
3100
|
|
- }
|
|
3101
|
|
-
|
|
3102
|
|
- for (var i = 0; i < lines.length; i++) {
|
|
3103
|
|
- var line = lines[i];
|
|
3104
|
|
-
|
|
3105
|
|
- // Fenced code block toggle
|
|
3106
|
|
- if (/^```/.test(line)) {
|
|
3107
|
|
- if (inCode) {
|
|
3108
|
|
- html += '<pre><code>' + codeLines.join('\n').replace(/</g,'<').replace(/>/g,'>') + '</code></pre>';
|
|
3109
|
|
- codeLines = [];
|
|
3110
|
|
- inCode = false;
|
|
3111
|
|
- } else {
|
|
3112
|
|
- closeList();
|
|
3113
|
|
- inCode = true;
|
|
3114
|
|
- }
|
|
3115
|
|
- continue;
|
|
3116
|
|
- }
|
|
3117
|
|
- if (inCode) { codeLines.push(line); continue; }
|
|
3118
|
|
-
|
|
3119
|
|
- // Headings
|
|
3120
|
|
- var hm = line.match(/^(#{1,6})\s+(.*)/);
|
|
3121
|
|
- if (hm) {
|
|
3122
|
|
- closeList();
|
|
3123
|
|
- var lvl = hm[1].length;
|
|
3124
|
|
- html += '<h' + lvl + '>' + qcldInlineMarkdown(hm[2]) + '</h' + lvl + '>';
|
|
3125
|
|
- continue;
|
|
3126
|
|
- }
|
|
3127
|
|
-
|
|
3128
|
|
- // Horizontal rule
|
|
3129
|
|
- if (/^---+$/.test(line.trim())) {
|
|
3130
|
|
- closeList();
|
|
3131
|
|
- html += '<hr>';
|
|
3132
|
|
- continue;
|
|
3133
|
|
- }
|
|
3134
|
|
-
|
|
3135
|
|
- // Unordered list
|
|
3136
|
|
- var ulm = line.match(/^\s*[-*+]\s+(.*)/);
|
|
3137
|
|
- if (ulm) {
|
|
3138
|
|
- if (inOL) { html += '</ol>'; inOL = false; }
|
|
3139
|
|
- if (!inUL) { html += '<ul>'; inUL = true; }
|
|
3140
|
|
- html += '<li>' + qcldInlineMarkdown(ulm[1]) + '</li>';
|
|
3141
|
|
- continue;
|
|
3142
|
|
- }
|
|
3143
|
|
-
|
|
3144
|
|
- // Ordered list
|
|
3145
|
|
- var olm = line.match(/^\s*\d+\.\s+(.*)/);
|
|
3146
|
|
- if (olm) {
|
|
3147
|
|
- if (inUL) { html += '</ul>'; inUL = false; }
|
|
3148
|
|
- if (!inOL) { html += '<ol>'; inOL = true; }
|
|
3149
|
|
- html += '<li>' + qcldInlineMarkdown(olm[1]) + '</li>';
|
|
3150
|
|
- continue;
|
|
3151
|
|
- }
|
|
3152
|
|
-
|
|
3153
|
|
- // Blank line
|
|
3154
|
|
- if (line.trim() === '') {
|
|
3155
|
|
- closeList();
|
|
3156
|
|
- html += '<br>';
|
|
3157
|
|
- continue;
|
|
3158
|
|
- }
|
|
3159
|
|
-
|
|
3160
|
|
- // Normal line
|
|
3161
|
|
- closeList();
|
|
3162
|
|
- html += qcldInlineMarkdown(line) + '<br>';
|
|
3163
|
|
- }
|
|
3164
|
|
-
|
|
3165
|
|
- if (inCode) { html += '<pre><code>' + codeLines.join('\n') + '</code></pre>'; }
|
|
3166
|
|
- closeList();
|
|
3167
|
|
- return html;
|
|
3168
|
|
-}
|
|
3169
|
|
-
|
|
3170
|
|
-function qcldTypeCharacterByCharacter($target, text, speed, onComplete) {
|
|
3171
|
|
- speed = speed || 10;
|
|
3172
|
|
- onComplete = onComplete || function(){};
|
|
3173
|
|
-
|
|
3174
|
|
- var i = 0;
|
|
3175
|
|
- function type() {
|
|
3176
|
|
- if (i < text.length) {
|
|
3177
|
|
- $target.append(document.createTextNode(text.charAt(i)));
|
|
3178
|
|
- i++;
|
|
3179
|
|
- setTimeout(type, speed);
|
|
3180
|
|
- } else {
|
|
3181
|
|
- onComplete();
|
|
3182
|
|
- }
|
|
3183
|
|
- }
|
|
3184
|
|
- type();
|
|
3185
|
|
-}
|
|
3186
|
|
-
|
|
3187
|
|
-function qcldStreamOpenAI(dataObj) {
|
|
3188
|
|
- fetch(qcld_chatbot_obj.stream_endpoint, {
|
|
3189
|
|
- method: 'POST',
|
|
3190
|
|
- headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
|
|
3191
|
|
- body: new URLSearchParams(dataObj)
|
|
3192
|
|
- })
|
|
3193
|
|
- .then(function(response) {
|
|
3194
|
|
- if (!response.ok || !response.body) {
|
|
3195
|
|
- throw new Error('Network response was not OK or empty body');
|
|
3196
|
|
- }
|
|
3197
|
|
-
|
|
3198
|
|
- var reader = response.body.getReader();
|
|
3199
|
|
- var decoder = new TextDecoder('utf-8');
|
|
3200
|
|
- var buffer = '';
|
|
3201
|
|
- var queue = [];
|
|
3202
|
|
- var isTyping = false;
|
|
3203
|
|
- var streamEnded = false;
|
|
3204
|
|
- var msgBuffer = '';
|
|
3205
|
|
-
|
|
3206
|
|
- function finalize() {
|
|
3207
|
|
- // Replace raw typed text with markdown-formatted HTML
|
|
3208
|
|
- var $para = jQuery('.wp-chatbot-msg').last().find('.wp-chatbot-paragraph');
|
|
3209
|
|
- if (msgBuffer.trim()) {
|
|
3210
|
|
- $para.html(qcldParseMarkdown(msgBuffer));
|
|
3211
|
|
- }
|
|
3212
|
|
- jQuery(globalwpw.settings.messageContainer)
|
|
3213
|
|
- .find('.wp-chatbot-msg:last .qcld-like-dislike-icon')
|
|
3214
|
|
- .css('display', 'block');
|
|
3215
|
|
- if (globalwpw.settings.obj.qcld_disable_repited_startmenu != '1') {
|
|
3216
|
|
- wpwMsg.single_nobg(
|
|
3217
|
|
- '<span class="qcld-chatbot-wildcard qcld_back_to_start" data-wildcart="back">' +
|
|
3218
|
|
- wpwKits.randomMsg(globalwpw.settings.obj.back_to_start) +
|
|
3219
|
|
- '</span>'
|
|
3220
|
|
- );
|
|
3221
|
|
- }
|
|
3222
|
|
- setTimeout(function() {
|
|
3223
|
|
- jQuery(globalwpw.settings.botContainer)
|
|
3224
|
|
- .stop(true)
|
|
3225
|
|
- .animate({ scrollTop: jQuery(globalwpw.settings.botContainer)[0].scrollHeight }, 400);
|
|
3226
|
|
- }, 150);
|
|
3227
|
|
- wpwKits.scrollTo();
|
|
3228
|
|
- }
|
|
3229
|
|
-
|
|
3230
|
|
- function processQueue() {
|
|
3231
|
|
- if (isTyping || queue.length === 0) {
|
|
3232
|
|
- if (streamEnded && !isTyping && queue.length === 0) {
|
|
3233
|
|
- finalize();
|
|
3234
|
|
- }
|
|
3235
|
|
- return;
|
|
3236
|
|
- }
|
|
3237
|
|
-
|
|
3238
|
|
- isTyping = true;
|
|
3239
|
|
- var nextChunk = queue.shift();
|
|
3240
|
|
- msgBuffer += nextChunk;
|
|
3241
|
|
-
|
|
3242
|
|
- var $para = jQuery('.wp-chatbot-msg').last().find('.wp-chatbot-paragraph');
|
|
3243
|
|
- if ($para.length) {
|
|
3244
|
|
- $para.find('.wp-chatbot-comment-loader').remove();
|
|
3245
|
|
- var $span = jQuery('<span>');
|
|
3246
|
|
- $para.append($span);
|
|
3247
|
|
- qcldTypeCharacterByCharacter($span, nextChunk, 10, function() {
|
|
3248
|
|
- isTyping = false;
|
|
3249
|
|
- processQueue();
|
|
3250
|
|
- wpwKits.scrollTo();
|
|
3251
|
|
- });
|
|
3252
|
|
- } else {
|
|
3253
|
|
- isTyping = false;
|
|
3254
|
|
- processQueue();
|
|
3255
|
|
- }
|
|
3256
|
|
- }
|
|
3257
|
|
-
|
|
3258
|
|
- function read() {
|
|
3259
|
|
- reader.read().then(function(result) {
|
|
3260
|
|
- if (result.done) { return; }
|
|
3261
|
|
-
|
|
3262
|
|
- buffer += decoder.decode(result.value, { stream: true });
|
|
3263
|
|
- var lines = buffer.split('\n');
|
|
3264
|
|
- buffer = lines.pop();
|
|
3265
|
|
-
|
|
3266
|
|
- for (var i = 0; i < lines.length; i++) {
|
|
3267
|
|
- var line = lines[i].trim();
|
|
3268
|
|
- if (!line) { continue; }
|
|
3269
|
|
- if (line.indexOf('data:') === 0) {
|
|
3270
|
|
- var jsonStr = line.replace(/^data:\s*/, '');
|
|
3271
|
|
- if (jsonStr === '[DONE]') {
|
|
3272
|
|
- streamEnded = true;
|
|
3273
|
|
- if (!isTyping && queue.length === 0) { finalize(); }
|
|
3274
|
|
- return;
|
|
3275
|
|
- }
|
|
3276
|
|
- try {
|
|
3277
|
|
- var parsed = JSON.parse(jsonStr);
|
|
3278
|
|
- var content = '';
|
|
3279
|
|
- if (parsed.choices && parsed.choices[0] && parsed.choices[0].delta) {
|
|
3280
|
|
- content = parsed.choices[0].delta.content || '';
|
|
3281
|
|
- } else if (parsed.delta && parsed.delta.content) {
|
|
3282
|
|
- content = parsed.delta.content;
|
|
3283
|
|
- }
|
|
3284
|
|
- if (content) {
|
|
3285
|
|
- queue.push(content);
|
|
3286
|
|
- processQueue();
|
|
3287
|
|
- wpwKits.scrollTo();
|
|
3288
|
|
- }
|
|
3289
|
|
- } catch(e) {
|
|
3290
|
|
- console.warn('Streaming parse error:', e, jsonStr);
|
|
3291
|
|
- }
|
|
3292
|
|
- }
|
|
3293
|
|
- }
|
|
3294
|
|
- read();
|
|
3295
|
|
- }).catch(function(err) { console.error('Stream read error:', err); });
|
|
3296
|
|
- }
|
|
3297
|
|
-
|
|
3298
|
|
- read();
|
|
3299
|
|
- })
|
|
3300
|
|
- .catch(function(err) { console.error('Stream fetch error:', err); });
|
|
3301
|
|
-}
|
|
3302
|
|
-
|
|
3303
|
|
-})(jQuery);
|
|
1
|
+/* |
|
2
|
+ * Project: wpwBot jQuery Plugin |
|
3
|
+ * Description: wpwBot AI based Chatting functionality are handled . |
|
4
|
+ * Author: QuantumCloud |
|
5
|
+ * Version: 1.0 |
|
6
|
+ */ |
|
7
|
+var wpwKits; |
|
8
|
+(function($) { |
|
9
|
+ /* |
|
10
|
+ * Global variable as object will beused to handle |
|
11
|
+ * wpwbot chatting initialize, tree change transfer, |
|
12
|
+ * changing tree steps and cookies etc. |
|
13
|
+ */ |
|
14
|
+ var globalwpw={ |
|
15
|
+ initialize:0, |
|
16
|
+ settings:{}, |
|
17
|
+ wildCard:0, |
|
18
|
+ wildcards:'', |
|
19
|
+ wildcardsHelp:['start','support','reset', 'search', 'email'], |
|
20
|
+ productStep:'asking', |
|
21
|
+ orderStep:'welcome', |
|
22
|
+ supportStep:'welcome', |
|
23
|
+ formStep: 'welcome', |
|
24
|
+ formfieldid:'', |
|
25
|
+ formid:'', |
|
26
|
+ formentry:0, |
|
27
|
+ hasNameCookie:$.cookie("shopper"), |
|
28
|
+ shopperUserName:'', |
|
29
|
+ shopperEmail:'', |
|
30
|
+ shopperMessage:'', |
|
31
|
+ emptymsghandler:0, |
|
32
|
+ repeatQueryEmpty:'', |
|
33
|
+ wpwIsWorking:0, |
|
34
|
+ ai_step:0, |
|
35
|
+ df_status_lock:0, |
|
36
|
+ counter:0 |
|
37
|
+ }; |
|
38
|
+ /* |
|
39
|
+ * wpwbot welcome section coverd |
|
40
|
+ * greeting for new and already visited shopper |
|
41
|
+ * based the memory after asking thier name. |
|
42
|
+ */ |
|
43
|
+ var wpwWelcome={ |
|
44
|
+ greeting:function () { |
|
45
|
+ //generating unique session id. |
|
46
|
+ if(!localStorage.getItem('botsessionid')){ |
|
47
|
+ var number = Math.random() // 0.9394456857981651 |
|
48
|
+ number.toString(36); // '0.xtis06h6' |
|
49
|
+ var id = number.toString(36).substr(2); // 'xtis06h6' |
|
50
|
+ localStorage.setItem('botsessionid', id); |
|
51
|
+ } |
|
52
|
+ // console.log(globalwpw.settings.obj.skip_wp_greetings=='1') |
|
53
|
+ if((globalwpw.settings.obj.skip_wp_greetings=='1') || (globalwpw.settings.obj.skip_greetings_and_menu =='1') ){ |
|
54
|
+ }else{ |
|
55
|
+ //Very begining greeting. |
|
56
|
+ if(globalwpw.settings.obj.re_target_handler==0){ |
|
57
|
+ var botJoinMsg="<strong>"+wpwMsg.oncommand_filter(globalwpw.settings.obj.agent)+" </strong> "+wpwKits.randomMsg(globalwpw.settings.obj.agent_join); |
|
58
|
+ wpwMsg.single(botJoinMsg); |
|
59
|
+ } |
|
60
|
+ //Showing greeting for name in cookie or fresh shopper. |
|
61
|
+ setTimeout(function(){ |
|
62
|
+ var firstMsg=wpwKits.randomMsg(globalwpw.settings.obj.hi_there)+' '+wpwKits.randomMsg(globalwpw.settings.obj.welcome)+" <strong>"+globalwpw.settings.obj.host+"!</strong> "; |
|
63
|
+ var secondMsg=wpwKits.randomMsg(globalwpw.settings.obj.asking_name); |
|
64
|
+ wpwMsg.double(firstMsg,secondMsg); |
|
65
|
+ }, globalwpw.settings.preLoadingTime*2); |
|
66
|
+ } |
|
67
|
+ |
|
68
|
+ var serviceOffer=wpwKits.randomMsg(globalwpw.settings.obj.wildcard_msg); |
|
69
|
+ if(globalwpw.settings.obj.skip_greetings_and_menu != 0){ |
|
70
|
+ wpwMsg.single(serviceOffer); |
|
71
|
+ } |
|
72
|
+ if( ( globalwpw.settings.obj.show_menu_after_greetings!=0 ) && ( globalwpw.wildcards !='' ) ){ |
|
73
|
+ wpwMsg.double_nobg(serviceOffer, globalwpw.wildcards); |
|
74
|
+ } if( ( globalwpw.settings.obj.skip_wp_greetings !=0 ) && ( globalwpw.wildcards !='' ) ){ |
|
75
|
+ wpwMsg.double_nobg(serviceOffer, globalwpw.wildcards); |
|
76
|
+ } else{ |
|
77
|
+ //wpwMsg.single(serviceOffer); |
|
78
|
+ } |
|
79
|
+ } |
|
80
|
+ }; |
|
81
|
+ function qcldPushAiContext(role, content) { |
|
82
|
+ if (typeof globalwpw === 'undefined') return; |
|
83
|
+ if (typeof globalwpw.aiContext === 'undefined') { |
|
84
|
+ globalwpw.aiContext = []; |
|
85
|
+ } |
|
86
|
+ if (!content) return; |
|
87
|
+ |
|
88
|
+ var cleanContent = content; |
|
89
|
+ if (role === 'assistant') { |
|
90
|
+ cleanContent = cleanContent.replace(/<[^>]*>?/gm, '').trim(); |
|
91
|
+ } else if (role === 'user') { |
|
92
|
+ var lower = content.toLowerCase().trim(); |
|
93
|
+ var titles = (typeof qcld_chatbot_obj !== 'undefined' && qcld_chatbot_obj.ai_form_titles) ? qcld_chatbot_obj.ai_form_titles : ((typeof wp_chatbot_obj !== 'undefined' && wp_chatbot_obj.ai_form_titles) ? wp_chatbot_obj.ai_form_titles : []); |
|
94
|
+ if (titles && titles.length) { |
|
95
|
+ for (var t = 0; t < titles.length; t++) { |
|
96
|
+ var title = titles[t]; |
|
97
|
+ if (lower === title || lower.indexOf(title) !== -1 || title.indexOf(lower) !== -1) { |
|
98
|
+ globalwpw.active_ai_action = title; |
|
99
|
+ globalwpw.qcld_ai_form_persisted_state = true; |
|
100
|
+ break; |
|
101
|
+ } |
|
102
|
+ } |
|
103
|
+ } |
|
104
|
+ } |
|
105
|
+ |
|
106
|
+ globalwpw.aiContext.push({role: role, content: cleanContent}); |
|
107
|
+ if (globalwpw.aiContext.length > 30) { |
|
108
|
+ globalwpw.aiContext.shift(); |
|
109
|
+ } |
|
110
|
+ } |
|
111
|
+ |
|
112
|
+ function qcldIsAiFormInProgress() { |
|
113
|
+ if (typeof globalwpw !== 'undefined' && (globalwpw.active_ai_action || globalwpw.qcld_ai_form_persisted_state)) { |
|
114
|
+ return true; |
|
115
|
+ } |
|
116
|
+ var titles = (typeof qcld_chatbot_obj !== 'undefined' && qcld_chatbot_obj.ai_form_titles) ? qcld_chatbot_obj.ai_form_titles : ((typeof wp_chatbot_obj !== 'undefined' && wp_chatbot_obj.ai_form_titles) ? wp_chatbot_obj.ai_form_titles : []); |
|
117
|
+ if (!titles || !titles.length || typeof globalwpw === 'undefined' || !globalwpw.aiContext) { |
|
118
|
+ return false; |
|
119
|
+ } |
|
120
|
+ |
|
121
|
+ var hasFormTrigger = false; |
|
122
|
+ for (var i = 0; i < globalwpw.aiContext.length; i++) { |
|
123
|
+ var msg = globalwpw.aiContext[i]; |
|
124
|
+ if (msg.role === 'user') { |
|
125
|
+ var content = (msg.content || '').toLowerCase().trim(); |
|
126
|
+ for (var t = 0; t < titles.length; t++) { |
|
127
|
+ var title = titles[t]; |
|
128
|
+ if (content === title || content.indexOf(title) !== -1 || title.indexOf(content) !== -1) { |
|
129
|
+ hasFormTrigger = true; |
|
130
|
+ globalwpw.active_ai_action = title; |
|
131
|
+ } |
|
132
|
+ } |
|
133
|
+ } |
|
134
|
+ if (msg.role === 'assistant') { |
|
135
|
+ var assistantContent = (msg.content || '').toLowerCase(); |
|
136
|
+ if (msg.content && (msg.content.indexOf('__AI_FORM_DATA__') !== -1 || msg.content.indexOf('ai-form-summary-card') !== -1 || assistantContent.indexOf('thank you for providing the information') !== -1 || assistantContent.indexOf('successfully submitted') !== -1)) { |
|
137
|
+ hasFormTrigger = false; |
|
138
|
+ globalwpw.active_ai_action = ''; |
|
139
|
+ } |
|
140
|
+ } |
|
141
|
+ } |
|
142
|
+ |
|
143
|
+ return hasFormTrigger || !!(globalwpw.active_ai_action); |
|
144
|
+ } |
|
145
|
+ //Append the message to the message container based on the requirement. |
|
146
|
+ var wpwMsg={ |
|
147
|
+ oncommand_filter:function(msg){ |
|
148
|
+ var str = msg; |
|
149
|
+ if(typeof(str) === 'string'){ |
|
150
|
+ str = str.replace(/on[a-zA-Z]+\s*=/g, ""); |
|
151
|
+ str = str.replace(/__AI_FORM_IN_PROGRESS__/g, ""); |
|
152
|
+ |
|
153
|
+ // Matches __AI_FORM_DATA__{...}__AI_FORM_DATA_END__ or html-wrapped variations (e.g. from Markdown Parsedown) |
|
154
|
+ var formRegex = /(?:<[^>]+>)*\s*(?:__|<strong>|<b>)?AI_FORM_DATA(?:__|<\/strong>|<\/b>)?[\s\S]*?(?:__|<strong>|<b>)?AI_FORM_DATA_END(?:__|<\/strong>|<\/b>)?\s*(?:<\/[^>]+>)*/gi; |
|
155
|
+ |
|
156
|
+ if (formRegex.test(str)) { |
|
157
|
+ str = str.replace(formRegex, function(match) { |
|
158
|
+ try { |
|
159
|
+ var jsonMatch = match.match(/\{[\s\S]*\}/); |
|
160
|
+ if (jsonMatch) { |
|
161
|
+ var jsonStr = jsonMatch[0]; |
|
162
|
+ var data = JSON.parse(jsonStr.trim()); |
|
163
|
+ |
|
164
|
+ // Save form entry via AJAX |
|
165
|
+ var postData = { |
|
166
|
+ 'action': 'qcld_save_ai_form', |
|
167
|
+ 'data': jsonStr, |
|
168
|
+ 'nonce': (typeof qcld_chatbot_obj !== 'undefined' ? qcld_chatbot_obj.nonce : '') |
|
169
|
+ }; |
|
170
|
+ var ajaxUrl = (typeof qcld_chatbot_obj !== 'undefined' && qcld_chatbot_obj.ajax_url) ? qcld_chatbot_obj.ajax_url : (typeof wpbot_ajax !== 'undefined' ? wpbot_ajax.ajax_url : (typeof ajaxurl !== 'undefined' ? ajaxurl : '')); |
|
171
|
+ if (ajaxUrl) { |
|
172
|
+ jQuery.post(ajaxUrl, postData); |
|
173
|
+ } |
|
174
|
+ |
|
175
|
+ if (typeof globalwpw !== 'undefined') { |
|
176
|
+ globalwpw.aiContext = []; |
|
177
|
+ globalwpw.active_ai_action = ''; |
|
178
|
+ globalwpw.qcld_ai_form_persisted_state = false; |
|
179
|
+ } |
|
180
|
+ |
|
181
|
+ var html = '<div class="ai-form-summary-card" style="background: #f4f6f9; border-left: 4px solid #0073aa; padding: 12px 14px; margin: 10px 0; border-radius: 4px; font-size: 13px; line-height: 1.5; color: #333;">'; |
|
182
|
+ if (data.form_title) { |
|
183
|
+ html += '<div style="font-weight: 600; color: #0073aa; margin-bottom: 8px; text-transform: capitalize; font-size: 14px;">' + data.form_title + '</div>'; |
|
184
|
+ } |
|
185
|
+ if (data.data && typeof data.data === 'object') { |
|
186
|
+ html += '<table style="width: 100%; border-collapse: collapse; margin-top: 4px;">'; |
|
187
|
+ for (var key in data.data) { |
|
188
|
+ if (data.data.hasOwnProperty(key)) { |
|
189
|
+ var cleanKey = key.replace(/[-_]/g, ' '); |
|
190
|
+ html += '<tr><td style="padding: 3px 6px 3px 0; color: #555; font-weight: 600; width: 42%; vertical-align: top;">' + cleanKey + ':</td><td style="padding: 3px 0; color: #222; vertical-align: top;">' + data.data[key] + '</td></tr>'; |
|
191
|
+ } |
|
192
|
+ } |
|
193
|
+ html += '</table>'; |
|
194
|
+ } |
|
195
|
+ html += '</div>'; |
|
196
|
+ return html; |
|
197
|
+ } |
|
198
|
+ } catch(e) { |
|
199
|
+ console.error('AI Form parse error:', e); |
|
200
|
+ } |
|
201
|
+ return ''; |
|
202
|
+ }); |
|
203
|
+ } |
|
204
|
+ } |
|
205
|
+ return str; |
|
206
|
+ }, |
|
207
|
+ open_new_tab: function(msg){ |
|
208
|
+ if(wp_chatbot_obj.open_links_newtab == '1'){ |
|
209
|
+ var temp = document.createElement('div'); |
|
210
|
+ temp.innerHTML = msg; |
|
211
|
+ let links = temp.querySelectorAll('a'); |
|
212
|
+ links.forEach(link => { |
|
213
|
+ link.setAttribute('target', '_blank'); |
|
214
|
+ }); |
|
215
|
+ let temps = temp.innerHTML; |
|
216
|
+ return temps; |
|
217
|
+ }else{ |
|
218
|
+ return msg; |
|
219
|
+ } |
|
220
|
+ }, |
|
221
|
+ single_openai:function (msg) { |
|
222
|
+ msg = wpwMsg.open_new_tab(msg); |
|
223
|
+ globalwpw.wpwIsWorking=1; |
|
224
|
+ if($(globalwpw.settings.messageLastChild+' .wp-chatbot-comment-loader').length==0){ |
|
225
|
+ $(globalwpw.settings.messageContainer).append(wpwKits.botPreloader()); |
|
226
|
+ } |
|
227
|
+ |
|
228
|
+ //Scroll to the last message |
|
229
|
+ wpwKits.scrollTo(); |
|
230
|
+ setTimeout(function(){ |
|
231
|
+ $(globalwpw.settings.messageLastChild+' .wp-chatbot-paragraph').text( msg ); |
|
232
|
+ //If has youtube link then show video |
|
233
|
+ wpwKits.videohandler(); |
|
234
|
+ //scroll to the last message |
|
235
|
+ wpwKits.scrollTo(); |
|
236
|
+ //Enable the editor |
|
237
|
+ wpwKits.enableEditor(wpwKits.randomMsg(globalwpw.settings.obj.send_a_msg)); |
|
238
|
+ //keeping in history |
|
239
|
+ wpwKits.wpwHistorySave(); |
|
240
|
+ |
|
241
|
+ }, globalwpw.settings.preLoadingTime); |
|
242
|
+ }, |
|
243
|
+ single:function (msg) { |
|
244
|
+ msg = wpwMsg.open_new_tab(msg); |
|
245
|
+ globalwpw.wpwIsWorking=1; |
|
246
|
+ if($(globalwpw.settings.messageLastChild+' .wp-chatbot-comment-loader').length==0){ |
|
247
|
+ $(globalwpw.settings.messageContainer).append(wpwKits.botPreloader()); |
|
248
|
+ } |
|
249
|
+ //Scroll to the last message |
|
250
|
+ wpwKits.scrollTo(); |
|
251
|
+ oncommand_filter = wpwMsg.oncommand_filter(msg); |
|
252
|
+ |
|
253
|
+ setTimeout(function(){ |
|
254
|
+ $(globalwpw.settings.messageLastChild+' .wp-chatbot-paragraph').html( '<div class="wp-chatbot-textanimation">' + oncommand_filter + '</div>'); |
|
255
|
+ //If has youtube link then show video |
|
256
|
+ wpwKits.videohandler(); |
|
257
|
+ //scroll to the last message |
|
258
|
+ wpwKits.scrollTo(); |
|
259
|
+ //Enable the editor |
|
260
|
+ wpwKits.enableEditor(wpwKits.randomMsg(globalwpw.settings.obj.send_a_msg)); |
|
261
|
+ //keeping in history |
|
262
|
+ wpwKits.wpwHistorySave(); |
|
263
|
+ }, globalwpw.settings.preLoadingTime); |
|
264
|
+ }, |
|
265
|
+ single_nobg:function (msg) { |
|
266
|
+ msg = wpwMsg.open_new_tab(msg); |
|
267
|
+ globalwpw.wpwIsWorking=1; |
|
268
|
+ if($(globalwpw.settings.messageLastChild+' .wp-chatbot-comment-loader').length==0){ |
|
269
|
+ $(globalwpw.settings.messageContainer).append(wpwKits.botPreloader()); |
|
270
|
+ } |
|
271
|
+ //Scroll to the last message |
|
272
|
+ oncommand_filter = wpwMsg.oncommand_filter(msg); |
|
273
|
+ wpwKits.scrollTo(); |
|
274
|
+ setTimeout(function(){ |
|
275
|
+ $(globalwpw.settings.messageLastChild+' .wp-chatbot-paragraph').parent().addClass('wp-chatbot-msg-flat').html( '<div class="wp-chatbot-textanimation">' + oncommand_filter + '</div>'); |
|
276
|
+ //scroll to the last message |
|
277
|
+ wpwKits.scrollTo(); |
|
278
|
+ //Enable the editor |
|
279
|
+ wpwKits.enableEditor(wpwKits.randomMsg(globalwpw.settings.obj.send_a_msg)); |
|
280
|
+ //Keeping the chat history in localStorage |
|
281
|
+ wpwKits.wpwHistorySave(); |
|
282
|
+ // disabled editor |
|
283
|
+ // wpwKits.disableEditor('Please choose an option.'); |
|
284
|
+ }, globalwpw.settings.preLoadingTime); |
|
285
|
+ }, |
|
286
|
+ double:function (fristMsg,secondMsg) { |
|
287
|
+ fristMsg = wpwMsg.open_new_tab(fristMsg); |
|
288
|
+ secondMsg = wpwMsg.open_new_tab(secondMsg); |
|
289
|
+ globalwpw.wpwIsWorking=1; |
|
290
|
+ if($(globalwpw.settings.messageLastChild+' .wp-chatbot-comment-loader').length==0){ |
|
291
|
+ $(globalwpw.settings.messageContainer).append(wpwKits.botPreloader()); |
|
292
|
+ } |
|
293
|
+ oncommand_fristMsg_filter = wpwMsg.oncommand_filter(fristMsg); |
|
294
|
+ oncommand_secondMsg_filter = wpwMsg.oncommand_filter(secondMsg); |
|
295
|
+ //Scroll to the last message |
|
296
|
+ wpwKits.scrollTo(); |
|
297
|
+ setTimeout(function(){ |
|
298
|
+ $(globalwpw.settings.messageLastChild+' .wp-chatbot-paragraph').html('<div class="wp-chatbot-textanimation">' + oncommand_fristMsg_filter + '</div>'); |
|
299
|
+ //Second Message with interval |
|
300
|
+ if($(globalwpw.settings.messageLastChild+' .wp-chatbot-comment-loader').length==0){ |
|
301
|
+ $(globalwpw.settings.messageContainer).append(wpwKits.botPreloader()); |
|
302
|
+ } |
|
303
|
+ //Scroll to the last message |
|
304
|
+ wpwKits.scrollTo(); |
|
305
|
+ setTimeout(function(){ |
|
306
|
+ $(globalwpw.settings.messageLastChild+' .wp-chatbot-paragraph').html('<div class="wp-chatbot-textanimation">' + oncommand_secondMsg_filter + '</div>'); |
|
307
|
+ //Scroll to the last message |
|
308
|
+ wpwKits.scrollTo(); |
|
309
|
+ //Enable the editor |
|
310
|
+ wpwKits.enableEditor(wpwKits.randomMsg(globalwpw.settings.obj.send_a_msg)); |
|
311
|
+ //keeping in history |
|
312
|
+ wpwKits.wpwHistorySave(); |
|
313
|
+ }, globalwpw.settings.preLoadingTime*2); |
|
314
|
+ }, globalwpw.settings.preLoadingTime); |
|
315
|
+ }, |
|
316
|
+ double_nobg:function (fristMsg,secondMsg) { |
|
317
|
+ fristMsg = wpwMsg.open_new_tab(fristMsg); |
|
318
|
+ secondMsg = wpwMsg.open_new_tab(secondMsg); |
|
319
|
+ oncommand_fristMsg_filter = wpwMsg.oncommand_filter(fristMsg); |
|
320
|
+ oncommand_secondMsg_filter = wpwMsg.oncommand_filter(secondMsg); |
|
321
|
+ |
|
322
|
+ globalwpw.wpwIsWorking=1; |
|
323
|
+ if($(globalwpw.settings.messageLastChild+' .wp-chatbot-comment-loader').length==0){ |
|
324
|
+ $(globalwpw.settings.messageContainer).append(wpwKits.botPreloader()); |
|
325
|
+ } |
|
326
|
+ //Scroll to the last message |
|
327
|
+ wpwKits.scrollTo(); |
|
328
|
+ setTimeout(function(){ |
|
329
|
+ $(globalwpw.settings.messageLastChild+' .wp-chatbot-paragraph').html('<div class="wp-chatbot-textanimation">' + oncommand_fristMsg_filter + '</div>'); |
|
330
|
+ //Second Message with interval |
|
331
|
+ if($(globalwpw.settings.messageLastChild+' .wp-chatbot-comment-loader').length==0){ |
|
332
|
+ $(globalwpw.settings.messageContainer).append(wpwKits.botPreloader()); |
|
333
|
+ } |
|
334
|
+ //Scroll to the last message |
|
335
|
+ wpwKits.scrollTo(); |
|
336
|
+ setTimeout(function(){ |
|
337
|
+ if( globalwpw.wildCard>0 && ((globalwpw.settings.obj.disable_back_to_start != '1' && globalwpw.settings.obj.skip_greetings_and_menu != 1)) ){ |
|
338
|
+ $(globalwpw.settings.messageLastChild+' .wp-chatbot-paragraph').parent().addClass('wp-chatbot-msg-flat').html(oncommand_secondMsg_filter).append('<span class="qcld-chatbot-wildcard" data-wildcart="back">' + wpwKits.randomMsg(globalwpw.settings.obj.back_to_start) + '</span>'); |
|
339
|
+ }else{ |
|
340
|
+ $(globalwpw.settings.messageLastChild+' .wp-chatbot-paragraph').parent().addClass('wp-chatbot-msg-flat').html('<div class="wp-chatbot-textanimation">' + oncommand_secondMsg_filter + '</div>'); |
|
341
|
+ } |
|
342
|
+ //scroll to the last message |
|
343
|
+ wpwKits.scrollTo(); |
|
344
|
+ //Enable the editor |
|
345
|
+ if(globalwpw.wildCard==1 && globalwpw.supportStep=='welcome'){ |
|
346
|
+ //wpwKits.disableEditor('Support'); |
|
347
|
+ wpwKits.enableEditor(wpwKits.randomMsg(globalwpw.settings.obj.send_a_msg)); |
|
348
|
+ }else{ |
|
349
|
+ wpwKits.enableEditor(wpwKits.randomMsg(globalwpw.settings.obj.send_a_msg)); |
|
350
|
+ } |
|
351
|
+ //keeping in history |
|
352
|
+ wpwKits.wpwHistorySave(); |
|
353
|
+ // disabled editor |
|
354
|
+ // wpwKits.disableEditor('Please choose an option.'); |
|
355
|
+ }, globalwpw.settings.preLoadingTime*2); |
|
356
|
+ }, globalwpw.settings.preLoadingTime); |
|
357
|
+ }, |
|
358
|
+ triple_nobg:function (fristMsg,secondMsg,thirdMsg) { |
|
359
|
+ fristMsg = wpwMsg.open_new_tab(fristMsg); |
|
360
|
+ secondMsg = wpwMsg.open_new_tab(secondMsg); |
|
361
|
+ oncommand_fristMsg_filter = wpwMsg.oncommand_filter(fristMsg); |
|
362
|
+ oncommand_secondMsg_filter = wpwMsg.oncommand_filter(secondMsg); |
|
363
|
+ globalwpw.wpwIsWorking=1; |
|
364
|
+ $(globalwpw.settings.messageContainer).append(wpwKits.botPreloader()); |
|
365
|
+ //Scroll to the last message |
|
366
|
+ wpwKits.scrollTo(); |
|
367
|
+ setTimeout(function(){ |
|
368
|
+ $(globalwpw.settings.messageLastChild+' .wp-chatbot-paragraph').html('<div class="wp-chatbot-textanimation">' + oncommand_fristMsg_filter + '</div>'); |
|
369
|
+ wpwKits.videohandler(); |
|
370
|
+ //Second Message with interval |
|
371
|
+ if($(globalwpw.settings.messageLastChild+' .wp-chatbot-comment-loader').length==0){ |
|
372
|
+ $(globalwpw.settings.messageContainer).append(wpwKits.botPreloader()); |
|
373
|
+ } |
|
374
|
+ //Scroll to the last message |
|
375
|
+ wpwKits.scrollTo(); |
|
376
|
+ setTimeout(function(){ |
|
377
|
+ $(globalwpw.settings.messageLastChild+' .wp-chatbot-paragraph').html('<div class="wp-chatbot-textanimation">' + oncommand_secondMsg_filter + '</div>'); |
|
378
|
+ wpwKits.videohandler(); |
|
379
|
+ if($(globalwpw.settings.messageLastChild+' .wp-chatbot-comment-loader').length==0){ |
|
380
|
+ $(globalwpw.settings.messageContainer).append(wpwKits.botPreloader()); |
|
381
|
+ } |
|
382
|
+ //Scroll to the last message |
|
383
|
+ wpwKits.scrollTo(); |
|
384
|
+ setTimeout(function(){ |
|
385
|
+ if(globalwpw.wildCard>0 && (globalwpw.settings.obj.disable_back_to_start != '1' && globalwpw.settings.obj.skip_greetings_and_menu != 1)){ |
|
386
|
+ $(globalwpw.settings.messageLastChild+' .wp-chatbot-paragraph').parent().addClass('wp-chatbot-msg-flat').html(thirdMsg).append('<span class="qcld-chatbot-wildcard qcld_back_to_start" data-wildcart="back">' + wpwKits.randomMsg(globalwpw.settings.obj.back_to_start) + '</span>'); |
|
387
|
+ }else{ |
|
388
|
+ $(globalwpw.settings.messageLastChild+' .wp-chatbot-paragraph').parent().addClass('wp-chatbot-msg-flat').html('<div class="wp-chatbot-textanimation">' + thirdMsg + '</div>'); |
|
389
|
+ } |
|
390
|
+ //scroll to the last message |
|
391
|
+ wpwKits.scrollTo(); |
|
392
|
+ wpwKits.videohandler(); |
|
393
|
+ //Enable the editor |
|
394
|
+ if(globalwpw.wildCard==1 && globalwpw.supportStep=='welcome'){ |
|
395
|
+ //wpwKits.disableEditor('Support'); |
|
396
|
+ }else{ |
|
397
|
+ wpwKits.enableEditor(wpwKits.randomMsg(globalwpw.settings.obj.send_a_msg)); |
|
398
|
+ } |
|
399
|
+ //keeping in history |
|
400
|
+ wpwKits.wpwHistorySave(); |
|
401
|
+ // disabled editor |
|
402
|
+ // wpwKits.disableEditor('Please choose an option.'); |
|
403
|
+ }, globalwpw.settings.preLoadingTime); |
|
404
|
+ }, globalwpw.settings.preLoadingTime); |
|
405
|
+ }, globalwpw.settings.preLoadingTime); |
|
406
|
+ }, |
|
407
|
+ shopper:function (shopperMsg) { |
|
408
|
+ $(globalwpw.settings.messageContainer).append(wpwKits.shopperMsgDom(shopperMsg)); |
|
409
|
+ //scroll to the last message |
|
410
|
+ wpwKits.scrollTo(); |
|
411
|
+ //keeping in history |
|
412
|
+ wpwKits.wpwHistorySave(); |
|
413
|
+ }, |
|
414
|
+ shopper_choice:function (shopperChoice) { |
|
415
|
+ $(globalwpw.settings.messageLastChild).fadeOut(globalwpw.settings.preLoadingTime); |
|
416
|
+ $(globalwpw.settings.messageContainer).append(wpwKits.shopperMsgDom(shopperChoice)); |
|
417
|
+ //scroll to the last message |
|
418
|
+ wpwKits.scrollTo(); |
|
419
|
+ //keeping in history |
|
420
|
+ wpwKits.wpwHistorySave(); |
|
421
|
+ } |
|
422
|
+ }; |
|
423
|
+ //Every tiny tools are implemented in wpwKits as object literal. |
|
424
|
+ wpwKits={ |
|
425
|
+ enableEditor:function(placeHolder){ |
|
426
|
+ if(globalwpw.settings.editor_handler==0){ |
|
427
|
+ if($(window).width()>380){ |
|
428
|
+ $("#wp-chatbot-editor").attr('disabled',false).focus(); |
|
429
|
+ }else{ |
|
430
|
+ $("#wp-chatbot-editor").attr('disabled',false) |
|
431
|
+ } |
|
432
|
+ $("#wp-chatbot-editor").attr('placeholder',placeHolder); |
|
433
|
+ $("#wp-chatbot-send-message").attr('disabled',false); |
|
434
|
+ } |
|
435
|
+ }, |
|
436
|
+ disableEditor:function (placeHolder) { |
|
437
|
+ if(globalwpw.settings.editor_handler==0){ |
|
438
|
+ $("#wp-chatbot-editor").attr('placeholder',placeHolder); |
|
439
|
+ $("#wp-chatbot-editor").attr('disabled',true); |
|
440
|
+ $("#wp-chatbot-send-message").attr('disabled',true); |
|
441
|
+ } |
|
442
|
+ //Remove extra pre loader. |
|
443
|
+ if($('.wp-chatbot-messages-container').find('.wp-chatbot-comment-loader').length>0){ |
|
444
|
+ $('.wp-chatbot-messages-container').find('.wp-chatbot-comment-loader').parent().parent().hide(); |
|
445
|
+ } |
|
446
|
+ }, |
|
447
|
+ htmlEntities:function(str) { |
|
448
|
+ return String(str).replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>').replace(/"/g, '"'); |
|
449
|
+ }, |
|
450
|
+ wpwHistorySave:function () { |
|
451
|
+ globalwpw.wpwIsWorking=0; |
|
452
|
+ var wpwHistory= $(globalwpw.settings.messageWrapper).html(); |
|
453
|
+ localStorage.setItem("wpwHitory", wpwHistory); |
|
454
|
+ if(localStorage.getItem('botsessionid')){ |
|
455
|
+ if(!localStorage.getItem('shopperemail')){ |
|
456
|
+ var useremail = ''; |
|
457
|
+ }else{ |
|
458
|
+ var useremail = localStorage.getItem('shopperemail'); |
|
459
|
+ } |
|
460
|
+ if(globalwpw.hasNameCookie){ |
|
461
|
+ var shopper=globalwpw.hasNameCookie; |
|
462
|
+ } else{ |
|
463
|
+ var shopper=globalwpw.settings.obj.shopper_demo_name; |
|
464
|
+ } |
|
465
|
+ if(localStorage.getItem('shopperphone')){ |
|
466
|
+ var shopperphone = localStorage.getItem('shopperphone'); |
|
467
|
+ }else{ |
|
468
|
+ var shopperphone = ''; |
|
469
|
+ } |
|
470
|
+ var data = {'action':'qcld_wb_chatbot_conversation_save','session_id': localStorage.getItem('botsessionid'),'name':shopper,'email':useremail, 'phone':shopperphone, 'conversation':wpwKits.htmlEntities(wpwHistory), 'security':globalwpw.settings.obj.ajax_nonce, 'user_id': globalwpw.settings.obj.current_user_id}; |
|
471
|
+ if( globalwpw.settings.obj.is_chat_session_active == 1 ){ |
|
472
|
+ wpwKits.ajax(data).done(function (response) { |
|
473
|
+ //console.log(response); |
|
474
|
+ }) |
|
475
|
+ } |
|
476
|
+ } |
|
477
|
+ //},globalwpw.settings.wildcardsShowTime); |
|
478
|
+ }, |
|
479
|
+ decodehtml: function(str) { |
|
480
|
+ var doc = new DOMParser().parseFromString(str, "text/html"); |
|
481
|
+ |
|
482
|
+ return doc.body.firstChild.data || ""; |
|
483
|
+ |
|
484
|
+ }, |
|
485
|
+ randomMsg:function(arrMsg){ |
|
486
|
+ var index=Math.floor(Math.random() * arrMsg.length); |
|
487
|
+ var msg = arrMsg[index]; |
|
488
|
+ if (typeof msg === 'string' && msg.indexOf('%%username%%') !== -1) { |
|
489
|
+ var shopperName = localStorage.getItem('shopper') || (globalwpw.settings.obj.display_name || ''); |
|
490
|
+ msg = msg.replace(/%%username%%/g, shopperName); |
|
491
|
+ } |
|
492
|
+ return msg; |
|
493
|
+ }, |
|
494
|
+ ajax:function (data) { |
|
495
|
+ return jQuery.post(globalwpw.settings.obj.ajax_url, data); |
|
496
|
+ }, |
|
497
|
+ dailogAIOAction:function(text){ |
|
498
|
+ if(globalwpw.settings.obj.df_api_version=='v1'){ |
|
499
|
+ return jQuery.ajax({ |
|
500
|
+ type : "POST", |
|
501
|
+ url :"https://api.dialogflow.com/v1/query?v=20170712", |
|
502
|
+ contentType : "application/json; charset=utf-8", |
|
503
|
+ dataType : "json", |
|
504
|
+ headers : { |
|
505
|
+ "Authorization" : "Bearer "+globalwpw.settings.obj.ai_df_token |
|
506
|
+ }, |
|
507
|
+ data: JSON.stringify( { |
|
508
|
+ query: text, |
|
509
|
+ lang : globalwpw.settings.obj.df_agent_lan, |
|
510
|
+ sessionId: localStorage.getItem('botsessionid')?localStorage.getItem('botsessionid'):'wpwBot_df_2018071' |
|
511
|
+ } ) |
|
512
|
+ }); |
|
513
|
+ }else{ |
|
514
|
+ |
|
515
|
+ return jQuery.post(globalwpw.settings.obj.ajax_url, { |
|
516
|
+ 'action': 'qcld_wp_df_api_call', |
|
517
|
+ 'dfquery': text, |
|
518
|
+ 'nonce': globalwpw.settings.obj.ajax_nonce, |
|
519
|
+ 'sessionid': localStorage.getItem('botsessionid')?localStorage.getItem('botsessionid'):'wpwBot_df_2018071' |
|
520
|
+ }); |
|
521
|
+ } |
|
522
|
+ }, |
|
523
|
+ responseIsOk(response){ |
|
524
|
+ if(globalwpw.settings.obj.df_api_version=='v1'){ |
|
525
|
+ if(response.status.code==200 || response.status.code==206){ |
|
526
|
+ return true; |
|
527
|
+ }else{ |
|
528
|
+ return false; |
|
529
|
+ } |
|
530
|
+ }else{ |
|
531
|
+ if(typeof response.responseId !== "undefined"){ |
|
532
|
+ return true; |
|
533
|
+ }else{ |
|
534
|
+ return false; |
|
535
|
+ } |
|
536
|
+ } |
|
537
|
+ }, |
|
538
|
+ getIntentName(response){ |
|
539
|
+ if(globalwpw.settings.obj.df_api_version=='v1'){ |
|
540
|
+ return response.result.metadata.intentName; |
|
541
|
+ }else{ |
|
542
|
+ return response.queryResult.intent.displayName; |
|
543
|
+ } |
|
544
|
+ }, |
|
545
|
+ getParameters(response){ |
|
546
|
+ if(globalwpw.settings.obj.df_api_version=='v1'){ |
|
547
|
+ return response.result.parameters; |
|
548
|
+ }else{ |
|
549
|
+ return response.queryResult.parameters; |
|
550
|
+ } |
|
551
|
+ }, |
|
552
|
+ getFulfillmentText(response){ |
|
553
|
+ if(globalwpw.settings.obj.df_api_version=='v1'){ |
|
554
|
+ return response.result.fulfillment.messages; |
|
555
|
+ }else{ |
|
556
|
+ return response.queryResult.fulfillmentText; |
|
557
|
+ } |
|
558
|
+ }, |
|
559
|
+ getFulfillmentSpeech(response){ |
|
560
|
+ if(globalwpw.settings.obj.df_api_version=='v1'){ |
|
561
|
+ return response.result.fulfillment.speech; |
|
562
|
+ }else{ |
|
563
|
+ return response.queryResult.fulfillmentText; |
|
564
|
+ } |
|
565
|
+ }, |
|
566
|
+ getScore(response){ |
|
567
|
+ if(globalwpw.settings.obj.df_api_version=='v1'){ |
|
568
|
+ return response.result.score; |
|
569
|
+ }else{ |
|
570
|
+ return response.queryResult.intentDetectionConfidence; |
|
571
|
+ } |
|
572
|
+ }, |
|
573
|
+ getAction(response){ |
|
574
|
+ if(globalwpw.settings.obj.df_api_version=='v1'){ |
|
575
|
+ return response.result.action; |
|
576
|
+ }else{ |
|
577
|
+ if(typeof response.queryResult.action !=="undefined"){ |
|
578
|
+ return response.queryResult.action; |
|
579
|
+ }else{ |
|
580
|
+ return ''; |
|
581
|
+ } |
|
582
|
+ } |
|
583
|
+ }, |
|
584
|
+ queryText(response){ |
|
585
|
+ if(globalwpw.settings.obj.df_api_version=='v1'){ |
|
586
|
+ return response.result.resolvedQuery; |
|
587
|
+ }else{ |
|
588
|
+ return response.queryResult.queryText; |
|
589
|
+ } |
|
590
|
+ }, |
|
591
|
+ isActionComplete(response){ |
|
592
|
+ if(globalwpw.settings.obj.df_api_version=='v1'){ |
|
593
|
+ if(!response.result.actionIncomplete){ |
|
594
|
+ return true; |
|
595
|
+ }else{ |
|
596
|
+ return false; |
|
597
|
+ } |
|
598
|
+ }else{ |
|
599
|
+ return response.queryResult.allRequiredParamsPresent; |
|
600
|
+ } |
|
601
|
+ }, |
|
602
|
+ isConversationEnd(response){ |
|
603
|
+ if(globalwpw.settings.obj.df_api_version=='v1'){ |
|
604
|
+ if(typeof(response.result.metadata.endConversation)!=="undefined" && response.result.metadata.endConversation){ |
|
605
|
+ return true; |
|
606
|
+ }else{ |
|
607
|
+ return false; |
|
608
|
+ } |
|
609
|
+ }else{ |
|
610
|
+ if(typeof response.queryResult.diagnosticInfo !=="undefined"){ |
|
611
|
+ if(typeof response.queryResult.diagnosticInfo.end_conversation !== "undefined"){ |
|
612
|
+ return response.queryResult.diagnosticInfo.end_conversation; |
|
613
|
+ }else{ |
|
614
|
+ return false; |
|
615
|
+ } |
|
616
|
+ }else{ |
|
617
|
+ return false; |
|
618
|
+ } |
|
619
|
+ } |
|
620
|
+ }, |
|
621
|
+ sugestCat:function () { |
|
622
|
+ var productSuggest=wpwKits.randomMsg(globalwpw.settings.obj.product_suggest); |
|
623
|
+ var data={'action':'qcld_wb_chatbot_category'}; |
|
624
|
+ var result=wpwKits.ajax(data); |
|
625
|
+ result.done(function( response ) { |
|
626
|
+ wpwMsg.double_nobg(productSuggest,response); |
|
627
|
+ if(globalwpw.settings.obj.ai_df_enable==1 && globalwpw.df_status_lock==0){ |
|
628
|
+ globalwpw.wildCard=0; |
|
629
|
+ globalwpw.ai_step=1; |
|
630
|
+ localStorage.setItem("wildCard", globalwpw.wildCard); |
|
631
|
+ localStorage.setItem("aiStep", globalwpw.ai_step); |
|
632
|
+ } |
|
633
|
+ }); |
|
634
|
+ }, |
|
635
|
+ subCats:function (parentId) { |
|
636
|
+ var subCatMsg=wpwKits.randomMsg(globalwpw.settings.obj.product_suggest); |
|
637
|
+ var data={'action':'qcld_wb_chatbot_sub_category','parent_id':parentId}; |
|
638
|
+ var result=wpwKits.ajax(data); |
|
639
|
+ result.done(function( response ) { |
|
640
|
+ wpwMsg.double_nobg(subCatMsg,response); |
|
641
|
+ }); |
|
642
|
+ }, |
|
643
|
+ suggestEmail:function (emailFor) { |
|
644
|
+ var sugMsg=wpwKits.randomMsg(globalwpw.settings.obj.support_option_again); |
|
645
|
+ var sugOptions= '<span class="qcld-chatbot-wildcard qcld_back_to_start" data-wildcart="back">' + wpwKits.randomMsg(globalwpw.settings.obj.back_to_start) + '</span>'; // /*emailFor+*/globalwpw.wildcards; |
|
646
|
+ if( ( globalwpw.settings.obj.disable_back_to_start != '1' && globalwpw.settings.obj.skip_greetings_and_menu != 1 )){ |
|
647
|
+ wpwMsg.single_nobg('<span class="qcld-chatbot-wildcard qcld_back_to_start" data-wildcart="back">' + wpwKits.randomMsg(globalwpw.settings.obj.back_to_start) + '</span>'); |
|
648
|
+ } |
|
649
|
+ }, |
|
650
|
+ videohandler:function () { |
|
651
|
+ $(globalwpw.settings.messageLastChild+' .wp-chatbot-paragraph').html(function(i, html) { |
|
652
|
+ return html.replace(/(?:https:\/\/)?(?:www\.)?(?:youtube\.com|youtu\.be)\/(?:watch\?v=)?(.+)/g, '<iframe width="250" height="180" src="http://www.youtube.com/embed/$1" frameborder="0" allowfullscreen></iframe>'); |
|
653
|
+ }); |
|
654
|
+ }, |
|
655
|
+ scrollTo:function () { |
|
656
|
+ var $bot = $(globalwpw.settings.botContainer); |
|
657
|
+ var scrollTarget = $(globalwpw.settings.messageWrapper).prop("scrollHeight"); |
|
658
|
+ $bot.animate({ scrollTop: scrollTarget }, 'slow', function () { |
|
659
|
+ if (typeof window.wpbotSyncSlimScrollBar === 'function') { |
|
660
|
+ window.wpbotSyncSlimScrollBar($bot); |
|
661
|
+ } else { |
|
662
|
+ var el = $bot[0]; |
|
663
|
+ var $wrap = $bot.parent(); |
|
664
|
+ var $bar = $wrap.children('.slimScrollBar'); |
|
665
|
+ if (!el || !$bar.length) { |
|
666
|
+ return; |
|
667
|
+ } |
|
668
|
+ if (el.scrollHeight <= el.clientHeight + 2) { |
|
669
|
+ $wrap.addClass('wpbot-no-scroll'); |
|
670
|
+ $bar.stop(true, true).hide(); |
|
671
|
+ $wrap.children('.slimScrollRail').stop(true, true).hide(); |
|
672
|
+ } else { |
|
673
|
+ $wrap.removeClass('wpbot-no-scroll'); |
|
674
|
+ var barH = $bar.outerHeight() || 30; |
|
675
|
+ $bar.css({ top: Math.max(0, $bot.outerHeight() - barH) + 'px', display: 'block' }); |
|
676
|
+ } |
|
677
|
+ } |
|
678
|
+ }); |
|
679
|
+ }, |
|
680
|
+ botPreloader:function () { |
|
681
|
+ var enableleReactions = globalwpw.settings.obj.skip_chat_reactions_menu; |
|
682
|
+ var eanleeReport = globalwpw.settings.obj.enable_chat_report_menu; |
|
683
|
+ var enableshare = globalwpw.settings.obj.enable_chat_share_menu; |
|
684
|
+ var likeTxt = globalwpw.settings.obj.qlcd_wp_chatbot_like_text; |
|
685
|
+ var disLikeTxt = globalwpw.settings.obj.qlcd_wp_chatbot_dislike_text; |
|
686
|
+ var reportTxt = globalwpw.settings.obj.qlcd_wp_chatbot_report_text; |
|
687
|
+ var sharetTxt = globalwpw.settings.obj.qlcd_wp_chatbot_share_text; |
|
688
|
+ |
|
689
|
+ var msgContent='<li class="wp-chatbot-msg">' + |
|
690
|
+ '<div class="wp-chatbot-avatar">'+ |
|
691
|
+ '<img src="'+globalwpw.settings.obj.agent_image_path+'" alt="">'+ |
|
692
|
+ '</div>'+ |
|
693
|
+ '<div class="wp-chatbot-agent">'+ wpwMsg.oncommand_filter(globalwpw.settings.obj.agent)+'</div>' |
|
694
|
+ +'<div class="chat-container"><div class="wp-chatbot-paragraph"><img class="wp-chatbot-comment-loader" src="'+globalwpw.settings.obj.image_path+'comment.gif" alt="Typing..." /></div>'+ |
|
695
|
+ '<div class="qcld-like-dislike-icon">' + |
|
696
|
+ (enableleReactions == 1 && !qcldIsAiFormInProgress() |
|
697
|
+ ? '<a href="#" title="' + (disLikeTxt?.en_US || 'Dislike') + '"><i class="dashicons dashicons-thumbs-down" aria-hidden="true"></i></a>' + '<a href="#" title="' + (likeTxt?.en_US || 'Like') + '"><i class="dashicons dashicons-thumbs-up" aria-hidden="true"></i></a>' |
|
698
|
+ : '') + |
|
699
|
+ |
|
700
|
+ (eanleeReport == 1 && !qcldIsAiFormInProgress() |
|
701
|
+ ? '<a href="#" title="' + (reportTxt?.en_US || 'Report') + '"><i class="dashicons dashicons-admin-comments"></i></a>' |
|
702
|
+ : '') + |
|
703
|
+ |
|
704
|
+ (enableshare == 1 && !qcldIsAiFormInProgress() |
|
705
|
+ ? '<div class="qcld-share">' + |
|
706
|
+ '<a href="#" class="share-toggle" title="' + (sharetTxt?.en_US || 'Share') + '"><i class="dashicons dashicons-share"></i></a>' + |
|
707
|
+ '<div class="share-menu" style="display:none;">' + |
|
708
|
+ '<a href="#" class="share-fb"><i class="dashicons dashicons-facebook"></i></a>' + |
|
709
|
+ '<a href="#" class="share-wa"><i class="dashicons dashicons-whatsapp"></i></a>' + |
|
710
|
+ '<a href="#" class="share-x"><i class="dashicons dashicons-twitter"></i></a>' + |
|
711
|
+ '<a href="#" class="share-email"><i class="dashicons dashicons-email-alt"></i></a>' + |
|
712
|
+ '</div>' + |
|
713
|
+ '</div>' |
|
714
|
+ : '') + |
|
715
|
+ '</div>' +'</div>' + |
|
716
|
+ '</li>'; |
|
717
|
+ return msgContent; |
|
718
|
+ }, |
|
719
|
+ shopperMsgDom:function (msg) { |
|
720
|
+ if(globalwpw.hasNameCookie){ |
|
721
|
+ var shopper=globalwpw.hasNameCookie; |
|
722
|
+ } else{ |
|
723
|
+ var shopper=globalwpw.settings.obj.shopper_demo_name; |
|
724
|
+ } |
|
725
|
+ //var date = new Date(); |
|
726
|
+ date = new Date(); |
|
727
|
+ var msgContent='<li class="wp-chat-user-msg">' + |
|
728
|
+ '<div style="margin-top:40px;" class="wp-chatbot-avatar">'+ |
|
729
|
+ '<img src="'+globalwpw.settings.obj.image_path+'client.png" alt="User Image">'+ |
|
730
|
+ '</div>'+ |
|
731
|
+ '<div class="wp-chatbot-agent">'+shopper +'</div>' |
|
732
|
+ +'<div class="wp-chatbot-paragraph"><div class="wp-chatbot-textanimation">'+msg+'</div></div></li>'; |
|
733
|
+ return msgContent; |
|
734
|
+ }, |
|
735
|
+ showCart:function () { |
|
736
|
+ var data = {'action':'qcld_wb_chatbot_show_cart'} |
|
737
|
+ this.ajax(data).done(function (response) { |
|
738
|
+ //if cart show on message board |
|
739
|
+ if($('#wp-chatbot-shortcode-template-container').length == 0) { |
|
740
|
+ $(globalwpw.settings.messageWrapper).html(response.html); |
|
741
|
+ $('#wp-chatbot-cart-numbers').html(response.items); |
|
742
|
+ $('.wp-chatbot-ball-cart-items').html(response.items); |
|
743
|
+ wpwKits.disableEditor(wpwKits.randomMsg(globalwpw.settings.obj.shopping_cart)); |
|
744
|
+ }else{ //Cart show on shortcode |
|
745
|
+ $('.wp-chatbot-cart-shortcode-container').html(response.html); |
|
746
|
+ } |
|
747
|
+ //Add scroll to the cart shortcode |
|
748
|
+ if($('#wp-chatbot-shortcode-template-container').length > 0 && $('.chatbot-shortcode-template-02').length==0) { |
|
749
|
+ $('.wp-chatbot-cart-body').slimScroll({height: '200px', start: 'bottom'}); |
|
750
|
+ } |
|
751
|
+ }); |
|
752
|
+ }, |
|
753
|
+ toTitlecase:function (msg) { |
|
754
|
+ return msg.replace(/\w\S*/g, function(txt){return txt.charAt(0).toUpperCase() + txt.substr(1).toLowerCase();}); |
|
755
|
+ }, |
|
756
|
+ filterStopWords:function(msg){ |
|
757
|
+ var spcialStopWords=",;,/,\\,[,],{,},(,),&,*,.,+ ,?,^,$,=,!,<,>,|,:,-"; |
|
758
|
+ var userMsg=""; |
|
759
|
+ //Removing Special Characts from last position. |
|
760
|
+ var msgLastChar=msg.slice(-1); |
|
761
|
+ if(spcialStopWords.indexOf(msgLastChar) >= 0 ){ |
|
762
|
+ userMsg=msg.slice(0, -1); |
|
763
|
+ }else{ |
|
764
|
+ userMsg=msg; |
|
765
|
+ } |
|
766
|
+ var stopWords=globalwpw.settings.obj.stop_words+spcialStopWords; |
|
767
|
+ var stopWordsArr=stopWords.split(','); |
|
768
|
+ var msgArr=userMsg.split(' '); |
|
769
|
+ var filtermsgArr = msgArr.filter(function myCallBack(el){ |
|
770
|
+ return stopWordsArr.indexOf(el.toLowerCase()) < 0; |
|
771
|
+ }); |
|
772
|
+ filterMsg=filtermsgArr.join(' '); |
|
773
|
+ return filterMsg; |
|
774
|
+ }, |
|
775
|
+ htmlTagsScape:function(userString) { |
|
776
|
+ var tagsToReplace = { |
|
777
|
+ '&': '&', |
|
778
|
+ '<': '<', |
|
779
|
+ '>': '>' |
|
780
|
+ }; |
|
781
|
+ return userString.replace(/[&<>]/g, function(tag) { |
|
782
|
+ return tagsToReplace[tag] || tag; |
|
783
|
+ }); |
|
784
|
+ }, |
|
785
|
+ reset: function() { |
|
786
|
+ $('#wp-chatbot-messages-container').html(''); |
|
787
|
+ localStorage.removeItem("wpwHitory"); |
|
788
|
+ localStorage.removeItem('shopper'); |
|
789
|
+ localStorage.removeItem('shopperemail'); |
|
790
|
+ localStorage.removeItem('default_asking_email'); |
|
791
|
+ globalwpw.wildCard=0; |
|
792
|
+ globalwpw.ai_step=0; |
|
793
|
+ localStorage.setItem("wildCard", globalwpw.wildCard); |
|
794
|
+ localStorage.setItem("aiStep", globalwpw.ai_step); |
|
795
|
+ globalwpw.formfieldid = ''; |
|
796
|
+ localStorage.setItem("formfieldid", globalwpw.formfieldid); |
|
797
|
+ globalwpw.formStep='welcome'; |
|
798
|
+ localStorage.setItem("formStep", globalwpw.formStep); |
|
799
|
+ globalwpw.formid=''; |
|
800
|
+ localStorage.setItem("formid", globalwpw.formid); |
|
801
|
+ globalwpw.formentry = 0; |
|
802
|
+ localStorage.setItem("formentry", globalwpw.formentry); |
|
803
|
+ localStorage.removeItem("cx-name" ); |
|
804
|
+ localStorage.removeItem("cx-diaplayname" ); |
|
805
|
+ localStorage.removeItem("cx-languagecode" ); |
|
806
|
+ localStorage.removeItem("cx-timezone" ); |
|
807
|
+ } |
|
808
|
+ } |
|
809
|
+ /* |
|
810
|
+ * wpwbot Trees are basically product,order and support |
|
811
|
+ * product tree : asking,showing & shopping part will be covered. |
|
812
|
+ * order tree : showing order list and email to admin option. |
|
813
|
+ * support tree : List of support query-answer including text & video and email to admin option. |
|
814
|
+ */ |
|
815
|
+ var wpwTree={ |
|
816
|
+ greeting:function (msg) { |
|
817
|
+ if(localStorage.getItem('default_asking_email')){ |
|
818
|
+ var shopperEmail = msg; |
|
819
|
+ var validate = ""; |
|
820
|
+ var re = /^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i; |
|
821
|
+ if(re.test(shopperEmail) != true){ |
|
822
|
+ validate = (globalwpw.settings.obj.invalid_email && globalwpw.settings.obj.invalid_email.length > 0) ? wpwKits.randomMsg(globalwpw.settings.obj.invalid_email) : "Please enter a valid email address."; |
|
823
|
+ } |
|
824
|
+ if(validate != ""){ |
|
825
|
+ wpwMsg.single(validate); |
|
826
|
+ }else{ |
|
827
|
+ var email = shopperEmail; |
|
828
|
+ $.cookie("shopperemail", email, { expires: 365 }); |
|
829
|
+ localStorage.setItem("shopperemail", email); |
|
830
|
+ |
|
831
|
+ if (email != "") { |
|
832
|
+ var data = { |
|
833
|
+ action: "qcld_wb_chatbot_email_subscription", |
|
834
|
+ name: localStorage.getItem("shopper"), |
|
835
|
+ email: email, |
|
836
|
+ url: window.location.href, |
|
837
|
+ }; |
|
838
|
+ |
|
839
|
+ wpwKits.ajax(data).done(function (response) { |
|
840
|
+ //response. |
|
841
|
+ }); |
|
842
|
+ } |
|
843
|
+ localStorage.removeItem('default_asking_email'); |
|
844
|
+ |
|
845
|
+ var shopperName = localStorage.getItem('shopper'); |
|
846
|
+ var shopperNameFiltered = wpwKits.toTitlecase(wpwKits.filterStopWords(shopperName)); |
|
847
|
+ |
|
848
|
+ if(globalwpw.settings.obj.ai_df_enable==1 && globalwpw.df_status_lock==0){ |
|
849
|
+ var NameGreeting=wpwKits.randomMsg(globalwpw.settings.obj.i_am) +" <strong>"+wpwMsg.oncommand_filter(globalwpw.settings.obj.agent)+"</strong>! "+ wpwKits.randomMsg(globalwpw.settings.obj.name_greeting); |
|
850
|
+ NameGreeting = NameGreeting.replace("%%username%%", shopperName); |
|
851
|
+ var serviceOffer=wpwKits.randomMsg(globalwpw.settings.obj.wildcard_msg); |
|
852
|
+ serviceOffer = serviceOffer.replace("%%username%%", shopperName); |
|
853
|
+ wpwMsg.triple_nobg( NameGreeting,serviceOffer, globalwpw.wildcards ) |
|
854
|
+ globalwpw.ai_step=1; |
|
855
|
+ globalwpw.wildCard=0; |
|
856
|
+ localStorage.setItem("wildCard", globalwpw.wildCard); |
|
857
|
+ localStorage.setItem("aiStep", globalwpw.ai_step); |
|
858
|
+ }else{ |
|
859
|
+ if((globalwpw.settings.obj.skip_wp_greetings=='1') || (globalwpw.settings.obj.skip_greetings_and_menu =='1') ){ |
|
860
|
+ wpwAction.bot(shopperName) |
|
861
|
+ }else{ |
|
862
|
+ var NameGreeting=wpwKits.randomMsg(globalwpw.settings.obj.i_am) +" <strong>"+wpwMsg.oncommand_filter(globalwpw.settings.obj.agent)+"</strong>! "+wpwKits.randomMsg(globalwpw.settings.obj.name_greeting); |
|
863
|
+ NameGreeting = NameGreeting.replace("%%username%%", shopperNameFiltered); |
|
864
|
+ var serviceOffer=wpwKits.randomMsg(globalwpw.settings.obj.wildcard_msg); |
|
865
|
+ if( ( globalwpw.settings.obj.show_menu_after_greetings!=0 ) && ( globalwpw.wildcards !='' ) ){ |
|
866
|
+ wpwMsg.triple_nobg( NameGreeting,serviceOffer, globalwpw.wildcards ) |
|
867
|
+ }else{ |
|
868
|
+ wpwMsg.double( NameGreeting,serviceOffer ); |
|
869
|
+ } |
|
870
|
+ } |
|
871
|
+ } |
|
872
|
+ } |
|
873
|
+ return; |
|
874
|
+ } |
|
875
|
+ /** |
|
876
|
+ * When Enable DialogFlow then or else |
|
877
|
+ */ |
|
878
|
+ |
|
879
|
+ if(globalwpw.settings.obj.ai_df_enable==1 && globalwpw.df_status_lock==0){ |
|
880
|
+ //When intialize 1 and don't have cookies then keep the name of shooper in in cookie |
|
881
|
+ if(globalwpw.initialize==1 && !localStorage.getItem('shopper') && globalwpw.wildCard==0 && globalwpw.ai_step==0 ){ |
|
882
|
+ msg=wpwKits.toTitlecase(wpwKits.filterStopWords(msg)); |
|
883
|
+ $.cookie("shopper", msg, { expires : 365 }); |
|
884
|
+ localStorage.setItem('shopper',msg); |
|
885
|
+ globalwpw.hasNameCookie=msg; |
|
886
|
+ |
|
887
|
+ if(globalwpw.settings.obj.ask_email_wp_greetings == '1' && !localStorage.getItem('shopperemail')) { |
|
888
|
+ localStorage.setItem('default_asking_email', '1'); |
|
889
|
+ var ask_msg = (globalwpw.settings.obj.asking_email && globalwpw.settings.obj.asking_email.length > 0) ? wpwKits.randomMsg(globalwpw.settings.obj.asking_email) : "Could you please provide your email address?"; |
|
890
|
+ wpwMsg.single(ask_msg); |
|
891
|
+ } else { |
|
892
|
+ //Greeting with name and suggesting the wildcard. |
|
893
|
+ var NameGreeting=wpwKits.randomMsg(globalwpw.settings.obj.i_am) +" <strong>"+wpwMsg.oncommand_filter(globalwpw.settings.obj.agent)+"</strong>! "+ wpwKits.randomMsg(globalwpw.settings.obj.name_greeting); |
|
894
|
+ NameGreeting = NameGreeting.replace("%%username%%", msg); |
|
895
|
+ var serviceOffer=wpwKits.randomMsg(globalwpw.settings.obj.wildcard_msg); |
|
896
|
+ serviceOffer = serviceOffer.replace("%%username%%", msg); |
|
897
|
+ //After completing two steps messaging showing wildcards. |
|
898
|
+ wpwMsg.triple_nobg( NameGreeting,serviceOffer, globalwpw.wildcards ) |
|
899
|
+ globalwpw.ai_step=1; |
|
900
|
+ globalwpw.wildCard=0; |
|
901
|
+ localStorage.setItem("wildCard", globalwpw.wildCard); |
|
902
|
+ localStorage.setItem("aiStep", globalwpw.ai_step); |
|
903
|
+ } |
|
904
|
+ } |
|
905
|
+ //When returning shopper then greeting with name and wildcards. |
|
906
|
+ else if(localStorage.getItem('shopper') && globalwpw.wildCard==0 && globalwpw.ai_step==0){ |
|
907
|
+ if(globalwpw.settings.obj.ask_email_wp_greetings == '1' && !localStorage.getItem('shopperemail')) { |
|
908
|
+ localStorage.setItem('default_asking_email', '1'); |
|
909
|
+ var ask_msg = (globalwpw.settings.obj.asking_email && globalwpw.settings.obj.asking_email.length > 0) ? wpwKits.randomMsg(globalwpw.settings.obj.asking_email) : "Could you please provide your email address?"; |
|
910
|
+ wpwMsg.single(ask_msg); |
|
911
|
+ } else { |
|
912
|
+ //After asking service show the wildcards. |
|
913
|
+ var serviceOffer=wpwKits.randomMsg(globalwpw.settings.obj.wildcard_msg); |
|
914
|
+ globalwpw.ai_step=1; |
|
915
|
+ globalwpw.wildCard=0; |
|
916
|
+ localStorage.setItem("wildCard", globalwpw.wildCard); |
|
917
|
+ localStorage.setItem("aiStep", globalwpw.ai_step); |
|
918
|
+ if( ( globalwpw.settings.obj.show_menu_after_greetings==1) && ( globalwpw.wildcards !='' ) ){ |
|
919
|
+ wpwMsg.double_nobg(serviceOffer, globalwpw.wildcards); |
|
920
|
+ }else{ |
|
921
|
+ wpwMsg.single(serviceOffer); |
|
922
|
+ } |
|
923
|
+ } |
|
924
|
+ } |
|
925
|
+ //When user asking needs then DialogFlow will given intent after NLP steps. |
|
926
|
+ else if(globalwpw.wildCard==0 && globalwpw.ai_step==1){ |
|
927
|
+ var dfReturns=wpwKits.dailogAIOAction(msg); |
|
928
|
+ dfReturns.done(function( response ) { |
|
929
|
+ if(globalwpw.settings.obj.df_api_version=='v2'){ |
|
930
|
+ response = $.parseJSON(JSON.parse(response)); |
|
931
|
+ } |
|
932
|
+ if(wpwKits.responseIsOk(response)){ |
|
933
|
+ var userIntent=wpwKits.getIntentName(response); |
|
934
|
+ |
|
935
|
+ if(userIntent=='start'){ |
|
936
|
+ globalwpw.wildCard=0; |
|
937
|
+ var serviceOffer=wpwKits.randomMsg(globalwpw.settings.obj.wildcard_msg); |
|
938
|
+ console.log( globalwpw.wildcards); |
|
939
|
+ wpwMsg.double_nobg(serviceOffer,globalwpw.wildcards); |
|
940
|
+ }else if(userIntent=='welcome'){ |
|
941
|
+ var messages = wpwKits.getFulfillmentSpeech(response); |
|
942
|
+ setTimeout(function () { |
|
943
|
+ wpwMsg.single(messages); |
|
944
|
+ },globalwpw.settings.preLoadingTime); |
|
945
|
+ }else if(userIntent=='help'){ |
|
946
|
+ $(globalwpw.settings.messageWrapper).html(localStorage.getItem("wpwHitory")); |
|
947
|
+ //Showing help message |
|
948
|
+ setTimeout(function () { |
|
949
|
+ wpwKits.scrollTo(); |
|
950
|
+ |
|
951
|
+ var helpWelcome = wpwKits.randomMsg(globalwpw.settings.obj.help_welcome); |
|
952
|
+ var helpMsg = wpwKits.randomMsg(globalwpw.settings.obj.help_msg); |
|
953
|
+ wpwMsg.double(helpWelcome,helpMsg); |
|
954
|
+ //dialogflow |
|
955
|
+ if(globalwpw.settings.obj.ai_df_enable==1 && globalwpw.df_status_lock==0){ |
|
956
|
+ globalwpw.wildCard=0; |
|
957
|
+ globalwpw.ai_step=1; |
|
958
|
+ localStorage.setItem("wildCard", globalwpw.wildCard); |
|
959
|
+ localStorage.setItem("aiStep", globalwpw.ai_step); |
|
960
|
+ } |
|
961
|
+ },globalwpw.settings.preLoadingTime); |
|
962
|
+ }else if(userIntent=='reset'){ |
|
963
|
+ var restWarning=globalwpw.settings.obj.reset; |
|
964
|
+ var confirmBtn='<span class="qcld-chatbot-reset-btn" reset-data="yes" >'+globalwpw.settings.obj.yes+'</span> <span> '+globalwpw.settings.obj.or+' </span><span class="qcld-chatbot-reset-btn" reset-data="no">'+globalwpw.settings.obj.no+'</span>'; |
|
965
|
+ wpwMsg.double_nobg(restWarning,confirmBtn); |
|
966
|
+ }else if(userIntent=='phone'){ |
|
967
|
+ if(typeof(globalwpw.hasNameCookie)=='undefined'|| globalwpw.hasNameCookie==''){ |
|
968
|
+ var shopperName= globalwpw.settings.obj.shopper_demo_name; |
|
969
|
+ }else{ |
|
970
|
+ var shopperName=globalwpw.hasNameCookie; |
|
971
|
+ } |
|
972
|
+ var ask_msg = wpwKits.randomMsg(globalwpw.settings.obj.asking_phone); |
|
973
|
+ var askEmail = (globalwpw.settings.obj.skip_wp_greetings=='1' || globalwpw.settings.obj.skip_greetings_and_menu =='1') ? 'Hello ' + ask_msg : 'Hello '+shopperName+'! '+ ask_msg; |
|
974
|
+ wpwMsg.single(askEmail); |
|
975
|
+ //Now updating the support part as . |
|
976
|
+ globalwpw.supportStep='phone'; |
|
977
|
+ globalwpw.wildCard=1; |
|
978
|
+ //keeping value in localstorage |
|
979
|
+ localStorage.setItem("wildCard", globalwpw.wildCard); |
|
980
|
+ localStorage.setItem("supportStep", globalwpw.supportStep); |
|
981
|
+ }else if(userIntent=='email'){ |
|
982
|
+ if(typeof(globalwpw.hasNameCookie)=='undefined'|| globalwpw.hasNameCookie==''){ |
|
983
|
+ var shopperName= globalwpw.settings.obj.shopper_demo_name; |
|
984
|
+ }else{ |
|
985
|
+ var shopperName=globalwpw.hasNameCookie; |
|
986
|
+ } |
|
987
|
+ var ask_msg = wpwKits.randomMsg(globalwpw.settings.obj.asking_email); |
|
988
|
+ var askEmail = (globalwpw.settings.obj.skip_wp_greetings=='1' || globalwpw.settings.obj.skip_greetings_and_menu =='1') ? wpwKits.randomMsg(globalwpw.settings.obj.hello)+' '+ ask_msg : wpwKits.randomMsg(globalwpw.settings.obj.hello)+' '+shopperName+'! '+ ask_msg; |
|
989
|
+ wpwMsg.single(askEmail); |
|
990
|
+ //Now updating the support part as . |
|
991
|
+ globalwpw.supportStep='email'; |
|
992
|
+ globalwpw.wildCard=1; |
|
993
|
+ //keeping value in localstorage |
|
994
|
+ localStorage.setItem("wildCard", globalwpw.wildCard); |
|
995
|
+ localStorage.setItem("supportStep", globalwpw.supportStep); |
|
996
|
+ }else if(userIntent=='faq'){ |
|
997
|
+ globalwpw.wildCard=1; |
|
998
|
+ globalwpw.supportStep='welcome'; |
|
999
|
+ wpwAction.bot('from wildcard support'); |
|
1000
|
+ //keeping value in localstorage |
|
1001
|
+ /*localStorage.setItem("wildCard", globalwpw.wildCard); |
|
1002
|
+ localStorage.setItem("supportStep", globalwpw.supportStep);*/ |
|
1003
|
+ }else if(userIntent=='Default Fallback Intent'){ |
|
1004
|
+ |
|
1005
|
+ var data = {'action':'wpbo_search_response','name':globalwpw.hasNameCookie,'keyword':msg}; |
|
1006
|
+ wpwKits.ajax(data).done(function (respond) { |
|
1007
|
+ var json=$.parseJSON(respond); |
|
1008
|
+ if(json.status=='success'){ |
|
1009
|
+ if(typeof(json.category)!=="undefined" && json.category){ |
|
1010
|
+ var question=''; |
|
1011
|
+ $.each(json.data, function (i, obj) { |
|
1012
|
+ question += '<span class="qcld-chatbot-wildcard qcld_simple_txt_response" data-strid="'+ obj.id +'">'+ obj.query +'</span>'; |
|
1013
|
+ }); |
|
1014
|
+ wpwMsg.single_nobg(question); |
|
1015
|
+ }else if(json.multiple){ |
|
1016
|
+ var question=''; |
|
1017
|
+ $.each(json.data, function (i, obj) { |
|
1018
|
+ question += '<span class="qcld-chatbot-wildcard qcld_simple_txt_response" data-strid="'+ obj.id +'">'+ obj.query +'</span>'; |
|
1019
|
+ }); |
|
1020
|
+ wpwMsg.double_nobg(wpwKits.randomMsg(globalwpw.settings.obj.did_you_mean),question); |
|
1021
|
+ }else{ |
|
1022
|
+ wpwMsg.single(json.data[0].response); |
|
1023
|
+ setTimeout(function(){ |
|
1024
|
+ wpwMsg.single_nobg('<span class="qcld-chatbot-wildcard" data-wildcart="back">' + wpwKits.randomMsg(globalwpw.settings.obj.back_to_start) + '</span>'); |
|
1025
|
+ },globalwpw.settings.preLoadingTime*2) |
|
1026
|
+ } |
|
1027
|
+ }if(wp_chatbot_obj.disable_site_search != 1){ |
|
1028
|
+ |
|
1029
|
+ wpwTree.site_search(msg) |
|
1030
|
+ }else{ |
|
1031
|
+ msg = wpwKits.filterStopWords(msg); |
|
1032
|
+ if(globalwpw.counter == 2 ){ |
|
1033
|
+ wpwTree.df_reply(response); |
|
1034
|
+ setTimeout(function(){ |
|
1035
|
+ var serviceOffer=wpwKits.randomMsg(globalwpw.settings.obj.support_option_again); |
|
1036
|
+ wpwMsg.single_nobg('<span class="qcld-chatbot-wildcard qcld_back_to_start" data-wildcart="back">' + wpwKits.randomMsg(globalwpw.settings.obj.back_to_start) + '</span>'); |
|
1037
|
+ },globalwpw.settings.preLoadingTime) |
|
1038
|
+ globalwpw.counter = 0; |
|
1039
|
+ }else{ |
|
1040
|
+ globalwpw.counter++; |
|
1041
|
+ wpwTree.df_reply(response); |
|
1042
|
+ } |
|
1043
|
+ } |
|
1044
|
+ }) |
|
1045
|
+ }else if(wpwKits.getScore(response)!=0){ // checking is reponsing from dialogflow. |
|
1046
|
+ var sTalkAction=wpwKits.getAction(response); |
|
1047
|
+ if(sTalkAction!='' && sTalkAction.indexOf('smalltalk') != -1 ){ |
|
1048
|
+ var sMgs=wpwKits.getFulfillmentText(response); |
|
1049
|
+ wpwMsg.single(sMgs); |
|
1050
|
+ }else{ |
|
1051
|
+ var messages = wpwKits.getFulfillmentText(response); |
|
1052
|
+ wpwTree.df_reply(response); |
|
1053
|
+ } |
|
1054
|
+ }else{ |
|
1055
|
+ console.log( globalwpw.wildcards); |
|
1056
|
+ var dfDefaultMsg=globalwpw.settings.obj.df_defualt_reply; |
|
1057
|
+ wpwMsg.double_nobg(dfDefaultMsg,globalwpw.wildcards); |
|
1058
|
+ } |
|
1059
|
+ }else{ |
|
1060
|
+ console.log( globalwpw.wildcards); |
|
1061
|
+ //if bad request or limit cross then |
|
1062
|
+ globalwpw.df_status_lock=0; |
|
1063
|
+ var dfDefaultMsg=globalwpw.settings.obj.df_defualt_reply; |
|
1064
|
+ wpwMsg.double_nobg(dfDefaultMsg,globalwpw.wildcards); |
|
1065
|
+ } |
|
1066
|
+ }).fail(function (error) { |
|
1067
|
+ var dfDefaultMsg=globalwpw.settings.obj.df_defualt_reply; |
|
1068
|
+ console.log( globalwpw.wildcards); |
|
1069
|
+ wpwMsg.double_nobg(dfDefaultMsg,globalwpw.wildcards); |
|
1070
|
+ }); |
|
1071
|
+ } |
|
1072
|
+ }else{ |
|
1073
|
+ //When intialize 1 and don't have cookies then keep the name of shooper in in cookie |
|
1074
|
+ if(globalwpw.initialize==1 && !localStorage.getItem('shopper') && globalwpw.wildCard==0){ |
|
1075
|
+ msg=wpwKits.toTitlecase(msg); |
|
1076
|
+ msg1=wpwKits.toTitlecase(wpwKits.filterStopWords(msg)); |
|
1077
|
+ $.cookie("shopper", msg, { expires : 365 }); |
|
1078
|
+ localStorage.setItem('shopper',msg); |
|
1079
|
+ globalwpw.hasNameCookie=msg; |
|
1080
|
+ |
|
1081
|
+ if(globalwpw.settings.obj.ask_email_wp_greetings == '1' && !localStorage.getItem('shopperemail')) { |
|
1082
|
+ localStorage.setItem('default_asking_email', '1'); |
|
1083
|
+ var ask_msg = (globalwpw.settings.obj.asking_email && globalwpw.settings.obj.asking_email.length > 0) ? wpwKits.randomMsg(globalwpw.settings.obj.asking_email) : "Could you please provide your email address?"; |
|
1084
|
+ wpwMsg.single(ask_msg); |
|
1085
|
+ } else { |
|
1086
|
+ //Greeting with name and suggesting the wildcard. |
|
1087
|
+ if((globalwpw.settings.obj.skip_wp_greetings=='1') || (globalwpw.settings.obj.skip_greetings_and_menu =='1') ){ |
|
1088
|
+ wpwAction.bot(msg) |
|
1089
|
+ }else{ |
|
1090
|
+ var NameGreeting=wpwKits.randomMsg(globalwpw.settings.obj.i_am) +" <strong>"+wpwMsg.oncommand_filter(globalwpw.settings.obj.agent)+"</strong>! "+wpwKits.randomMsg(globalwpw.settings.obj.name_greeting); |
|
1091
|
+ NameGreeting = NameGreeting.replace("%%username%%", msg1); |
|
1092
|
+ var serviceOffer=wpwKits.randomMsg(globalwpw.settings.obj.wildcard_msg); |
|
1093
|
+ //After completing two steps messaging showing wildcards. |
|
1094
|
+ if( ( globalwpw.settings.obj.show_menu_after_greetings!=0 ) && ( globalwpw.wildcards !='' ) ){ |
|
1095
|
+ wpwMsg.triple_nobg( NameGreeting,serviceOffer, globalwpw.wildcards ) |
|
1096
|
+ |
|
1097
|
+ }else{ |
|
1098
|
+ wpwMsg.double( NameGreeting,serviceOffer ); |
|
1099
|
+ } |
|
1100
|
+ } |
|
1101
|
+ } |
|
1102
|
+ } |
|
1103
|
+ //When returning shopper then greeting with name and wildcards. |
|
1104
|
+ else if(localStorage.getItem('shopper') && globalwpw.wildCard==0){ |
|
1105
|
+ if(globalwpw.settings.obj.ask_email_wp_greetings == '1' && !localStorage.getItem('shopperemail')) { |
|
1106
|
+ localStorage.setItem('default_asking_email', '1'); |
|
1107
|
+ var ask_msg = (globalwpw.settings.obj.asking_email && globalwpw.settings.obj.asking_email.length > 0) ? wpwKits.randomMsg(globalwpw.settings.obj.asking_email) : "Could you please provide your email address?"; |
|
1108
|
+ wpwMsg.single(ask_msg); |
|
1109
|
+ } else { |
|
1110
|
+ //After asking service show the wildcards. |
|
1111
|
+ var serviceOffer=wpwKits.randomMsg(globalwpw.settings.obj.wildcard_msg); |
|
1112
|
+ console.log( globalwpw.wildcards); |
|
1113
|
+ wpwMsg.double_nobg(serviceOffer,globalwpw.wildcards); |
|
1114
|
+ } |
|
1115
|
+ } |
|
1116
|
+ } |
|
1117
|
+ }, |
|
1118
|
+ df_multi_handle:function(array){ |
|
1119
|
+ if(array.length>0){ |
|
1120
|
+ setTimeout(function(){ |
|
1121
|
+ wpwMsg.single(array[0]); |
|
1122
|
+ array.splice(0, 1); |
|
1123
|
+ setTimeout(function(){ |
|
1124
|
+ wpwTree.df_multi_handle(array); |
|
1125
|
+ }, globalwpw.settings.preLoadingTime) |
|
1126
|
+ }, globalwpw.settings.preLoadingTime) |
|
1127
|
+ } |
|
1128
|
+ }, |
|
1129
|
+ df_reply:function(response){ |
|
1130
|
+ //checking for facebook platform |
|
1131
|
+ var i = 0; |
|
1132
|
+ var html = ''; |
|
1133
|
+ var responses = []; |
|
1134
|
+ if(globalwpw.settings.obj.df_api_version=='v1'){ |
|
1135
|
+ var messages = (response && response.result && response.result.fulfillment && response.result.fulfillment.messages) ? response.result.fulfillment.messages : []; |
|
1136
|
+ var action = (response && response.result && typeof response.result.actionIncomplete !== 'undefined') ? response.result.actionIncomplete : false; |
|
1137
|
+ jQuery.each( messages, function( key, message ) { |
|
1138
|
+ html = ''; |
|
1139
|
+ i +=1; |
|
1140
|
+ if(message.type==2){ |
|
1141
|
+ html += "<p>" + message.title + "</p>"; |
|
1142
|
+ var index = 0; |
|
1143
|
+ for (index; index<message.replies.length; index++) { |
|
1144
|
+ html += "<span class=\"wpb-quick-reply qcld-chat-common\">"+ message.replies[index] +"</span>"; |
|
1145
|
+ } |
|
1146
|
+ } |
|
1147
|
+ //check for default reply |
|
1148
|
+ else if(message.type==0 && message.speech!=''){ |
|
1149
|
+ html += message.speech; |
|
1150
|
+ }else if(message.type==1){ |
|
1151
|
+ html +=''; |
|
1152
|
+ }else if(message.type=='simple_response'){ |
|
1153
|
+ html += message.textToSpeech; |
|
1154
|
+ } |
|
1155
|
+ if(html!=''){ |
|
1156
|
+ responses.push(html); |
|
1157
|
+ } |
|
1158
|
+ }) |
|
1159
|
+ }else{ |
|
1160
|
+ var messages = (response && response.queryResult && response.queryResult.fulfillmentMessages) ? response.queryResult.fulfillmentMessages : []; |
|
1161
|
+ var actioncomplete = (response && response.queryResult && typeof response.queryResult.allRequiredParamsPresent !== 'undefined') ? response.queryResult.allRequiredParamsPresent : false; |
|
1162
|
+ jQuery.each( messages, function( key, message ) { |
|
1163
|
+ html = ''; |
|
1164
|
+ i +=1; |
|
1165
|
+ //handeling quickreplies |
|
1166
|
+ if(typeof message.quickReplies !=="undefined"){ |
|
1167
|
+ if(typeof message.quickReplies.title !=="undefined"){ |
|
1168
|
+ html += "<p>" + message.quickReplies.title + "</p>"; |
|
1169
|
+ } |
|
1170
|
+ if(typeof message.quickReplies.quickReplies !=="undefined" ){ |
|
1171
|
+ var index = 0; |
|
1172
|
+ for (index; index<message.quickReplies.quickReplies.length; index++) { |
|
1173
|
+ html += "<span class=\"wpb-quick-reply qcld-chat-common\">"+ message.quickReplies.quickReplies[index] +"</span>"; |
|
1174
|
+ } |
|
1175
|
+ } |
|
1176
|
+ } |
|
1177
|
+ //handleing default response |
|
1178
|
+ else if(typeof message.text !=="undefined"){ |
|
1179
|
+ if(typeof message.text.text !=="undefined" && message.text.text.length>0){ |
|
1180
|
+ html += message.text.text[0]; |
|
1181
|
+ } |
|
1182
|
+ } |
|
1183
|
+ if(html!=''){ |
|
1184
|
+ responses.push(html); |
|
1185
|
+ } |
|
1186
|
+ }) |
|
1187
|
+ } |
|
1188
|
+ wpwTree.df_multi_handle(responses); |
|
1189
|
+ }, |
|
1190
|
+ support:function (msg) { |
|
1191
|
+ if(globalwpw.wildCard==1 && globalwpw.supportStep=='welcome'){ |
|
1192
|
+ var welcomeMsg= wpwKits.randomMsg(globalwpw.settings.obj.support_welcome); |
|
1193
|
+ var orPhoneSuggest = ''; |
|
1194
|
+ if(globalwpw.settings.obj.support_query.length>0){ |
|
1195
|
+ var supportsItems = ''; |
|
1196
|
+ var messenger = ''; |
|
1197
|
+ if(globalwpw.settings.obj.enable_messenger==1) { |
|
1198
|
+ messenger += '<span class="qcld-chatbot-wildcard" data-wildcart="messenger">'+wpwKits.randomMsg(globalwpw.settings.obj.messenger_label)+'</span>'; |
|
1199
|
+ } |
|
1200
|
+ if(globalwpw.settings.obj.enable_whats==1) { |
|
1201
|
+ messenger += '<span class="qcld-chatbot-wildcard" data-wildcart="whatsapp">'+wpwKits.randomMsg(globalwpw.settings.obj.whats_label)+'</span>'; |
|
1202
|
+ } |
|
1203
|
+ if(globalwpw.settings.obj.disable_feedback=='') { |
|
1204
|
+ messenger+= '<span class="qcld-chatbot-suggest-email" >'+wpwKits.randomMsg(globalwpw.settings.obj.feedback_label)+'</span>'; |
|
1205
|
+ } |
|
1206
|
+ $.each(globalwpw.settings.obj.support_query, function (i, obj) { |
|
1207
|
+ supportsItems += '<span class="qcld-chatbot-support-items" data-query-index="' + i + '">' + obj + '</span>'; |
|
1208
|
+ }); |
|
1209
|
+ var orEmailSuggest = '<span class="qcld-chatbot-suggest-email" >' + wpwKits.randomMsg(globalwpw.settings.obj.support_email) + '</span>'; |
|
1210
|
+ if(globalwpw.settings.obj.call_sup=="") { |
|
1211
|
+ orPhoneSuggest = '<span class="qcld-chatbot-suggest-phone" >' + wpwKits.randomMsg(globalwpw.settings.obj.support_phone) + '</span>'; |
|
1212
|
+ } |
|
1213
|
+ var queryOrEmail=supportsItems/*+orEmailSuggest+orPhoneSuggest+messenger*/; |
|
1214
|
+ }else { |
|
1215
|
+ if(globalwpw.settings.obj.call_sup=="") { |
|
1216
|
+ orPhoneSuggest = '<span class="qcld-chatbot-suggest-phone" >' + wpwKits.randomMsg(globalwpw.settings.obj.support_phone) + '</span>'; |
|
1217
|
+ } |
|
1218
|
+ var queryOrEmail='<span class="qcld-chatbot-suggest-email" >' + wpwKits.randomMsg(globalwpw.settings.obj.support_email) + '</span>'+orPhoneSuggest; |
|
1219
|
+ } |
|
1220
|
+ wpwMsg.double_nobg(welcomeMsg,queryOrEmail); |
|
1221
|
+ globalwpw.wildCard = 0; |
|
1222
|
+ } else if(globalwpw.wildCard==1 && globalwpw.supportStep=='email'){ |
|
1223
|
+ globalwpw.shopperEmail=msg; |
|
1224
|
+ var validate = ""; |
|
1225
|
+ var re = /^([\w-]+(?:\.[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i; |
|
1226
|
+ if( re.test(globalwpw.shopperEmail)!=true){ |
|
1227
|
+ validate = validate+wpwKits.randomMsg(globalwpw.settings.obj.invalid_email) ; |
|
1228
|
+ } |
|
1229
|
+ if(validate == ""){ |
|
1230
|
+ var askingMsg=wpwKits.randomMsg(globalwpw.settings.obj.asking_msg); |
|
1231
|
+ wpwMsg.single(askingMsg); |
|
1232
|
+ globalwpw.supportStep='message'; |
|
1233
|
+ //keeping value in localstorage |
|
1234
|
+ localStorage.setItem("supportStep", globalwpw.supportStep); |
|
1235
|
+ }else{ |
|
1236
|
+ wpwMsg.single(validate); |
|
1237
|
+ globalwpw.supportStep='email'; |
|
1238
|
+ //keeping value in localstorage |
|
1239
|
+ localStorage.setItem("supportStep", globalwpw.supportStep); |
|
1240
|
+ } |
|
1241
|
+ }else if(globalwpw.wildCard==1 && globalwpw.supportStep=='message'){ |
|
1242
|
+ var data = {'action':'qcld_wb_chatbot_support_email','name':globalwpw.hasNameCookie,'email':globalwpw.shopperEmail,'message':msg,'nonce':globalwpw.settings.obj.ajax_nonce}; |
|
1243
|
+ wpwKits.ajax(data).done(function (response) { |
|
1244
|
+ var json=$.parseJSON(response); |
|
1245
|
+ var orPhoneSuggest=''; |
|
1246
|
+ if(json.status=='success'){ |
|
1247
|
+ var sucMsg=json.message; |
|
1248
|
+ wpwMsg.single(sucMsg); |
|
1249
|
+ //Asking email after showing answer. |
|
1250
|
+ setTimeout(function(){ |
|
1251
|
+ if(globalwpw.settings.obj.call_sup=="") { |
|
1252
|
+ orPhoneSuggest = '<span class="qcld-chatbot-suggest-phone" >' + wpwKits.randomMsg(globalwpw.settings.obj.support_phone) + '</span>'; |
|
1253
|
+ } |
|
1254
|
+ var orEmailSuggest='<span class="qcld-chatbot-suggest-email" >'+wpwKits.randomMsg(globalwpw.settings.obj.support_email)+'</span>'; |
|
1255
|
+ wpwKits.suggestEmail(orEmailSuggest+orPhoneSuggest); |
|
1256
|
+ globalwpw.wildCard=0; |
|
1257
|
+ },globalwpw.settings.preLoadingTime); |
|
1258
|
+ }else{ |
|
1259
|
+ var failMsg=json.message; |
|
1260
|
+ wpwMsg.single(failMsg); |
|
1261
|
+ //Asking email after showing answer. |
|
1262
|
+ setTimeout(function(){ |
|
1263
|
+ if(globalwpw.settings.obj.call_sup=="") { |
|
1264
|
+ orPhoneSuggest = '<span class="qcld-chatbot-suggest-phone" >' + wpwKits.randomMsg(globalwpw.settings.obj.support_phone) + '</span>'; |
|
1265
|
+ } |
|
1266
|
+ var orEmailSuggest='<span class="qcld-chatbot-suggest-email" >'+wpwKits.randomMsg(globalwpw.settings.obj.support_email)+'</span>'; |
|
1267
|
+ wpwKits.suggestEmail(orEmailSuggest+orPhoneSuggest); |
|
1268
|
+ globalwpw.wildCard=0; |
|
1269
|
+ },globalwpw.settings.preLoadingTime); |
|
1270
|
+ } |
|
1271
|
+ }); |
|
1272
|
+ }else if(globalwpw.wildCard==1 && globalwpw.supportStep=='phone'){ |
|
1273
|
+ var data = {'action':'qcld_wb_chatbot_support_phone','name':globalwpw.hasNameCookie,'phone':msg,'nonce':globalwpw.settings.obj.ajax_nonce}; |
|
1274
|
+ wpwKits.ajax(data).done(function (response) { |
|
1275
|
+ var json=$.parseJSON(response); |
|
1276
|
+ var orPhoneSuggest=''; |
|
1277
|
+ if(json.status=='success'){ |
|
1278
|
+ var sucMsg=json.message; |
|
1279
|
+ wpwMsg.single(sucMsg); |
|
1280
|
+ //Asking email after showing answer. |
|
1281
|
+ setTimeout(function(){ |
|
1282
|
+ if(globalwpw.settings.obj.call_sup=="") { |
|
1283
|
+ orPhoneSuggest = '<span class="qcld-chatbot-suggest-phone" >' + wpwKits.randomMsg(globalwpw.settings.obj.support_phone) + '</span>'; |
|
1284
|
+ } |
|
1285
|
+ var orEmailSuggest='<span class="qcld-chatbot-suggest-email" >'+wpwKits.randomMsg(globalwpw.settings.obj.support_email)+'</span>'; |
|
1286
|
+ wpwKits.suggestEmail(orEmailSuggest+orPhoneSuggest); |
|
1287
|
+ globalwpw.wildCard=0; |
|
1288
|
+ },globalwpw.settings.preLoadingTime); |
|
1289
|
+ }else{ |
|
1290
|
+ var failMsg=json.message; |
|
1291
|
+ wpwMsg.single(failMsg); |
|
1292
|
+ //Asking email after showing answer. |
|
1293
|
+ setTimeout(function(){ |
|
1294
|
+ if(globalwpw.settings.obj.call_sup=="") { |
|
1295
|
+ orPhoneSuggest = '<span class="qcld-chatbot-suggest-phone" >' + wpwKits.randomMsg(globalwpw.settings.obj.support_phone) + '</span>'; |
|
1296
|
+ } |
|
1297
|
+ var orEmailSuggest='<span class="qcld-chatbot-suggest-email" >'+wpwKits.randomMsg(globalwpw.settings.obj.support_email)+'</span>'; |
|
1298
|
+ wpwKits.suggestEmail(orEmailSuggest+orPhoneSuggest); |
|
1299
|
+ globalwpw.wildCard=0; |
|
1300
|
+ },globalwpw.settings.preLoadingTime); |
|
1301
|
+ } |
|
1302
|
+ }); |
|
1303
|
+ }else if(globalwpw.wildCard==1 && globalwpw.supportStep=='search'){ |
|
1304
|
+ msg = wpwKits.filterStopWords(msg); |
|
1305
|
+ var data = {'action':'wpbo_search_site','name':globalwpw.hasNameCookie,'keyword':msg, 'security':wp_chatbot_obj.ajax_nonce }; |
|
1306
|
+ wpwKits.ajax(data).done(function (response) { |
|
1307
|
+ var json=$.parseJSON(response); |
|
1308
|
+ if(json.status=='success'){ |
|
1309
|
+ wpwMsg.double_nobg(wp_chatbot_obj.found_result_message,json.html); |
|
1310
|
+ }else{ |
|
1311
|
+ |
|
1312
|
+ wpwMsg.single( wpwKits.randomMsg(wp_chatbot_obj.product_fail)); |
|
1313
|
+ |
|
1314
|
+ // setTimeout(function(){ |
|
1315
|
+ // var serviceOffer=wpwKits.randomMsg(globalwpw.settings.obj.support_option_again); |
|
1316
|
+ // wpwMsg.double_nobg(serviceOffer,globalwpw.wildcards); |
|
1317
|
+ // },globalwpw.settings.preLoadingTime) |
|
1318
|
+ } |
|
1319
|
+ }); |
|
1320
|
+ }// |
|
1321
|
+ }, |
|
1322
|
+ formbuilder:function(msg){ |
|
1323
|
+ if(globalwpw.wildCard==7 && globalwpw.formStep=='welcome'){ |
|
1324
|
+ var data = {'action':'wpbot_get_form','formid':msg}; |
|
1325
|
+ wpwKits.ajax(data).done(function (response) { |
|
1326
|
+ if(response!=''){ |
|
1327
|
+ var json=$.parseJSON(response); |
|
1328
|
+ globalwpw.prevform = json.ID; |
|
1329
|
+ globalwpw.formfieldid = json.ID; |
|
1330
|
+ localStorage.setItem("formfieldid", globalwpw.formfieldid); |
|
1331
|
+ globalwpw.formStep='field'; |
|
1332
|
+ localStorage.setItem("formStep", globalwpw.formStep); |
|
1333
|
+ globalwpw.formid=msg; |
|
1334
|
+ localStorage.setItem("formid", globalwpw.formid); |
|
1335
|
+ localStorage.setItem("wildCard", globalwpw.wildCard); |
|
1336
|
+ var label = json.label; |
|
1337
|
+ if(json.type=='dropdown'){ |
|
1338
|
+ var html = ''; |
|
1339
|
+ jQuery.each(json.config.option, function(key, value){ |
|
1340
|
+ html += '<span class="qcld-chatbot-wildcard qcld-chatbot-formanswer" data-form-value="'+value.value+'" >'+value.label+'</span>'; |
|
1341
|
+ }) |
|
1342
|
+ wpwMsg.double(label, html); |
|
1343
|
+ }else if(json.type=='checkbox'){ |
|
1344
|
+ var html = ''; |
|
1345
|
+ jQuery.each(json.config.option, function(key, value){ |
|
1346
|
+ html += '<input type="checkbox" class="qcld-chatbot-checkbox" value="'+value.value+'">'+value.label+'<br>'; |
|
1347
|
+ }) |
|
1348
|
+ wpwMsg.double(label, html); |
|
1349
|
+ }else if(json.type=='html'){ |
|
1350
|
+ wpwMsg.single(json.config.default); |
|
1351
|
+ globalwpw.formfieldid = json.ID; |
|
1352
|
+ localStorage.setItem("formfieldid", globalwpw.formfieldid); |
|
1353
|
+ globalwpw.formentry = json.entry; |
|
1354
|
+ localStorage.setItem("formentry", globalwpw.formentry); |
|
1355
|
+ setTimeout(function(){ |
|
1356
|
+ wpwTree.formbuilder(); |
|
1357
|
+ }, globalwpw.settings.preLoadingTime) |
|
1358
|
+ }else{ |
|
1359
|
+ wpwMsg.single(label); |
|
1360
|
+ } |
|
1361
|
+ } |
|
1362
|
+ }) |
|
1363
|
+ }else if(globalwpw.wildCard==7 && globalwpw.formStep=='field'){ |
|
1364
|
+ var data = {'action':'wpbot_capture_form_value','formid':globalwpw.formid, 'fieldid': globalwpw.formfieldid, 'answer': msg, 'entry':globalwpw.formentry,'session': localStorage.getItem('botsessionid'), 'name': globalwpw.hasNameCookie,'email':localStorage.getItem('shopperemail'), 'url': window.location.href}; |
|
1365
|
+ wpwKits.ajax(data).done(function (response) { |
|
1366
|
+ var json=$.parseJSON(response); |
|
1367
|
+ if(json.status=='incomplete'){ |
|
1368
|
+ if( json.type !='html' ){ |
|
1369
|
+ if($('.chatbot_intent_reload').length > 0){ |
|
1370
|
+ $('.chatbot_intent_reload').remove(); |
|
1371
|
+ } |
|
1372
|
+ $('#wp-chatbot-editor-container').append('<span class="chatbot_intent_reload" title="Click to go back." data-wildcard="7" data-step="welcome" data-intent-type="formbuilder" data-intent="'+globalwpw.prevform+'"><i class="dashicons dashicons-controls-repeat"></i></span>'); |
|
1373
|
+ globalwpw.prevform = globalwpw.formfieldid; |
|
1374
|
+ } |
|
1375
|
+ globalwpw.formStep='field'; |
|
1376
|
+ localStorage.setItem("formStep", globalwpw.formStep); |
|
1377
|
+ globalwpw.formfieldid = json.ID; |
|
1378
|
+ localStorage.setItem("formfieldid", globalwpw.formfieldid); |
|
1379
|
+ globalwpw.formentry = json.entry; |
|
1380
|
+ localStorage.setItem("formentry", globalwpw.formentry); |
|
1381
|
+ var label = json.label; |
|
1382
|
+ if(json.type=='dropdown'){ |
|
1383
|
+ var html = ''; |
|
1384
|
+ jQuery.each(json.config.option, function(key, value){ |
|
1385
|
+ html += '<span class="qcld-chatbot-wildcard qcld-chatbot-formanswer" data-form-value="'+value.value+'" >'+value.label+'</span>'; |
|
1386
|
+ }) |
|
1387
|
+ wpwMsg.double(label, html); |
|
1388
|
+ }else if(json.type=='html'){ |
|
1389
|
+ wpwMsg.single(json.config.default); |
|
1390
|
+ globalwpw.formfieldid = json.ID; |
|
1391
|
+ localStorage.setItem("formfieldid", globalwpw.formfieldid); |
|
1392
|
+ globalwpw.formentry = json.entry; |
|
1393
|
+ localStorage.setItem("formentry", globalwpw.formentry); |
|
1394
|
+ setTimeout(function(){ |
|
1395
|
+ wpwTree.formbuilder(); |
|
1396
|
+ }, 500) |
|
1397
|
+ }else if(json.type=='checkbox'){ |
|
1398
|
+ jQuery('.qcld-chatbot-checkbox').val(''); |
|
1399
|
+ var html = ''; |
|
1400
|
+ jQuery.each(json.config.option, function(key, value){ |
|
1401
|
+ html += '<input type="checkbox" class="qcld-chatbot-checkbox" value="'+value.value+'">'+value.label+'<br>'; |
|
1402
|
+ }) |
|
1403
|
+ wpwMsg.double(label, html); |
|
1404
|
+ }else if(json.type=='date_picker'){ |
|
1405
|
+ if(json.hasOwnProperty("additional") && json.additional!=''){ |
|
1406
|
+ label +='<i class="wpbot_addition_label">'+json.additional+'</i>'; |
|
1407
|
+ } |
|
1408
|
+ wpwMsg.single(label); |
|
1409
|
+ jQuery('#wp-chatbot-editor').blur(); |
|
1410
|
+ jQuery('#wp-chatbot-editor').datetimepicker(); |
|
1411
|
+ }else if(json.type=='number'){ |
|
1412
|
+ if(json.hasOwnProperty("additional") && json.additional!=''){ |
|
1413
|
+ label +='<i class="wpbot_addition_label">'+json.additional+'</i>'; |
|
1414
|
+ } |
|
1415
|
+ wpwMsg.single(label); |
|
1416
|
+ jQuery('#wp-chatbot-editor').addClass("qcnumberfield"); |
|
1417
|
+ if(json.hasOwnProperty("config") && json.config.hasOwnProperty("min") && json.config.min>0){ |
|
1418
|
+ jQuery('#wp-chatbot-editor').attr("minlength", json.config.min); |
|
1419
|
+ } |
|
1420
|
+ if(json.hasOwnProperty("config") && json.config.hasOwnProperty("max") && json.config.max>0){ |
|
1421
|
+ jQuery('#wp-chatbot-editor').attr("maxlength", json.config.max); |
|
1422
|
+ } |
|
1423
|
+ }else if(json.type=='email'){ |
|
1424
|
+ if(json.hasOwnProperty("additional") && json.additional!=''){ |
|
1425
|
+ label +='<i class="wpbot_addition_label">'+json.additional+'</i>'; |
|
1426
|
+ } |
|
1427
|
+ wpwMsg.single(label); |
|
1428
|
+ jQuery('#wp-chatbot-editor').attr("type", "email"); |
|
1429
|
+ }else if(json.type=='url'){ |
|
1430
|
+ if(json.hasOwnProperty("additional") && json.additional!=''){ |
|
1431
|
+ label +='<i class="wpbot_addition_label">'+json.additional+'</i>'; |
|
1432
|
+ } |
|
1433
|
+ wpwMsg.single(label); |
|
1434
|
+ jQuery('#wp-chatbot-editor').attr("type", "url"); |
|
1435
|
+ }else if(json.type=='phone'){ |
|
1436
|
+ wpwMsg.single(label); |
|
1437
|
+ jQuery('#wp-chatbot-editor').addClass('qcphonebasicus'); |
|
1438
|
+ }else if(json.type=='calculation'){ |
|
1439
|
+ let calresult = json.calresult; |
|
1440
|
+ calresult = eval(calresult); |
|
1441
|
+ setTimeout(function(){ |
|
1442
|
+ var cal = (json.calbefore +' '+ calresult.toFixed(2) +' '+ json.calafter) |
|
1443
|
+ wpwTree.formbuilder(cal); |
|
1444
|
+ wpwMsg.single(cal); |
|
1445
|
+ }, globalwpw.settings.preLoadingTime) |
|
1446
|
+ }else if(json.type=='hidden'){ |
|
1447
|
+ var email = json.config.default; |
|
1448
|
+ if( globalwpw.settings.obj.order_login == 1 && json.slug=='email' ){ |
|
1449
|
+ email = globalwpw.settings.obj.order_email; |
|
1450
|
+ } |
|
1451
|
+ wpwTree.formbuilder(email); |
|
1452
|
+ }else if(json.type=='text'){ |
|
1453
|
+ wpwMsg.single(label); |
|
1454
|
+ }else{ |
|
1455
|
+ // wpwMsg.single(label); |
|
1456
|
+ } |
|
1457
|
+ }else{ |
|
1458
|
+ if($('.chatbot_intent_reload').length > 0){ |
|
1459
|
+ $('.chatbot_intent_reload').attr('data-step', 'complete'); |
|
1460
|
+ } |
|
1461
|
+ globalwpw.formfieldid = ''; |
|
1462
|
+ localStorage.setItem("formfieldid", globalwpw.formfieldid); |
|
1463
|
+ globalwpw.formStep='welcome'; |
|
1464
|
+ localStorage.setItem("formStep", globalwpw.formStep); |
|
1465
|
+ globalwpw.formid=''; |
|
1466
|
+ localStorage.setItem("formid", globalwpw.formid); |
|
1467
|
+ globalwpw.wildCard = 0; |
|
1468
|
+ localStorage.setItem("wildCard", globalwpw.wildCard); |
|
1469
|
+ globalwpw.formentry = 0; |
|
1470
|
+ localStorage.setItem("formentry", globalwpw.formentry); |
|
1471
|
+ var serviceOffer=wpwKits.randomMsg(globalwpw.settings.obj.wildcard_msg); |
|
1472
|
+ setTimeout(function(){ |
|
1473
|
+ wpwMsg.single_nobg('<span class="qcld-chatbot-wildcard qcld_back_to_start" data-wildcart="back">' + wpwKits.randomMsg(globalwpw.settings.obj.back_to_start) + '</span>'); |
|
1474
|
+ }, globalwpw.settings.preLoadingTime); |
|
1475
|
+ if(jQuery('.chatbot_intent_reload').length>0){ |
|
1476
|
+ jQuery('.chatbot_intent_reload').remove(); |
|
1477
|
+ } |
|
1478
|
+ } |
|
1479
|
+ }) |
|
1480
|
+ } |
|
1481
|
+ }, |
|
1482
|
+ formbuilder_force_complete:function(msg){ |
|
1483
|
+ //destroy date picker |
|
1484
|
+ //if ( jQuery.isFunction(jQuery.fn.datetimepicker) ) { |
|
1485
|
+ if ( typeof jQuery.fn.datetimepicker === 'function' ) { |
|
1486
|
+ jQuery('#wp-chatbot-editor').datetimepicker('destroy'); |
|
1487
|
+ } |
|
1488
|
+ jQuery('#wp-chatbot-editor').attr("type", "text"); |
|
1489
|
+ jQuery('#wp-chatbot-editor').prop("disabled", false); |
|
1490
|
+ jQuery('#wp-chatbot-editor').removeAttr("multiple"); |
|
1491
|
+ jQuery('#wp-chatbot-editor').removeClass('qcphonebasicus'); |
|
1492
|
+ jQuery('#wp-chatbot-editor').removeClass("qcnumberfield"); |
|
1493
|
+ jQuery('#wp-chatbot-editor').removeAttr("minlength"); |
|
1494
|
+ jQuery('#wp-chatbot-editor').removeAttr("maxlength"); |
|
1495
|
+ if(globalwpw.wildCard==7 && globalwpw.formStep=='field'){ |
|
1496
|
+ var data = {'action':'wpbot_capture_form_value','formid':globalwpw.formid, 'fieldid': globalwpw.formfieldid, 'answer': msg, 'entry':globalwpw.formentry, 'session': localStorage.getItem('botsessionid'), 'name':globalwpw.hasNameCookie, 'email':localStorage.getItem('shopperemail'), 'url': window.location.href, 'do_complete': 1}; |
|
1497
|
+ globalwpw.formfieldid = ''; |
|
1498
|
+ localStorage.setItem("formfieldid", globalwpw.formfieldid); |
|
1499
|
+ globalwpw.formStep='welcome'; |
|
1500
|
+ localStorage.setItem("formStep", globalwpw.formStep); |
|
1501
|
+ globalwpw.formid=''; |
|
1502
|
+ localStorage.setItem("formid", globalwpw.formid); |
|
1503
|
+ globalwpw.wildCard = 0; |
|
1504
|
+ localStorage.setItem("wildCard", globalwpw.wildCard); |
|
1505
|
+ globalwpw.formentry = 0; |
|
1506
|
+ localStorage.setItem("formentry", globalwpw.formentry); |
|
1507
|
+ wpwKits.ajax(data).done(function (response) { |
|
1508
|
+ var json=$.parseJSON(response); |
|
1509
|
+ if( json.status == 'complete' ){ |
|
1510
|
+ // |
|
1511
|
+ } |
|
1512
|
+ }) |
|
1513
|
+ } |
|
1514
|
+ }, |
|
1515
|
+ reset: function( msg ){ |
|
1516
|
+ if( globalwpw.wildCard == 25 && globalwpw.resetStep == 'welcome' ){ |
|
1517
|
+ var restWarning= globalwpw.settings.obj.reset; |
|
1518
|
+ var confirmBtn='<span class="qcld-chatbot-reset-btn" reset-data="yes" >'+globalwpw.settings.obj.yes+'</span> <span> '+globalwpw.settings.obj.or+' </span><span class="qcld-chatbot-reset-btn" reset-data="no">'+globalwpw.settings.obj.no+'</span>'; |
|
1519
|
+ globalwpw.resetStep = 'answer' |
|
1520
|
+ wpwMsg.double_nobg(restWarning,confirmBtn); |
|
1521
|
+ setTimeout(function(){ |
|
1522
|
+ // wpwKits.disableEditor(''); |
|
1523
|
+ }, 1500) |
|
1524
|
+ }else if( globalwpw.wildCard == 25 && globalwpw.resetStep == 'answer' ){ |
|
1525
|
+ if( msg.toLowerCase() == globalwpw.settings.obj.yes.toLowerCase() ){ |
|
1526
|
+ wpwKits.reset(); |
|
1527
|
+ var number = Math.random() // 0.9394456857981651 |
|
1528
|
+ number.toString(36); // '0.xtis06h6' |
|
1529
|
+ var id = number.toString(36).substr(2); // 'xtis06h6' |
|
1530
|
+ localStorage.setItem('botsessionid', id); |
|
1531
|
+ wpwWelcome.greeting(); |
|
1532
|
+ wpwKits.enableEditor(wpwKits.randomMsg(globalwpw.settings.obj.send_a_msg)); |
|
1533
|
+ }else if( msg.toLowerCase() == globalwpw.settings.obj.no.toLowerCase() ){ |
|
1534
|
+ |
|
1535
|
+ wpwAction.bot(globalwpw.settings.obj.sys_key_help.toLowerCase()); |
|
1536
|
+ wpwKits.enableEditor(wpwKits.randomMsg(globalwpw.settings.obj.send_a_msg)); |
|
1537
|
+ } |
|
1538
|
+ globalwpw.wildCard = 0; |
|
1539
|
+ globalwpw.resetStep = 'welcome' |
|
1540
|
+ } |
|
1541
|
+ }, |
|
1542
|
+ formatResponse: function(response) { |
|
1543
|
+ let cleanResponse = response.replace(/(\w+)\n/g,''); |
|
1544
|
+ cleanResponse = cleanResponse.replace(/(.*?)/gs, '<pre>$1</pre>'); |
|
1545
|
+ cleanResponse = cleanResponse.replace(/(.*?)/g, '<code>$1</code>'); |
|
1546
|
+ return cleanResponse; |
|
1547
|
+ }, |
|
1548
|
+ openai_reply:function(msg){ |
|
1549
|
+ |
|
1550
|
+ if(globalwpw.settings.obj.openai_enabled == 1){ |
|
1551
|
+ |
|
1552
|
+ var customAappend = globalwpw.settings.obj.qcld_openai_append_content; |
|
1553
|
+ var customMessage = customAappend ? msg + ' ' + customAappend : msg; |
|
1554
|
+ |
|
1555
|
+ qcldPushAiContext('user', customMessage); |
|
1556
|
+ |
|
1557
|
+ if(wp_chatbot_obj.is_stream_enabled == '1'){ |
|
1558
|
+ // Callers already append botPreloader before calling openai_reply |
|
1559
|
+ var streamData = { |
|
1560
|
+ action: 'qcld_stream_openai', |
|
1561
|
+ name: globalwpw.hasNameCookie, |
|
1562
|
+ keyword: customMessage, |
|
1563
|
+ active_ai_action: globalwpw.active_ai_action || "", |
|
1564
|
+ ai_history: JSON.stringify(globalwpw.aiContext), |
|
1565
|
+ nonce: qcld_chatbot_obj.nonce |
|
1566
|
+ }; |
|
1567
|
+ qcldStreamOpenAI(streamData); |
|
1568
|
+ } else { |
|
1569
|
+ var data = {'action':'qcld_openai_response','name':globalwpw.hasNameCookie,'keyword':customMessage,'active_ai_action':(globalwpw.active_ai_action || ""),'ai_history':JSON.stringify(globalwpw.aiContext),nonce: qcld_chatbot_obj.nonce}; |
|
1570
|
+ |
|
1571
|
+ wpwKits.ajax(data).done(function (res) { |
|
1572
|
+ if( res == '' || typeof res === 'object' ){ |
|
1573
|
+ var json = res; |
|
1574
|
+ }if(typeof res === 'string'){ |
|
1575
|
+ var json = $.parseJSON(res); |
|
1576
|
+ } |
|
1577
|
+ |
|
1578
|
+ if(json.status=='success'){ |
|
1579
|
+ qcldPushAiContext('assistant', json.message); |
|
1580
|
+ |
|
1581
|
+ var serviceOffer=wpwKits.randomMsg(globalwpw.settings.obj.support_option_again); |
|
1582
|
+ |
|
1583
|
+ setTimeout(function(){ |
|
1584
|
+ var isFormInProgress = qcldIsAiFormInProgress(); |
|
1585
|
+ if (json.message && json.message.indexOf('__AI_FORM_IN_PROGRESS__') !== -1) { |
|
1586
|
+ isFormInProgress = true; |
|
1587
|
+ json.message = json.message.replace(/__AI_FORM_IN_PROGRESS__/g, '').trim(); |
|
1588
|
+ } |
|
1589
|
+ if (json.message && (json.message.indexOf('AI_FORM_DATA') !== -1 || json.message.indexOf('ai-form-summary-card') !== -1)) { |
|
1590
|
+ isFormInProgress = false; |
|
1591
|
+ if (typeof globalwpw !== 'undefined') { |
|
1592
|
+ globalwpw.aiContext = []; |
|
1593
|
+ globalwpw.active_ai_action = ''; |
|
1594
|
+ globalwpw.qcld_ai_form_persisted_state = false; |
|
1595
|
+ } |
|
1596
|
+ } |
|
1597
|
+ |
|
1598
|
+ wpwMsg.single(json.message); |
|
1599
|
+ |
|
1600
|
+ if(!isFormInProgress && (globalwpw.settings.obj.qcld_disable_repited_startmenu != "1")){ |
|
1601
|
+ if(globalwpw.settings.obj.disable_repeatative!=1){ |
|
1602
|
+ setTimeout(function(){ |
|
1603
|
+ var serviceOffer=wpwKits.randomMsg(globalwpw.settings.obj.support_option_again); |
|
1604
|
+ if((globalwpw.settings.obj.qcld_disable_repited_startmenu != "1") && ((globalwpw.settings.obj.disable_back_to_start != '1' && globalwpw.settings.obj.skip_greetings_and_menu != 1))){ |
|
1605
|
+ wpwMsg.single_nobg('<span class="qcld-chatbot-wildcard qcld_back_to_start" data-wildcart="back">' + wpwKits.randomMsg(globalwpw.settings.obj.back_to_start) + '</span>'); |
|
1606
|
+ } |
|
1607
|
+ },globalwpw.settings.preLoadingTime) |
|
1608
|
+ }else{ |
|
1609
|
+ setTimeout(function(){ |
|
1610
|
+ if((globalwpw.settings.obj.qcld_disable_repited_startmenu != "1") && ((globalwpw.settings.obj.disable_back_to_start != '1' && globalwpw.settings.obj.skip_greetings_and_menu != 1))){ |
|
1611
|
+ wpwMsg.single_nobg('<span class="qcld-chatbot-wildcard qcld_back_to_start" data-wildcart="back">' + wpwKits.randomMsg(globalwpw.settings.obj.back_to_start) + '</span>'); |
|
1612
|
+ } |
|
1613
|
+ }, globalwpw.settings.preLoadingTime*2); |
|
1614
|
+ } |
|
1615
|
+ } |
|
1616
|
+ if(!isFormInProgress) { $(globalwpw.settings.messageContainer).find('.wp-chatbot-msg:last .qcld-like-dislike-icon').css('display', 'block'); } |
|
1617
|
+ |
|
1618
|
+ },globalwpw.settings.preLoadingTime) |
|
1619
|
+ } |
|
1620
|
+ }) |
|
1621
|
+ } |
|
1622
|
+ } |
|
1623
|
+ if(globalwpw.settings.obj.openrouter_enabled == 1){ |
|
1624
|
+ |
|
1625
|
+ var customAappend = globalwpw.settings.obj.qcld_openrouter_append_content; |
|
1626
|
+ var customprepend = globalwpw.settings.obj.qcld_openrouter_prepend_content; |
|
1627
|
+ var customMessage = customprepend ? customprepend + ' ' + msg : msg; |
|
1628
|
+ customMessage = customAappend ? customMessage + ' ' + customAappend : customMessage; |
|
1629
|
+ |
|
1630
|
+ qcldPushAiContext('user', customMessage); |
|
1631
|
+ |
|
1632
|
+ var data = {'action':'openrouter_response','name':globalwpw.hasNameCookie,'keyword':customMessage, 'active_ai_action':(globalwpw.active_ai_action || ""), nonce: qcld_chatbot_obj.nonce, ai_history: JSON.stringify(globalwpw.aiContext)}; |
|
1633
|
+ wpwKits.ajax(data).done(function (res) { |
|
1634
|
+ if( res == '' || typeof res === 'object' ){ |
|
1635
|
+ var json = res; |
|
1636
|
+ }if(typeof res === 'string'){ |
|
1637
|
+ var json = $.parseJSON(res); |
|
1638
|
+ } |
|
1639
|
+ if(json.status=='success'){ |
|
1640
|
+ qcldPushAiContext('assistant', json.message); |
|
1641
|
+ var serviceOffer=wpwKits.randomMsg(globalwpw.settings.obj.support_option_again); |
|
1642
|
+ |
|
1643
|
+ setTimeout(function(){ |
|
1644
|
+ var isFormInProgress = qcldIsAiFormInProgress(); |
|
1645
|
+ if (json.message && json.message.indexOf('__AI_FORM_IN_PROGRESS__') !== -1) { |
|
1646
|
+ isFormInProgress = true; |
|
1647
|
+ json.message = json.message.replace(/__AI_FORM_IN_PROGRESS__/g, '').trim(); |
|
1648
|
+ } |
|
1649
|
+ if (json.message && (json.message.indexOf('AI_FORM_DATA') !== -1 || json.message.indexOf('ai-form-summary-card') !== -1)) { |
|
1650
|
+ isFormInProgress = false; |
|
1651
|
+ if (typeof globalwpw !== 'undefined') { |
|
1652
|
+ globalwpw.aiContext = []; |
|
1653
|
+ globalwpw.active_ai_action = ''; |
|
1654
|
+ globalwpw.qcld_ai_form_persisted_state = false; |
|
1655
|
+ } |
|
1656
|
+ } |
|
1657
|
+ |
|
1658
|
+ wpwMsg.single(json.message); |
|
1659
|
+ |
|
1660
|
+ if(!isFormInProgress && globalwpw.settings.obj.qcld_disable_repited_startmenu != "1" ){ |
|
1661
|
+ if(globalwpw.settings.obj.disable_repeatative!=1){ |
|
1662
|
+ setTimeout(function(){ |
|
1663
|
+ var serviceOffer=wpwKits.randomMsg(globalwpw.settings.obj.support_option_again); |
|
1664
|
+ if((globalwpw.settings.obj.qcld_disable_repited_startmenu != "1") && ((globalwpw.settings.obj.disable_back_to_start != '1' && globalwpw.settings.obj.skip_greetings_and_menu != 1))){ |
|
1665
|
+ wpwMsg.single_nobg('<span class="qcld-chatbot-wildcard qcld_back_to_start" data-wildcart="back">' + wpwKits.randomMsg(globalwpw.settings.obj.back_to_start) + '</span>'); |
|
1666
|
+ } |
|
1667
|
+ },globalwpw.settings.preLoadingTime) |
|
1668
|
+ }else{ |
|
1669
|
+ setTimeout(function(){ |
|
1670
|
+ if((globalwpw.settings.obj.qcld_disable_repited_startmenu != "1") && ((globalwpw.settings.obj.disable_back_to_start != '1' && globalwpw.settings.obj.skip_greetings_and_menu != 1))){ |
|
1671
|
+ wpwMsg.single_nobg('<span class="qcld-chatbot-wildcard qcld_back_to_start" data-wildcart="back">' + wpwKits.randomMsg(globalwpw.settings.obj.back_to_start) + '</span>'); |
|
1672
|
+ } |
|
1673
|
+ }, globalwpw.settings.preLoadingTime*2); |
|
1674
|
+ } |
|
1675
|
+ } |
|
1676
|
+ if(!isFormInProgress) { $(globalwpw.settings.messageContainer).find('.wp-chatbot-msg:last .qcld-like-dislike-icon').css('display', 'block'); } |
|
1677
|
+ },globalwpw.settings.preLoadingTime) |
|
1678
|
+ }else{ |
|
1679
|
+ wpwMsg.single_nobg('<span class="qcld-chatbot-wildcard qcld_back_to_start" data-wildcart="back">' + 'Sorry, I encountered an error processing your AI request. Please check api key and try again later.' + '</span>'); |
|
1680
|
+ } |
|
1681
|
+ }) |
|
1682
|
+ } |
|
1683
|
+ |
|
1684
|
+ if(globalwpw.settings.obj.claude_enabled == 1){ |
|
1685
|
+ var customAappend = globalwpw.settings.obj.qcld_claude_append_content; |
|
1686
|
+ var customprepend = globalwpw.settings.obj.qcld_claude_prepend_content; |
|
1687
|
+ var customMessage = customprepend ? customprepend + ' ' + msg : msg; |
|
1688
|
+ customMessage = customAappend ? customMessage + ' ' + customAappend : customMessage; |
|
1689
|
+ |
|
1690
|
+ qcldPushAiContext('user', customMessage); |
|
1691
|
+ |
|
1692
|
+ var claudeStreamEnabled = globalwpw.settings.obj.qcld_claude_stream_enabled; |
|
1693
|
+ if (claudeStreamEnabled == "1") { |
|
1694
|
+ const claudeStreamData = { |
|
1695
|
+ action: "qcld_stream_claude", |
|
1696
|
+ name: globalwpw.hasNameCookie, |
|
1697
|
+ keyword: customMessage, |
|
1698
|
+ active_ai_action: globalwpw.active_ai_action || "", |
|
1699
|
+ ai_history: JSON.stringify(globalwpw.aiContext) |
|
1700
|
+ }; |
|
1701
|
+ streamClaude(claudeStreamData); |
|
1702
|
+ return; |
|
1703
|
+ } else { |
|
1704
|
+ var data = {'action':'claude_response','name':globalwpw.hasNameCookie,'keyword':customMessage, 'active_ai_action':(globalwpw.active_ai_action || ""), nonce: qcld_chatbot_obj.nonce, ai_history: JSON.stringify(globalwpw.aiContext)}; |
|
1705
|
+ wpwKits.ajax(data).done(function (res) { |
|
1706
|
+ if( res == '' || typeof res === 'object' ){ |
|
1707
|
+ var json = res; |
|
1708
|
+ }if(typeof res === 'string'){ |
|
1709
|
+ var json = $.parseJSON(res); |
|
1710
|
+ } |
|
1711
|
+ if(json.status=='success'){ |
|
1712
|
+ qcldPushAiContext('assistant', json.message); |
|
1713
|
+ var serviceOffer=wpwKits.randomMsg(globalwpw.settings.obj.support_option_again); |
|
1714
|
+ setTimeout(function(){ |
|
1715
|
+ var isFormInProgress = qcldIsAiFormInProgress(); |
|
1716
|
+ if (json.message && json.message.indexOf('__AI_FORM_IN_PROGRESS__') !== -1) { |
|
1717
|
+ isFormInProgress = true; |
|
1718
|
+ json.message = json.message.replace(/__AI_FORM_IN_PROGRESS__/g, '').trim(); |
|
1719
|
+ } |
|
1720
|
+ if (json.message && (json.message.indexOf('AI_FORM_DATA') !== -1 || json.message.indexOf('ai-form-summary-card') !== -1)) { |
|
1721
|
+ isFormInProgress = false; |
|
1722
|
+ if (typeof globalwpw !== 'undefined') { |
|
1723
|
+ globalwpw.aiContext = []; |
|
1724
|
+ globalwpw.active_ai_action = ''; |
|
1725
|
+ globalwpw.qcld_ai_form_persisted_state = false; |
|
1726
|
+ } |
|
1727
|
+ } |
|
1728
|
+ |
|
1729
|
+ wpwMsg.single(json.message); |
|
1730
|
+ if(!isFormInProgress && globalwpw.settings.obj.qcld_disable_repited_startmenu != "1" ){ |
|
1731
|
+ if(globalwpw.settings.obj.disable_repeatative!=1){ |
|
1732
|
+ setTimeout(function(){ |
|
1733
|
+ var serviceOffer=wpwKits.randomMsg(globalwpw.settings.obj.support_option_again); |
|
1734
|
+ if((globalwpw.settings.obj.qcld_disable_repited_startmenu != "1") && ((globalwpw.settings.obj.disable_back_to_start != '1' && globalwpw.settings.obj.skip_greetings_and_menu != 1))){ |
|
1735
|
+ wpwMsg.single_nobg('<span class="qcld-chatbot-wildcard qcld_back_to_start" data-wildcart="back">' + wpwKits.randomMsg(globalwpw.settings.obj.back_to_start) + '</span>'); |
|
1736
|
+ } |
|
1737
|
+ },globalwpw.settings.preLoadingTime) |
|
1738
|
+ }else{ |
|
1739
|
+ setTimeout(function(){ |
|
1740
|
+ if((globalwpw.settings.obj.qcld_disable_repited_startmenu != "1") && ((globalwpw.settings.obj.disable_back_to_start != '1' && globalwpw.settings.obj.skip_greetings_and_menu != 1))){ |
|
1741
|
+ wpwMsg.single_nobg('<span class="qcld-chatbot-wildcard qcld_back_to_start" data-wildcart="back">' + wpwKits.randomMsg(globalwpw.settings.obj.back_to_start) + '</span>'); |
|
1742
|
+ } |
|
1743
|
+ }, globalwpw.settings.preLoadingTime*2); |
|
1744
|
+ } |
|
1745
|
+ } |
|
1746
|
+ if(!isFormInProgress) { $(globalwpw.settings.messageContainer).find('.wp-chatbot-msg:last .qcld-like-dislike-icon').css('display', 'block'); } |
|
1747
|
+ },globalwpw.settings.preLoadingTime) |
|
1748
|
+ }else{ |
|
1749
|
+ wpwMsg.single_nobg('<span class="qcld-chatbot-wildcard qcld_back_to_start" data-wildcart="back">' + 'Sorry, I encountered an error processing your AI request. Please check api key and try again later.' + '</span>'); |
|
1750
|
+ } |
|
1751
|
+ }); |
|
1752
|
+ } |
|
1753
|
+ } |
|
1754
|
+ if(globalwpw.settings.obj.gemini_enabled == 1){ |
|
1755
|
+ var customAappend = globalwpw.settings.obj.qcld_openrouter_append_content; |
|
1756
|
+ var customprepend = globalwpw.settings.obj.qcld_openrouter_prepend_content; |
|
1757
|
+ var customMessage = customprepend ? customprepend + ' ' + msg : msg; |
|
1758
|
+ customMessage = customAappend ? customMessage + ' ' + customAappend : customMessage; |
|
1759
|
+ |
|
1760
|
+ qcldPushAiContext('user', customMessage); |
|
1761
|
+ |
|
1762
|
+ var data = {'action':'qcld_gemini_response','name':globalwpw.hasNameCookie,'keyword':customMessage, 'active_ai_action':(globalwpw.active_ai_action || ""), nonce: qcld_chatbot_obj.nonce, ai_history: JSON.stringify(globalwpw.aiContext)}; |
|
1763
|
+ wpwKits.ajax(data).done(function (res) { |
|
1764
|
+ if( res == '' || typeof res === 'object' ){ |
|
1765
|
+ var json = res; |
|
1766
|
+ }if(typeof res === 'string'){ |
|
1767
|
+ var json = $.parseJSON(res); |
|
1768
|
+ } |
|
1769
|
+ |
|
1770
|
+ if(json.status=='success'){ |
|
1771
|
+ qcldPushAiContext('assistant', json.message); |
|
1772
|
+ var serviceOffer=wpwKits.randomMsg(globalwpw.settings.obj.support_option_again); |
|
1773
|
+ |
|
1774
|
+ setTimeout(function(){ |
|
1775
|
+ var isFormInProgress = qcldIsAiFormInProgress(); |
|
1776
|
+ if (json.message && json.message.indexOf('__AI_FORM_IN_PROGRESS__') !== -1) { |
|
1777
|
+ isFormInProgress = true; |
|
1778
|
+ json.message = json.message.replace(/__AI_FORM_IN_PROGRESS__/g, '').trim(); |
|
1779
|
+ } |
|
1780
|
+ if (json.message && (json.message.indexOf('AI_FORM_DATA') !== -1 || json.message.indexOf('ai-form-summary-card') !== -1)) { |
|
1781
|
+ isFormInProgress = false; |
|
1782
|
+ if (typeof globalwpw !== 'undefined') { |
|
1783
|
+ globalwpw.aiContext = []; |
|
1784
|
+ globalwpw.active_ai_action = ''; |
|
1785
|
+ globalwpw.qcld_ai_form_persisted_state = false; |
|
1786
|
+ } |
|
1787
|
+ } |
|
1788
|
+ |
|
1789
|
+ wpwMsg.single(json.message); |
|
1790
|
+ |
|
1791
|
+ if(!isFormInProgress && (globalwpw.settings.obj.qcld_disable_repited_startmenu != "1")){ |
|
1792
|
+ if((globalwpw.settings.obj.qcld_disable_repited_startmenu != "1") && ((globalwpw.settings.obj.disable_back_to_start != '1' && globalwpw.settings.obj.skip_greetings_and_menu != 1))){ |
|
1793
|
+ setTimeout(function(){ |
|
1794
|
+ var serviceOffer=wpwKits.randomMsg(globalwpw.settings.obj.support_option_again); |
|
1795
|
+ if((globalwpw.settings.obj.qcld_disable_start_menu != "1" && (globalwpw.settings.obj.disable_back_to_start != '1' && globalwpw.settings.obj.skip_greetings_and_menu != 1))){ |
|
1796
|
+ wpwMsg.single_nobg('<span class="qcld-chatbot-wildcard qcld_back_to_start" data-wildcart="back">' + wpwKits.randomMsg(globalwpw.settings.obj.back_to_start) + '</span>'); |
|
1797
|
+ } |
|
1798
|
+ },globalwpw.settings.preLoadingTime) |
|
1799
|
+ }else{ |
|
1800
|
+ setTimeout(function(){ |
|
1801
|
+ if((globalwpw.settings.obj.qcld_disable_repited_startmenu != "1" && (globalwpw.settings.obj.disable_back_to_start != '1' && globalwpw.settings.obj.skip_greetings_and_menu != 1))){ |
|
1802
|
+ wpwMsg.single_nobg('<span class="qcld-chatbot-wildcard qcld_back_to_start" data-wildcart="back">' + wpwKits.randomMsg(globalwpw.settings.obj.back_to_start) + '</span>'); |
|
1803
|
+ } |
|
1804
|
+ }, globalwpw.settings.preLoadingTime*2); |
|
1805
|
+ } |
|
1806
|
+ } |
|
1807
|
+ },globalwpw.settings.preLoadingTime) |
|
1808
|
+ }else{ |
|
1809
|
+ wpwMsg.single_nobg('<span class="qcld-chatbot-wildcard qcld_back_to_start" data-wildcart="back">' + 'Sorry, I encountered an error processing your AI request. Please check api key and try again later.' + '</span>'); |
|
1810
|
+ } |
|
1811
|
+ }) |
|
1812
|
+ } |
|
1813
|
+ if(globalwpw.settings.obj.grok_enabled == 1){ |
|
1814
|
+ var customMessage = msg; |
|
1815
|
+ customMessage = customAappend ? customMessage + ' ' + customAappend : customMessage; |
|
1816
|
+ |
|
1817
|
+ qcldPushAiContext('user', customMessage); |
|
1818
|
+ |
|
1819
|
+ var data = {'action':'qcld_grok_response','name':globalwpw.hasNameCookie,'keyword':customMessage, 'active_ai_action':(globalwpw.active_ai_action || ""), nonce: qcld_chatbot_obj.nonce, ai_history: JSON.stringify(globalwpw.aiContext)}; |
|
1820
|
+ wpwKits.ajax(data).done(function (res) { |
|
1821
|
+ if( res == '' || typeof res === 'object' ){ |
|
1822
|
+ var json = res; |
|
1823
|
+ }if(typeof res === 'string'){ |
|
1824
|
+ var json = $.parseJSON(res); |
|
1825
|
+ } |
|
1826
|
+ |
|
1827
|
+ if(json.status=='success'){ |
|
1828
|
+ qcldPushAiContext('assistant', json.message); |
|
1829
|
+ var serviceOffer=wpwKits.randomMsg(globalwpw.settings.obj.support_option_again); |
|
1830
|
+ |
|
1831
|
+ setTimeout(function(){ |
|
1832
|
+ var isFormInProgress = qcldIsAiFormInProgress(); |
|
1833
|
+ if (json.message && json.message.indexOf('__AI_FORM_IN_PROGRESS__') !== -1) { |
|
1834
|
+ isFormInProgress = true; |
|
1835
|
+ json.message = json.message.replace(/__AI_FORM_IN_PROGRESS__/g, '').trim(); |
|
1836
|
+ } |
|
1837
|
+ if (json.message && (json.message.indexOf('AI_FORM_DATA') !== -1 || json.message.indexOf('ai-form-summary-card') !== -1)) { |
|
1838
|
+ isFormInProgress = false; |
|
1839
|
+ if (typeof globalwpw !== 'undefined') { |
|
1840
|
+ globalwpw.aiContext = []; |
|
1841
|
+ globalwpw.active_ai_action = ''; |
|
1842
|
+ globalwpw.qcld_ai_form_persisted_state = false; |
|
1843
|
+ } |
|
1844
|
+ } |
|
1845
|
+ |
|
1846
|
+ wpwMsg.single(json.message); |
|
1847
|
+ |
|
1848
|
+ if(!isFormInProgress && (globalwpw.settings.obj.qcld_disable_repited_startmenu != "1")){ |
|
1849
|
+ if((globalwpw.settings.obj.qcld_disable_repited_startmenu != "1") && ((globalwpw.settings.obj.disable_back_to_start != '1' && globalwpw.settings.obj.skip_greetings_and_menu != 1))){ |
|
1850
|
+ setTimeout(function(){ |
|
1851
|
+ var serviceOffer=wpwKits.randomMsg(globalwpw.settings.obj.support_option_again); |
|
1852
|
+ if((globalwpw.settings.obj.qcld_disable_start_menu != "1" && (globalwpw.settings.obj.disable_back_to_start != '1' && globalwpw.settings.obj.skip_greetings_and_menu != 1))){ |
|
1853
|
+ wpwMsg.single_nobg('<span class="qcld-chatbot-wildcard qcld_back_to_start" data-wildcart="back">' + wpwKits.randomMsg(globalwpw.settings.obj.back_to_start) + '</span>'); |
|
1854
|
+ } |
|
1855
|
+ },globalwpw.settings.preLoadingTime) |
|
1856
|
+ }else{ |
|
1857
|
+ setTimeout(function(){ |
|
1858
|
+ if((globalwpw.settings.obj.qcld_disable_repited_startmenu != "1" && (globalwpw.settings.obj.disable_back_to_start != '1' && globalwpw.settings.obj.skip_greetings_and_menu != 1))){ |
|
1859
|
+ wpwMsg.single_nobg('<span class="qcld-chatbot-wildcard qcld_back_to_start" data-wildcart="back">' + wpwKits.randomMsg(globalwpw.settings.obj.back_to_start) + '</span>'); |
|
1860
|
+ } |
|
1861
|
+ }, globalwpw.settings.preLoadingTime*2); |
|
1862
|
+ } |
|
1863
|
+ } |
|
1864
|
+ },globalwpw.settings.preLoadingTime) |
|
1865
|
+ }else{ |
|
1866
|
+ wpwMsg.single_nobg('<span class="qcld-chatbot-wildcard qcld_back_to_start" data-wildcart="back">' + 'Sorry, I encountered an error processing your AI request. Please check api key and try again later.' + '</span>'); |
|
1867
|
+ } |
|
1868
|
+ }) |
|
1869
|
+ } |
|
1870
|
+ }, |
|
1871
|
+ site_search:function(msg){ |
|
1872
|
+ msg1 = wpwKits.filterStopWords(msg); |
|
1873
|
+ var data = {'action':'wpbo_search_site','name':globalwpw.hasNameCookie,'keyword':msg1, 'security':wp_chatbot_obj.ajax_nonce}; |
|
1874
|
+ wpwKits.ajax(data).done(function (res) { |
|
1875
|
+ var json=$.parseJSON(res); |
|
1876
|
+ if(!qcldIsAiFormInProgress()) { $(globalwpw.settings.messageContainer).find('.wp-chatbot-msg:last .qcld-like-dislike-icon').css('display', 'block'); } |
|
1877
|
+ |
|
1878
|
+ if(json.status=='success'){ |
|
1879
|
+ if((globalwpw.settings.obj.disable_back_to_start != '1' && globalwpw.settings.obj.skip_greetings_and_menu != 1)){ |
|
1880
|
+ wpwMsg.triple_nobg( wp_chatbot_obj.found_result_message,json.html,'<span class="qcld-chatbot-wildcard" data-wildcart="back">' + wpwKits.randomMsg(globalwpw.settings.obj.back_to_start) + '</span>' ); |
|
1881
|
+ }else{ |
|
1882
|
+ wpwMsg.double_nobg( wp_chatbot_obj.found_result_message,json.html); |
|
1883
|
+ } |
|
1884
|
+ }else if( (globalwpw.settings.obj.openai_enabled == 1) || (wp_chatbot_obj.openai_enabled == 1) || (globalwpw.settings.obj.openrouter_enabled == 1) || (wp_chatbot_obj.openrouter_enabled == 1) || (globalwpw.settings.obj.gemini_enabled == 1) || (wp_chatbot_obj.gemini_enabled == 1) || (globalwpw.settings.obj.grok_enabled == 1) || (wp_chatbot_obj.grok_enabled == 1) || (wp_chatbot_obj.claude_enabled == 1) || (globalwpw.settings.obj.claude_enabled == 1) ){ |
|
1885
|
+ if($(globalwpw.settings.messageLastChild+' .wp-chatbot-comment-loader').length==0){ |
|
1886
|
+ $(globalwpw.settings.messageContainer).append(wpwKits.botPreloader()); |
|
1887
|
+ } |
|
1888
|
+ wpwTree.openai_reply(msg); |
|
1889
|
+ }else{ |
|
1890
|
+ if((globalwpw.settings.obj.disable_back_to_start != '1' && globalwpw.settings.obj.skip_greetings_and_menu != 1)){ |
|
1891
|
+ wpwMsg.double_nobg( wpwKits.randomMsg(wp_chatbot_obj.product_fail ),'<span class="qcld-chatbot-wildcard qcld_back_to_start" data-wildcart="back">' + wpwKits.randomMsg(globalwpw.settings.obj.back_to_start) + '</span>'); |
|
1892
|
+ }else{ |
|
1893
|
+ wpwMsg.single( wpwKits.randomMsg(wp_chatbot_obj.product_fail )); |
|
1894
|
+ } |
|
1895
|
+ } |
|
1896
|
+ }) |
|
1897
|
+ } |
|
1898
|
+ }; |
|
1899
|
+ /* |
|
1900
|
+ * wpwbot Actions are divided into two part |
|
1901
|
+ * shopper will response after initialize message, |
|
1902
|
+ * then based on shopper activities shopper will act. |
|
1903
|
+ */ |
|
1904
|
+ var wpwAction={ |
|
1905
|
+ findkey:function(array, msg){ |
|
1906
|
+ var index = -1; |
|
1907
|
+ $.each( array, function( key, value ) { |
|
1908
|
+ value = jQuery.map(value, function(n,i){return n.toLowerCase();}); |
|
1909
|
+ if(value.indexOf(msg.toLowerCase()) > -1){ |
|
1910
|
+ index = key; |
|
1911
|
+ return false; |
|
1912
|
+ } |
|
1913
|
+ }); |
|
1914
|
+ return index; |
|
1915
|
+ }, |
|
1916
|
+ bot:function(msg){ |
|
1917
|
+ var simple_response_intent = globalwpw.settings.obj.simple_response_intent; |
|
1918
|
+ if(simple_response_intent.length>0){ |
|
1919
|
+ simple_response_intent = jQuery.map(simple_response_intent, function(n,i){return n.toLowerCase();}); |
|
1920
|
+ } |
|
1921
|
+ var allformname = jQuery.map(globalwpw.settings.obj.forms, function(n,i){return n.toLowerCase();}); |
|
1922
|
+ var allformcommand = globalwpw.settings.obj.form_commands; |
|
1923
|
+ if(globalwpw.wildcardsHelp.indexOf(msg.toLowerCase())>-1){ |
|
1924
|
+ |
|
1925
|
+ if(globalwpw.wildCard==7){ |
|
1926
|
+ wpwTree.formbuilder_force_complete( msg ); |
|
1927
|
+ } |
|
1928
|
+ if(msg.toLowerCase()==globalwpw.settings.obj.sys_key_help.toLowerCase()){ |
|
1929
|
+ |
|
1930
|
+ globalwpw.wildCard=0; |
|
1931
|
+ var serviceOffer=wpwKits.randomMsg(globalwpw.settings.obj.wildcard_msg); |
|
1932
|
+ wpwMsg.double_nobg(serviceOffer,globalwpw.wildcards); |
|
1933
|
+ } |
|
1934
|
+ if(msg.toLowerCase()==globalwpw.settings.obj.sys_key_support.toLowerCase()){ |
|
1935
|
+ globalwpw.wildCard=1; |
|
1936
|
+ globalwpw.supportStep='welcome'; |
|
1937
|
+ wpwTree.support(msg); |
|
1938
|
+ } |
|
1939
|
+ // if(msg.toLowerCase()==globalwpw.settings.obj.sys_key_product.toLowerCase()){ |
|
1940
|
+ // globalwpw.wildCard=20; |
|
1941
|
+ // globalwpw.productStep='asking'; |
|
1942
|
+ // // wpwTree.product(msg); |
|
1943
|
+ // } |
|
1944
|
+ if(globalwpw.settings.obj.woocommerce){ |
|
1945
|
+ if(msg.toLowerCase()==globalwpw.settings.obj.sys_key_catalog.toLowerCase()){ |
|
1946
|
+ globalwpw.wildCard=20; |
|
1947
|
+ globalwpw.productStep='search'; |
|
1948
|
+ wpwKits.sugestCat(); |
|
1949
|
+ } |
|
1950
|
+ if(msg.toLowerCase()==globalwpw.settings.obj.sys_key_order.toLowerCase()){ |
|
1951
|
+ globalwpw.wildCard=21; |
|
1952
|
+ globalwpw.orderStep='welcome'; |
|
1953
|
+ wpwTree.order(msg); |
|
1954
|
+ } |
|
1955
|
+ } |
|
1956
|
+ if( globalwpw.settings.obj.open_a_ticket && msg.toLowerCase()==globalwpw.settings.obj.open_a_ticket.toLowerCase() && globalwpw.settings.obj.ticket_url!=''){ |
|
1957
|
+ //comming |
|
1958
|
+ window.open(globalwpw.settings.obj.ticket_url, '_blank'); |
|
1959
|
+ wpwKits.enableEditor(wpwKits.randomMsg(globalwpw.settings.obj.send_a_msg)); |
|
1960
|
+ } |
|
1961
|
+ if(msg.toLowerCase()==globalwpw.settings.obj.sys_key_reset.toLowerCase()){ |
|
1962
|
+ globalwpw.wildCard=25; |
|
1963
|
+ globalwpw.resetStep='welcome'; |
|
1964
|
+ wpwTree.reset(msg); |
|
1965
|
+ } |
|
1966
|
+ if(msg.toLowerCase()==globalwpw.settings.obj.sys_key_email.toLowerCase()){ |
|
1967
|
+ // var shopperChoice=$(this).text(); |
|
1968
|
+ wpwMsg.shopper_choice(globalwpw.settings.obj.sys_key_email.toLowerCase()); |
|
1969
|
+ //Then ask email address |
|
1970
|
+ if(typeof(globalwpw.hasNameCookie)=='undefined'|| globalwpw.hasNameCookie==''){ |
|
1971
|
+ var shopperName= globalwpw.settings.obj.shopper_demo_name; |
|
1972
|
+ }else{ |
|
1973
|
+ var shopperName=globalwpw.hasNameCookie; |
|
1974
|
+ } |
|
1975
|
+ var ask_msg = wpwKits.randomMsg(globalwpw.settings.obj.asking_email); |
|
1976
|
+ var askEmail = (globalwpw.settings.obj.skip_wp_greetings=='1' || globalwpw.settings.obj.skip_greetings_and_menu =='1') ? wpwKits.randomMsg(globalwpw.settings.obj.hello)+' '+ ask_msg : wpwKits.randomMsg(globalwpw.settings.obj.hello)+' '+shopperName+'! '+ ask_msg; |
|
1977
|
+ wpwMsg.single(askEmail); |
|
1978
|
+ globalwpw.supportStep='email'; |
|
1979
|
+ globalwpw.wildCard=1; |
|
1980
|
+ localStorage.setItem("wildCard", globalwpw.wildCard); |
|
1981
|
+ localStorage.setItem("supportStep", globalwpw.supportStep); |
|
1982
|
+ } |
|
1983
|
+ if( globalwpw.settings.obj.sys_key_livechat && msg.toLowerCase()==globalwpw.settings.obj.sys_key_livechat.toLowerCase()){ |
|
1984
|
+ wpwKits.enableEditor(wpwKits.randomMsg(globalwpw.settings.obj.send_a_msg)); |
|
1985
|
+ if(globalwpw.settings.obj.is_livechat_active){ |
|
1986
|
+ if(globalwpw.settings.obj.disable_livechat_operator_offline==1){ |
|
1987
|
+ if(globalwpw.settings.obj.is_operator_online==1){ |
|
1988
|
+ $(globalwpw.settings.messageWrapper).html(localStorage.getItem("wpwHitory")); |
|
1989
|
+ if($('#wbca_signup_fullname').length>0){ |
|
1990
|
+ if(localStorage.getItem('shopper')!==null){ |
|
1991
|
+ $('#wbca_signup_fullname').val(localStorage.getItem('shopper')); |
|
1992
|
+ } |
|
1993
|
+ if(localStorage.getItem('shopperemail')!==null){ |
|
1994
|
+ $('#wbca_signup_email').val(localStorage.getItem('shopperemail')); |
|
1995
|
+ } |
|
1996
|
+ } |
|
1997
|
+ $("#wp-chatbot-board-container").removeClass('active-chat-board'); |
|
1998
|
+ $('.wp-chatbot-container').hide(); |
|
1999
|
+ $('.wpbot-saas-live-chat').show(); |
|
2000
|
+ } |
|
2001
|
+ }else{ |
|
2002
|
+ $(globalwpw.settings.messageWrapper).html(localStorage.getItem("wpwHitory")); |
|
2003
|
+ if($('#wbca_signup_fullname').length>0){ |
|
2004
|
+ if(localStorage.getItem('shopper')!==null){ |
|
2005
|
+ $('#wbca_signup_fullname').val(localStorage.getItem('shopper')); |
|
2006
|
+ } |
|
2007
|
+ if(localStorage.getItem('shopperemail')!==null){ |
|
2008
|
+ $('#wbca_signup_email').val(localStorage.getItem('shopperemail')); |
|
2009
|
+ } |
|
2010
|
+ } |
|
2011
|
+ $("#wp-chatbot-board-container").removeClass('active-chat-board'); |
|
2012
|
+ $('.wp-chatbot-container').hide(); |
|
2013
|
+ $('.wpbot-saas-live-chat').show(); |
|
2014
|
+ } |
|
2015
|
+ } |
|
2016
|
+ } |
|
2017
|
+ }else if(allformname.indexOf(msg.toLowerCase()) > -1 || this.findkey(allformcommand, msg)> -1){ |
|
2018
|
+ //Form builder commands form name |
|
2019
|
+ if(globalwpw.wildCard==7){ |
|
2020
|
+ wpwTree.formbuilder_force_complete( msg ); |
|
2021
|
+ } |
|
2022
|
+ var index = (allformname.indexOf(msg.toLowerCase()) > -1?allformname.indexOf(msg.toLowerCase()):this.findkey(allformcommand, msg)); |
|
2023
|
+ var formid=globalwpw.settings.obj.form_ids[index]; |
|
2024
|
+ globalwpw.wildCard=7; |
|
2025
|
+ globalwpw.formStep='welcome'; |
|
2026
|
+ wpwTree.formbuilder(formid); |
|
2027
|
+ }else if(simple_response_intent.indexOf(msg.toLowerCase()) > -1){ |
|
2028
|
+ if(globalwpw.wildCard==7){ |
|
2029
|
+ wpwTree.formbuilder_force_complete( msg ); |
|
2030
|
+ } |
|
2031
|
+ var data = {'action':'wpbo_search_responseby_intent','name':globalwpw.hasNameCookie,'keyword':msg, 'language':globalwpw.settings.obj.language}; |
|
2032
|
+ if($(globalwpw.settings.messageLastChild+' .wp-chatbot-comment-loader').length==0){ |
|
2033
|
+ $(globalwpw.settings.messageContainer).append(wpwKits.botPreloader()); |
|
2034
|
+ } |
|
2035
|
+ wpwKits.ajax(data).done(function (response) { |
|
2036
|
+ var json=$.parseJSON(response); |
|
2037
|
+ if(json.status=='success'){ |
|
2038
|
+ wpwMsg.single(json.html); |
|
2039
|
+ var serviceOffer=wpwKits.randomMsg(globalwpw.settings.obj.wildcard_msg); |
|
2040
|
+ if( typeof(json.followup)!=="undefined" && json.followup!='' ){ |
|
2041
|
+ setTimeout(function(){ |
|
2042
|
+ wpwMsg.single(json.followup); |
|
2043
|
+ }, globalwpw.settings.preLoadingTime*2); |
|
2044
|
+ }else{ |
|
2045
|
+ |
|
2046
|
+ setTimeout(function(){ |
|
2047
|
+ if(!qcldIsAiFormInProgress()) { $(globalwpw.settings.messageContainer).find('.wp-chatbot-msg:last .qcld-like-dislike-icon').css('display', 'block'); } |
|
2048
|
+ if((globalwpw.settings.obj.disable_back_to_start != '1' && globalwpw.settings.obj.skip_greetings_and_menu != 1)){ |
|
2049
|
+ wpwMsg.single_nobg('<span class="qcld-chatbot-wildcard qcld_back_to_start" data-wildcart="back">' + wpwKits.randomMsg(globalwpw.settings.obj.back_to_start) + '</span>'); |
|
2050
|
+ } |
|
2051
|
+ }, globalwpw.settings.preLoadingTime*2); |
|
2052
|
+ } |
|
2053
|
+ } |
|
2054
|
+ }) |
|
2055
|
+ }else{ |
|
2056
|
+ /* |
|
2057
|
+ * Greeting part |
|
2058
|
+ * bot action |
|
2059
|
+ */ |
|
2060
|
+ if(globalwpw.wildCard==0){ |
|
2061
|
+ //When intialize 1 and don't have cookies then keep the name of shooper in in cookie |
|
2062
|
+ if(globalwpw.initialize==1 && !localStorage.getItem('shopper') && globalwpw.wildCard==0){ |
|
2063
|
+ wpwTree.greeting(msg); |
|
2064
|
+ }else if(globalwpw.settings.obj.ai_df_enable==1 && globalwpw.df_status_lock==0){ |
|
2065
|
+ wpwTree.greeting(msg); |
|
2066
|
+ }else if(localStorage.getItem('default_asking_email')){ |
|
2067
|
+ wpwTree.greeting(msg); |
|
2068
|
+ }else if(localStorage.getItem('default_asking_phone')){ |
|
2069
|
+ wpwTree.greeting(msg); |
|
2070
|
+ }else{ |
|
2071
|
+ //simple text response wrapper |
|
2072
|
+ |
|
2073
|
+ var data = {'action':'wpbo_search_response','name':globalwpw.hasNameCookie,'keyword':msg, 'language':globalwpw.settings.obj.language}; |
|
2074
|
+ if(wp_chatbot_obj.disable_site_search == 1){ |
|
2075
|
+ if($(globalwpw.settings.messageLastChild+' .wp-chatbot-comment-loader').length==0){ |
|
2076
|
+ $(globalwpw.settings.messageContainer).append(wpwKits.botPreloader()); |
|
2077
|
+ } |
|
2078
|
+ } |
|
2079
|
+ wpwKits.ajax(data).done(function (response) { |
|
2080
|
+ var json=$.parseJSON(response); |
|
2081
|
+ |
|
2082
|
+ if(json.status=='fail' && json.data !==''){ |
|
2083
|
+ |
|
2084
|
+ if(wp_chatbot_obj.disable_site_search != 1){ |
|
2085
|
+ wpwTree.site_search(msg) |
|
2086
|
+ } |
|
2087
|
+ else if( (globalwpw.settings.obj.openai_enabled == 1) || (wp_chatbot_obj.openai_enabled == 1) || (globalwpw.settings.obj.openrouter_enabled == 1) || (wp_chatbot_obj.openrouter_enabled == 1) || (globalwpw.settings.obj.gemini_enabled == 1) || (wp_chatbot_obj.gemini_enabled == 1) || (globalwpw.settings.obj.grok_enabled == 1) || (wp_chatbot_obj.grok_enabled == 1) || (wp_chatbot_obj.claude_enabled == 1) || (globalwpw.settings.obj.claude_enabled == 1) ){ |
|
2088
|
+ wpwTree.openai_reply(msg) |
|
2089
|
+ }else{ |
|
2090
|
+ wpwMsg.single(globalwpw.settings.obj.empty_filter_msg); |
|
2091
|
+ } |
|
2092
|
+ }else if(json.status=='success'){ |
|
2093
|
+ if(typeof(json.category)!=="undefined" && json.category){ |
|
2094
|
+ var question=''; |
|
2095
|
+ $.each(json.data, function (i, obj) { |
|
2096
|
+ question += '<span class="qcld-chatbot-wildcard qcld_simple_txt_response" data-strid="'+ obj.id +'">'+ obj.query +'</span>'; |
|
2097
|
+ }); |
|
2098
|
+ wpwMsg.single_nobg(question); |
|
2099
|
+ } |
|
2100
|
+ else if(json.multiple){ |
|
2101
|
+ var question=''; |
|
2102
|
+ $.each(json.data, function (i, obj) { |
|
2103
|
+ question += '<span class="qcld-chatbot-wildcard qcld_simple_txt_response" data-strid="'+ obj.id +'">'+ obj.query +'</span>'; |
|
2104
|
+ }); |
|
2105
|
+ wpwMsg.double_nobg(wpwKits.randomMsg(globalwpw.settings.obj.did_you_mean),question); |
|
2106
|
+ }else{ |
|
2107
|
+ wpwMsg.single(json.data[0].response); |
|
2108
|
+ var serviceOffer=wpwKits.randomMsg(globalwpw.settings.obj.wildcard_msg); |
|
2109
|
+ if( typeof(json.data[0].followup)!=="undefined" && json.data[0].followup!='' ){ |
|
2110
|
+ setTimeout(function(){ |
|
2111
|
+ wpwMsg.single(json.data[0].followup); |
|
2112
|
+ }, globalwpw.settings.preLoadingTime*2); |
|
2113
|
+ }else{ |
|
2114
|
+ // if(globalwpw.settings.obj.disable_repeatative!=1){ |
|
2115
|
+ // setTimeout(function(){ |
|
2116
|
+ // wpwMsg.double_nobg(serviceOffer, globalwpw.wildcards); |
|
2117
|
+ // }, globalwpw.settings.preLoadingTime*2); |
|
2118
|
+ // }else{ |
|
2119
|
+ setTimeout(function(){ |
|
2120
|
+ if(!qcldIsAiFormInProgress()) { $(globalwpw.settings.messageContainer).find('.wp-chatbot-msg:last .qcld-like-dislike-icon').css('display', 'block'); } |
|
2121
|
+ if( (globalwpw.settings.obj.disable_back_to_start != '1' && globalwpw.settings.obj.skip_greetings_and_menu != 1)){ |
|
2122
|
+ wpwMsg.single_nobg('<span class="qcld-chatbot-wildcard qcld_back_to_start" data-wildcart="back">' + wpwKits.randomMsg(globalwpw.settings.obj.back_to_start) + '</span>'); |
|
2123
|
+ } |
|
2124
|
+ }, globalwpw.settings.preLoadingTime*2); |
|
2125
|
+ // } |
|
2126
|
+ } |
|
2127
|
+ } |
|
2128
|
+ }else{ |
|
2129
|
+ //Default intents site search |
|
2130
|
+ msg = wpwKits.filterStopWords(msg); |
|
2131
|
+ if(globalwpw.settings.obj.woocommerce){ |
|
2132
|
+ var data = {'action':'qcld_wb_chatbot_keyword', 'keyword':msg}; |
|
2133
|
+ //Products by string search ajax handler. |
|
2134
|
+ if($(globalwpw.settings.messageLastChild+' .wp-chatbot-comment-loader').length==0){ |
|
2135
|
+ $(globalwpw.settings.messageContainer).append(wpwKits.botPreloader()); |
|
2136
|
+ } |
|
2137
|
+ wpwKits.ajax(data).done(function( response ) { |
|
2138
|
+ if(response.product_num==0){ |
|
2139
|
+ if(msg!='' && globalwpw.settings.obj.disable_sitesearch==''){ |
|
2140
|
+ msg = wpwKits.filterStopWords(msg); |
|
2141
|
+ var data = {'action':'wpbo_search_site','name':globalwpw.hasNameCookie,'keyword':msg, 'security':wp_chatbot_obj.ajax_nonce}; |
|
2142
|
+ if($(globalwpw.settings.messageLastChild+' .wp-chatbot-comment-loader').length==0){ |
|
2143
|
+ $(globalwpw.settings.messageContainer).append(wpwKits.botPreloader()); |
|
2144
|
+ } |
|
2145
|
+ wpwKits.ajax(data).done(function (response) { |
|
2146
|
+ var json=$.parseJSON(response); |
|
2147
|
+ if(json.status=='success'){ |
|
2148
|
+ // wpwMsg.single(wp_chatbot_obj.found_result_message); |
|
2149
|
+ $('span[data-wildcart="back"]').remove(); |
|
2150
|
+ if((globalwpw.settings.obj.disable_back_to_start != '1' && globalwpw.settings.obj.skip_greetings_and_menu != 1)){ |
|
2151
|
+ wpwMsg.triple_nobg(wp_chatbot_obj.found_result_message,json.html,'<span class="qcld-chatbot-wildcard" data-wildcart="back">' + wpwKits.randomMsg(globalwpw.settings.obj.back_to_start) + '</span>'); |
|
2152
|
+ }else{ |
|
2153
|
+ wpwMsg.double_nobg(wp_chatbot_obj.found_result_message,json.html); |
|
2154
|
+ } |
|
2155
|
+ }else{ |
|
2156
|
+ var data = {'action':'wpbo_failed_response','name':globalwpw.hasNameCookie,'keyword':msg}; |
|
2157
|
+ wpwKits.ajax(data).done(function (res) { |
|
2158
|
+ // |
|
2159
|
+ }) |
|
2160
|
+ if(globalwpw.counter == globalwpw.settings.obj.no_result_attempt_count || globalwpw.settings.obj.no_result_attempt_count == 0 ){ |
|
2161
|
+ wpwMsg.single(wpwKits.randomMsg(json.html)); |
|
2162
|
+ setTimeout(function(){ |
|
2163
|
+ var serviceOffer=wpwKits.randomMsg(globalwpw.settings.obj.support_option_again); |
|
2164
|
+ if((globalwpw.settings.obj.disable_back_to_start != '1' && globalwpw.settings.obj.skip_greetings_and_menu != 1)){ |
|
2165
|
+ wpwMsg.single_nobg('<span class="qcld-chatbot-wildcard qcld_back_to_start" data-wildcart="back">' + wpwKits.randomMsg(globalwpw.settings.obj.back_to_start) + '</span>'); |
|
2166
|
+ } |
|
2167
|
+ },globalwpw.settings.preLoadingTime) |
|
2168
|
+ globalwpw.counter = 0; |
|
2169
|
+ }else{ |
|
2170
|
+ globalwpw.counter++; |
|
2171
|
+ wpwMsg.single(wpwKits.randomMsg(json.html)); |
|
2172
|
+ } |
|
2173
|
+ } |
|
2174
|
+ globalwpw.wildCard=0; |
|
2175
|
+ }); |
|
2176
|
+ }else{ |
|
2177
|
+ globalwpw.wildCard=0; |
|
2178
|
+ wpwMsg.single(wpwKits.randomMsg(globalwpw.settings.obj.empty_filter_msg)); |
|
2179
|
+ // if(globalwpw.settings.obj.disable_repeatative!=1){ |
|
2180
|
+ // setTimeout(function(){ |
|
2181
|
+ // var serviceOffer=wpwKits.randomMsg(globalwpw.settings.obj.support_option_again); |
|
2182
|
+ // wpwMsg.double_nobg(serviceOffer,globalwpw.wildcards); |
|
2183
|
+ // },globalwpw.settings.preLoadingTime) |
|
2184
|
+ // }else{ |
|
2185
|
+ setTimeout(function(){ |
|
2186
|
+ if(!qcldIsAiFormInProgress()) { $(globalwpw.settings.messageContainer).find('.wp-chatbot-msg:last .qcld-like-dislike-icon').css('display', 'block'); } |
|
2187
|
+ if((globalwpw.settings.obj.disable_back_to_start != '1' && globalwpw.settings.obj.skip_greetings_and_menu != 1)){ |
|
2188
|
+ wpwMsg.single_nobg('<span class="qcld-chatbot-wildcard qcld_back_to_start" data-wildcart="back">' + wpwKits.randomMsg(globalwpw.settings.obj.back_to_start) + '</span>'); |
|
2189
|
+ } |
|
2190
|
+ }, globalwpw.settings.preLoadingTime*2); |
|
2191
|
+ // } |
|
2192
|
+ } |
|
2193
|
+ }else { |
|
2194
|
+ var productSucces= wpwKits.randomMsg(globalwpw.settings.obj.product_success)+" <strong>"+msg+"</strong>!"; |
|
2195
|
+ console.log(globalwpw.wildcards); |
|
2196
|
+ wpwMsg.double_nobg(productSucces,response.html); |
|
2197
|
+ if(response.per_page >= response.product_num){ |
|
2198
|
+ setTimeout(function () { |
|
2199
|
+ var searchAgain = wpwKits.randomMsg(globalwpw.settings.obj.product_infinite); |
|
2200
|
+ wpwMsg.single(searchAgain); |
|
2201
|
+ //keeping value in localstorage |
|
2202
|
+ globalwpw.wildCard=20; |
|
2203
|
+ globalwpw.productStep='search'; |
|
2204
|
+ localStorage.setItem("productStep", globalwpw.productStep); |
|
2205
|
+ },globalwpw.settings.wildcardsShowTime); |
|
2206
|
+ } |
|
2207
|
+ } |
|
2208
|
+ }); |
|
2209
|
+ }else{ |
|
2210
|
+ if(msg!='' && globalwpw.settings.obj.disable_sitesearch==''){ |
|
2211
|
+ msg = wpwKits.filterStopWords(msg); |
|
2212
|
+ var data = {'action':'wpbo_search_site','name':globalwpw.hasNameCookie,'keyword':msg, 'security':wp_chatbot_obj.ajax_nonce}; |
|
2213
|
+ if($(globalwpw.settings.messageLastChild+' .wp-chatbot-comment-loader').length==0){ |
|
2214
|
+ $(globalwpw.settings.messageContainer).append(wpwKits.botPreloader()); |
|
2215
|
+ } |
|
2216
|
+ wpwKits.ajax(data).done(function (response) { |
|
2217
|
+ var json=$.parseJSON(response); |
|
2218
|
+ if(json.status=='success'){ |
|
2219
|
+ //wpwMsg.single(); |
|
2220
|
+ $('span[data-wildcart="back"]').remove(); |
|
2221
|
+ if((globalwpw.settings.obj.disable_back_to_start != '1' && globalwpw.settings.obj.skip_greetings_and_menu != 1)){ |
|
2222
|
+ wpwMsg.triple_nobg(wp_chatbot_obj.found_result_message,json.html,'<span class="qcld-chatbot-wildcard" data-wildcart="back">' + wpwKits.randomMsg(globalwpw.settings.obj.back_to_start) + '</span>'); |
|
2223
|
+ }else{ |
|
2224
|
+ wpwMsg.double_nobg(wp_chatbot_obj.found_result_message,json.html); |
|
2225
|
+ } |
|
2226
|
+ }else{ |
|
2227
|
+ var data = {'action':'wpbo_failed_response','name':globalwpw.hasNameCookie,'keyword':msg}; |
|
2228
|
+ wpwKits.ajax(data).done(function (res) { |
|
2229
|
+ // |
|
2230
|
+ }) |
|
2231
|
+ if(globalwpw.counter == globalwpw.settings.obj.no_result_attempt_count || globalwpw.settings.obj.no_result_attempt_count == 0 ){ |
|
2232
|
+ wpwMsg.single(wpwKits.randomMsg(json.html)); |
|
2233
|
+ setTimeout(function(){ |
|
2234
|
+ var serviceOffer=wpwKits.randomMsg(globalwpw.settings.obj.support_option_again); |
|
2235
|
+ if((globalwpw.settings.obj.disable_back_to_start != '1' && globalwpw.settings.obj.skip_greetings_and_menu != 1)){ |
|
2236
|
+ wpwMsg.single_nobg('<span class="qcld-chatbot-wildcard qcld_back_to_start" data-wildcart="back">' + wpwKits.randomMsg(globalwpw.settings.obj.back_to_start) + '</span>'); |
|
2237
|
+ } |
|
2238
|
+ },globalwpw.settings.preLoadingTime) |
|
2239
|
+ globalwpw.counter = 0; |
|
2240
|
+ }else{ |
|
2241
|
+ globalwpw.counter++; |
|
2242
|
+ wpwMsg.single(wpwKits.randomMsg(json.html)); |
|
2243
|
+ } |
|
2244
|
+ } |
|
2245
|
+ globalwpw.wildCard=0; |
|
2246
|
+ }); |
|
2247
|
+ }else{ |
|
2248
|
+ globalwpw.wildCard=0; |
|
2249
|
+ wpwMsg.single(wpwKits.randomMsg(globalwpw.settings.obj.empty_filter_msg)); |
|
2250
|
+ // if(globalwpw.settings.obj.disable_repeatative!=1){ |
|
2251
|
+ // setTimeout(function(){ |
|
2252
|
+ // var serviceOffer=wpwKits.randomMsg(globalwpw.settings.obj.support_option_again); |
|
2253
|
+ // wpwMsg.double_nobg(serviceOffer,globalwpw.wildcards); |
|
2254
|
+ // },globalwpw.settings.preLoadingTime) |
|
2255
|
+ // }else{ |
|
2256
|
+ setTimeout(function(){ |
|
2257
|
+ if(!qcldIsAiFormInProgress()) { $(globalwpw.settings.messageContainer).find('.wp-chatbot-msg:last .qcld-like-dislike-icon').css('display', 'block'); } |
|
2258
|
+ if((globalwpw.settings.obj.disable_back_to_start != '1' && globalwpw.settings.obj.skip_greetings_and_menu != 1)){ |
|
2259
|
+ wpwMsg.single_nobg('<span class="qcld-chatbot-wildcard qcld_back_to_start" data-wildcart="back">' + wpwKits.randomMsg(globalwpw.settings.obj.back_to_start) + '</span>'); |
|
2260
|
+ } |
|
2261
|
+ }, globalwpw.settings.preLoadingTime*2); |
|
2262
|
+ // } |
|
2263
|
+ } |
|
2264
|
+ } |
|
2265
|
+ } |
|
2266
|
+ }) |
|
2267
|
+ |
|
2268
|
+ } // |
|
2269
|
+ } |
|
2270
|
+ if(globalwpw.settings.obj.woocommerce){ |
|
2271
|
+ //Product |
|
2272
|
+ if(globalwpw.wildCard==20){ |
|
2273
|
+ wpwTree.product(msg); |
|
2274
|
+ } |
|
2275
|
+ /* |
|
2276
|
+ * order status part |
|
2277
|
+ * bot action |
|
2278
|
+ */ |
|
2279
|
+ if(globalwpw.wildCard==21){ |
|
2280
|
+ wpwTree.order(msg); |
|
2281
|
+ } |
|
2282
|
+ } |
|
2283
|
+ if(globalwpw.wildCard==1){ |
|
2284
|
+ wpwTree.support(msg); |
|
2285
|
+ } |
|
2286
|
+ if(globalwpw.wildCard==3){ |
|
2287
|
+ wpwTree.subscription(msg); |
|
2288
|
+ } |
|
2289
|
+ if(globalwpw.wildCard==6){ |
|
2290
|
+ wpwTree.unsubscription(msg); |
|
2291
|
+ } |
|
2292
|
+ if(globalwpw.wildCard==7){ |
|
2293
|
+ wpwTree.formbuilder(msg); |
|
2294
|
+ } |
|
2295
|
+ if(globalwpw.wildCard==9){ |
|
2296
|
+ wpwTree.bargain(msg); |
|
2297
|
+ } |
|
2298
|
+ if(globalwpw.wildCard==25){ |
|
2299
|
+ wpwTree.reset(msg); |
|
2300
|
+ } |
|
2301
|
+ if(globalwpw.wildCard==26){ |
|
2302
|
+ wpwTree.dfcx(msg); |
|
2303
|
+ } |
|
2304
|
+ if(globalwpw.wildCard==30){ |
|
2305
|
+ wpwTree.ldsuggestion(); |
|
2306
|
+ } |
|
2307
|
+ } |
|
2308
|
+ }, |
|
2309
|
+ clickstr: function(id){ |
|
2310
|
+ var data = {'action':'wpbo_search_response','name':globalwpw.hasNameCookie,'strid':id, 'language':globalwpw.settings.obj.language}; |
|
2311
|
+ |
|
2312
|
+ wpwKits.ajax(data).done(function (response) { |
|
2313
|
+ var json=$.parseJSON(response); |
|
2314
|
+ if(json.status=='success'){ |
|
2315
|
+ if(typeof(json.data)!=="undefined" && json.data){ |
|
2316
|
+ var question=''; |
|
2317
|
+ $.each(json.data, function (i, obj) { |
|
2318
|
+ |
|
2319
|
+ question += obj.response; |
|
2320
|
+ }); |
|
2321
|
+ wpwMsg.single(question); |
|
2322
|
+ } |
|
2323
|
+ } |
|
2324
|
+ }) |
|
2325
|
+ }, |
|
2326
|
+ shopper:function (msg) { |
|
2327
|
+ wpwMsg.shopper(msg); |
|
2328
|
+ if(globalwpw.wildCard==1) { |
|
2329
|
+ this.bot(msg); |
|
2330
|
+ }else if(globalwpw.settings.obj.ai_df_enable==1 && globalwpw.wildCard==0 && globalwpw.ai_step==1 && globalwpw.df_status_lock==0){ |
|
2331
|
+ this.bot(msg); |
|
2332
|
+ } else{ |
|
2333
|
+ //Filtering the user given messages by stopwords |
|
2334
|
+ var filterMsg=(msg); |
|
2335
|
+ //handle empty filterMsg as repeat the message. |
|
2336
|
+ if(filterMsg=="") { |
|
2337
|
+ //if(globalwpw.emptymsghandler==0){ |
|
2338
|
+ globalwpw.repeatQueryEmpty=wpwKits.randomMsg(globalwpw.settings.obj.empty_filter_msg); |
|
2339
|
+ globalwpw.emptymsghandler++; |
|
2340
|
+ //} |
|
2341
|
+ wpwMsg.single(globalwpw.repeatQueryEmpty); |
|
2342
|
+ setTimeout(function(){ |
|
2343
|
+ var serviceOffer=wpwKits.randomMsg(globalwpw.settings.obj.support_option_again); |
|
2344
|
+ if((globalwpw.settings.obj.disable_back_to_start != '1' && globalwpw.settings.obj.skip_greetings_and_menu != 1)){ |
|
2345
|
+ wpwMsg.single_nobg('<span class="qcld-chatbot-wildcard qcld_back_to_start" data-wildcart="back">' + wpwKits.randomMsg(globalwpw.settings.obj.back_to_start) + '</span>'); |
|
2346
|
+ } |
|
2347
|
+ },globalwpw.settings.preLoadingTime) |
|
2348
|
+ }else { |
|
2349
|
+ globalwpw.emptymsghandler=0; |
|
2350
|
+ this.bot(filterMsg); |
|
2351
|
+ } |
|
2352
|
+ } |
|
2353
|
+ } |
|
2354
|
+ }; |
|
2355
|
+ /* |
|
2356
|
+ * wpwBot Plugin Creation without selector and |
|
2357
|
+ * wpwbot and shoppers all activities will be handled. |
|
2358
|
+ */ |
|
2359
|
+ $.wpwbot = function(options) { |
|
2360
|
+ //Using plugins defualts values or overwrite by options. |
|
2361
|
+ |
|
2362
|
+ var settings = $.extend({}, $.wpwbot.defaults, options); |
|
2363
|
+ //Updating global settings |
|
2364
|
+ globalwpw.settings=settings; |
|
2365
|
+ //updating the helpkeywords |
|
2366
|
+ globalwpw.wildcardsHelp=[globalwpw.settings.obj.sys_key_help.toLowerCase(),globalwpw.settings.obj.sys_key_product.toLowerCase(),globalwpw.settings.obj.sys_key_catalog.toLowerCase(),globalwpw.settings.obj.sys_key_support.toLowerCase(),globalwpw.settings.obj.sys_key_order.toLowerCase(),globalwpw.settings.obj.sys_key_reset.toLowerCase(),globalwpw.settings.obj.sys_key_email.toLowerCase()] |
|
2367
|
+ //updating wildcards |
|
2368
|
+ globalwpw.wildcards=''; |
|
2369
|
+ if(globalwpw.settings.obj.start_menu!=''){ |
|
2370
|
+ var menu_html = ''; |
|
2371
|
+ var menu_items = $.parseHTML($.trim(globalwpw.settings.obj.start_menu)); |
|
2372
|
+ $(menu_items).each(function(){ |
|
2373
|
+ if( $(this).prop('tagName') == 'SPAN' ){ |
|
2374
|
+ if( $(this).hasClass('qcld-chatbot-suggest-email') ){ |
|
2375
|
+ if( globalwpw.settings.obj.disable_feedback=='' ){ |
|
2376
|
+ menu_html += $(this).prop('outerHTML'); |
|
2377
|
+ } |
|
2378
|
+ }else if( $(this).hasClass('qcld-chatbot-suggest-phone') ){ |
|
2379
|
+ if( globalwpw.settings.obj.call_gen=="" ){ |
|
2380
|
+ menu_html += $(this).prop('outerHTML'); |
|
2381
|
+ } |
|
2382
|
+ }else if( $(this).hasClass('qcld-chatbot-wildcard') && $(this).attr('data-wildcart') == 'support' ){ |
|
2383
|
+ if( globalwpw.settings.obj.disable_faq=='' ){ |
|
2384
|
+ menu_html += $(this).prop('outerHTML'); |
|
2385
|
+ } |
|
2386
|
+ }else if( $(this).hasClass('qcld-chatbot-wildcard') && $(this).attr('data-wildcart') == 'messenger' ){ |
|
2387
|
+ if( globalwpw.settings.obj.enable_messenger==1 ){ |
|
2388
|
+ menu_html += $(this).prop('outerHTML'); |
|
2389
|
+ } |
|
2390
|
+ }else if( $(this).hasClass('qcld-chatbot-wildcard') && $(this).attr('data-wildcart') == 'whatspp' ){ |
|
2391
|
+ if( globalwpw.settings.obj.enable_whats==1 ){ |
|
2392
|
+ menu_html += $(this).prop('outerHTML'); |
|
2393
|
+ } |
|
2394
|
+ }else{ |
|
2395
|
+ menu_html += $(this).prop('outerHTML'); |
|
2396
|
+ } |
|
2397
|
+ } |
|
2398
|
+ }) |
|
2399
|
+ if( menu_html != '' ){ |
|
2400
|
+ globalwpw.wildcards = menu_html; |
|
2401
|
+ }else{ |
|
2402
|
+ globalwpw.wildcards = globalwpw.settings.obj.start_menu; |
|
2403
|
+ } |
|
2404
|
+ } |
|
2405
|
+ //Initialize the wpwBot with greeting and if already initialize and given name then return greeting.. |
|
2406
|
+ if(localStorage.getItem("wpwHitory") && globalwpw.initialize==0 ){ |
|
2407
|
+ var wpwHistory=localStorage.getItem("wpwHitory"); |
|
2408
|
+ $(globalwpw.settings.messageWrapper).html(wpwHistory); |
|
2409
|
+ //Scroll to the last element. |
|
2410
|
+ wpwKits.scrollTo(); |
|
2411
|
+ //Now mainting the current stages tokens |
|
2412
|
+ globalwpw.initialize=1; |
|
2413
|
+ if(localStorage.getItem("wildCard")){ |
|
2414
|
+ globalwpw.wildCard=localStorage.getItem("wildCard"); |
|
2415
|
+ } |
|
2416
|
+ if(localStorage.getItem("productStep")){ |
|
2417
|
+ globalwpw.productStep=localStorage.getItem("productStep"); |
|
2418
|
+ } |
|
2419
|
+ if(localStorage.getItem("orderStep")){ |
|
2420
|
+ globalwpw.orderStep=localStorage.getItem("orderStep"); |
|
2421
|
+ } |
|
2422
|
+ if(localStorage.getItem("supportStep")){ |
|
2423
|
+ globalwpw.supportStep=localStorage.getItem("supportStep"); |
|
2424
|
+ } |
|
2425
|
+ if(localStorage.getItem("aiStep")){ |
|
2426
|
+ globalwpw.ai_step=localStorage.getItem("aiStep"); |
|
2427
|
+ } |
|
2428
|
+ if(localStorage.getItem("formfieldid")){ |
|
2429
|
+ globalwpw.formfieldid=localStorage.getItem("formfieldid"); |
|
2430
|
+ } |
|
2431
|
+ if(localStorage.getItem("formentry")){ |
|
2432
|
+ globalwpw.formentry=localStorage.getItem("formentry"); |
|
2433
|
+ } |
|
2434
|
+ if(localStorage.getItem("formStep")){ |
|
2435
|
+ globalwpw.formStep=localStorage.getItem("formStep"); |
|
2436
|
+ } |
|
2437
|
+ if(localStorage.getItem("formid")){ |
|
2438
|
+ globalwpw.formid=localStorage.getItem("formid"); |
|
2439
|
+ } |
|
2440
|
+ //update the value for initializing. |
|
2441
|
+ globalwpw.initialize=1; |
|
2442
|
+ } else { |
|
2443
|
+ if(globalwpw.initialize==0 && globalwpw.wildCard==0 && globalwpw.settings.obj.re_target_handler==0){ |
|
2444
|
+ wpwWelcome.greeting(); |
|
2445
|
+ //update the value for initializing. |
|
2446
|
+ globalwpw.initialize=1; |
|
2447
|
+ }else{ // re targeting part . |
|
2448
|
+ setTimeout(function (e) { |
|
2449
|
+ wpwWelcome.greeting(); |
|
2450
|
+ },8500); |
|
2451
|
+ globalwpw.initialize=1; |
|
2452
|
+ } |
|
2453
|
+ } |
|
2454
|
+ function wpbotResetSendMessageClasses() { |
|
2455
|
+ $(settings.sendButton).removeClass('wp-chatbot-send-message-active wp-chatbot-send-message-typing'); |
|
2456
|
+ } |
|
2457
|
+ |
|
2458
|
+ // Typing state only: add active class while editor has content. |
|
2459
|
+ $(document).on('input keyup', settings.messageEditor, function () { |
|
2460
|
+ var hasValue = $.trim($(settings.messageEditor).val()).length > 0; |
|
2461
|
+ $(settings.sendButton).toggleClass('wp-chatbot-send-message-active', hasValue); |
|
2462
|
+ }); |
|
2463
|
+ |
|
2464
|
+ // Blur state: clean both classes if no input value. |
|
2465
|
+ $(document).on('blur', settings.messageEditor, function () { |
|
2466
|
+ var hasValue = $.trim($(settings.messageEditor).val()).length > 0; |
|
2467
|
+ if (!hasValue) { |
|
2468
|
+ wpbotResetSendMessageClasses(); |
|
2469
|
+ } |
|
2470
|
+ }); |
|
2471
|
+ |
|
2472
|
+ //When shopper click on send button |
|
2473
|
+ $(document).on('click',settings.sendButton,function (e) { |
|
2474
|
+ var shopperMsg =$(settings.messageEditor).val(); |
|
2475
|
+ if(shopperMsg != ""){ |
|
2476
|
+ wpwAction.shopper(wpwKits.htmlTagsScape(shopperMsg)); |
|
2477
|
+ $(settings.messageEditor).val(''); |
|
2478
|
+ wpbotResetSendMessageClasses(); |
|
2479
|
+ } |
|
2480
|
+ }); |
|
2481
|
+ $(document).on('click', '.chatbot_intent_reload', function(e){ |
|
2482
|
+ e.preventDefault(); |
|
2483
|
+ var obj = $(this); |
|
2484
|
+ if(obj.attr('data-intent-type')=='formbuilder'){ |
|
2485
|
+ if( obj.attr('data-step')=='complete' ){ |
|
2486
|
+ globalwpw.formStep='field'; |
|
2487
|
+ localStorage.setItem("formStep", globalwpw.formStep); |
|
2488
|
+ } |
|
2489
|
+ globalwpw.wildCard=obj.attr('data-wildcard'); |
|
2490
|
+ globalwpw.formfieldid = obj.attr('data-intent'); |
|
2491
|
+ wpwTree.formbuilder(); |
|
2492
|
+ } |
|
2493
|
+ }) |
|
2494
|
+ /* |
|
2495
|
+ * Or when shopper press the ENTER key |
|
2496
|
+ * Then chatting functionality will be started. |
|
2497
|
+ */ |
|
2498
|
+ $(document).on('click', '.wpb-quick-reply', function(e){ |
|
2499
|
+ e.preventDefault(); |
|
2500
|
+ $('#wp-chatbot-editor').val($(this).html()); |
|
2501
|
+ $('#wp-chatbot-send-message').trigger( "click" ); |
|
2502
|
+ }) |
|
2503
|
+ $(document).on('keypress',settings.messageEditor,function (e) { |
|
2504
|
+ if (e.which == 13||e.keyCode==13) { |
|
2505
|
+ e.preventDefault(); |
|
2506
|
+ var shopperMsg =$(settings.messageEditor).val(); |
|
2507
|
+ if(shopperMsg != ""){ |
|
2508
|
+ wpwAction.shopper(wpwKits.htmlTagsScape(shopperMsg)); |
|
2509
|
+ $(settings.messageEditor).val(''); |
|
2510
|
+ wpbotResetSendMessageClasses(); |
|
2511
|
+ } |
|
2512
|
+ } |
|
2513
|
+ }); |
|
2514
|
+ $(document).on('click', '.qcld-chatbot-checkbox', function(){ |
|
2515
|
+ |
|
2516
|
+ var value = []; |
|
2517
|
+ $('.qcld-chatbot-checkbox').each(function(){ |
|
2518
|
+ if($(this).prop("checked") == true){ |
|
2519
|
+ value.push($(this).val()); |
|
2520
|
+ } |
|
2521
|
+ }) |
|
2522
|
+ $('#wp-chatbot-editor').val(value.join()); |
|
2523
|
+ if ($.trim($('#wp-chatbot-editor').val()).length > 0) { |
|
2524
|
+ $(settings.sendButton).addClass('wp-chatbot-send-message-active'); |
|
2525
|
+ } else { |
|
2526
|
+ wpbotResetSendMessageClasses(); |
|
2527
|
+ } |
|
2528
|
+ }) |
|
2529
|
+ //Click on the wildcards to select a service |
|
2530
|
+ $(document).on('click','.qcld-chatbot-wildcard',function(){ |
|
2531
|
+ var wildcardData=$(this).attr('data-form'); |
|
2532
|
+ var shooperChoice=$(this).text(); |
|
2533
|
+ wpwMsg.shopper_choice(shooperChoice); |
|
2534
|
+ if(typeof wildcardData === "undefined"){ |
|
2535
|
+ var wildcardData=$(this).attr('data-wildcart'); |
|
2536
|
+ } |
|
2537
|
+ //Wild cards handling for bot. |
|
2538
|
+ if(wildcardData=='product'){ |
|
2539
|
+ globalwpw.wildCard=1; |
|
2540
|
+ globalwpw.productStep='asking' |
|
2541
|
+ wpwAction.bot('from wildcard product'); |
|
2542
|
+ //keeping value in localstorage |
|
2543
|
+ localStorage.setItem("wildCard", globalwpw.wildCard); |
|
2544
|
+ localStorage.setItem("productStep", globalwpw.productStep); |
|
2545
|
+ } |
|
2546
|
+ if(wildcardData=='catalog'){ |
|
2547
|
+ wpwAction.bot(globalwpw.settings.obj.sys_key_catalog.toLowerCase()); |
|
2548
|
+ } |
|
2549
|
+ if(wildcardData=='featured'){ |
|
2550
|
+ globalwpw.wildCard=1; |
|
2551
|
+ globalwpw.productStep='featured' |
|
2552
|
+ wpwAction.bot('from wildcard product'); |
|
2553
|
+ //keeping value in localstorage |
|
2554
|
+ localStorage.setItem("wildCard", globalwpw.wildCard); |
|
2555
|
+ localStorage.setItem("productStep", globalwpw.productStep); |
|
2556
|
+ } |
|
2557
|
+ if(wildcardData=='sale'){ |
|
2558
|
+ globalwpw.wildCard=1; |
|
2559
|
+ globalwpw.productStep='sale' |
|
2560
|
+ wpwAction.bot('from wildcard product'); |
|
2561
|
+ //keeping value in localstorage |
|
2562
|
+ localStorage.setItem("wildCard", globalwpw.wildCard); |
|
2563
|
+ localStorage.setItem("productStep", globalwpw.productStep); |
|
2564
|
+ } |
|
2565
|
+ if(wildcardData=='order'){ |
|
2566
|
+ globalwpw.wildCard=2; |
|
2567
|
+ globalwpw.orderStep='welcome'; |
|
2568
|
+ wpwAction.bot('from wildcard order'); |
|
2569
|
+ //keeping value in localstorage |
|
2570
|
+ localStorage.setItem("wildCard", globalwpw.wildCard); |
|
2571
|
+ localStorage.setItem("orderStep", globalwpw.orderStep); |
|
2572
|
+ } |
|
2573
|
+ if((wildcardData=='support ui-sortable-handle') || (wildcardData=='support')) { |
|
2574
|
+ globalwpw.wildCard=1; |
|
2575
|
+ globalwpw.supportStep='welcome'; |
|
2576
|
+ wpwAction.bot('from wildcard support'); |
|
2577
|
+ //keeping value in localstorage |
|
2578
|
+ localStorage.setItem("wildCard", globalwpw.wildCard); |
|
2579
|
+ localStorage.setItem("supportStep", globalwpw.supportStep); |
|
2580
|
+ } |
|
2581
|
+ if(wildcardData=='back'){ |
|
2582
|
+ globalwpw.wildCard=0; |
|
2583
|
+ //wpwAction.bot('start'); |
|
2584
|
+ wpwAction.bot(wp_chatbot_obj.sys_key_help.toLowerCase()); |
|
2585
|
+ //keeping value in localstorage |
|
2586
|
+ localStorage.setItem("wildCard", globalwpw.wildCard); |
|
2587
|
+ } |
|
2588
|
+ if(wildcardData=='ai_form'){ |
|
2589
|
+ globalwpw.wildCard=0; |
|
2590
|
+ globalwpw.active_ai_action = shooperChoice; |
|
2591
|
+ globalwpw.qcld_ai_form_persisted_state = true; |
|
2592
|
+ wpwAction.bot(shooperChoice); |
|
2593
|
+ localStorage.setItem("wildCard", globalwpw.wildCard); |
|
2594
|
+ } |
|
2595
|
+ if(wildcardData=='messenger'){ |
|
2596
|
+ var url='https://www.messenger.com/t/'+globalwpw.settings.obj.fb_page_id; |
|
2597
|
+ var win = window.open(url, '_blank'); |
|
2598
|
+ win.focus(); |
|
2599
|
+ } |
|
2600
|
+ if(wildcardData=='whatsapp'){ |
|
2601
|
+ var url='https://api.whatsapp.com/send?phone='+globalwpw.settings.obj.whats_num; |
|
2602
|
+ var win = window.open(url, '_blank'); |
|
2603
|
+ win.focus(); |
|
2604
|
+ } |
|
2605
|
+ }); |
|
2606
|
+ $(document).on('click','.qcld-chatbot-form',function(e){ |
|
2607
|
+ e.preventDefault(); |
|
2608
|
+ var formid=$(this).attr('data-form'); |
|
2609
|
+ globalwpw.wildCard=7; |
|
2610
|
+ globalwpw.formStep='welcome'; |
|
2611
|
+ wpwTree.formbuilder(formid); |
|
2612
|
+ }) |
|
2613
|
+ $(document).on('click','.qcld_simple_txt_response',function(e){ |
|
2614
|
+ e.preventDefault(); |
|
2615
|
+ var text=$(this).text(); |
|
2616
|
+ var id = $(this).data('strid'); |
|
2617
|
+ globalwpw.wildCard=0; |
|
2618
|
+ wpwAction.clickstr(id); |
|
2619
|
+ }) |
|
2620
|
+ $(document).on('click','#wp-chatbot-desktop-reload',function (e) { |
|
2621
|
+ e.preventDefault(); |
|
2622
|
+ var actionType=$(this).attr('reset-data'); |
|
2623
|
+ $('#wp-chatbot-messages-container').html(''); |
|
2624
|
+ localStorage.removeItem('shopper'); |
|
2625
|
+ globalwpw.wildCard=0; |
|
2626
|
+ globalwpw.ai_step=0; |
|
2627
|
+ localStorage.setItem("wildCard", globalwpw.wildCard); |
|
2628
|
+ localStorage.setItem("aiStep", globalwpw.ai_step); |
|
2629
|
+ globalwpw.formfieldid = ''; |
|
2630
|
+ localStorage.setItem("formfieldid", globalwpw.formfieldid); |
|
2631
|
+ globalwpw.formStep='welcome'; |
|
2632
|
+ localStorage.setItem("formStep", globalwpw.formStep); |
|
2633
|
+ globalwpw.formid=''; |
|
2634
|
+ localStorage.setItem("formid", globalwpw.formid); |
|
2635
|
+ globalwpw.formentry = 0; |
|
2636
|
+ localStorage.setItem("formentry", globalwpw.formentry); |
|
2637
|
+ localStorage.removeItem("cx-name" ); |
|
2638
|
+ localStorage.removeItem("cx-diaplayname" ); |
|
2639
|
+ localStorage.removeItem("cx-languagecode" ); |
|
2640
|
+ localStorage.removeItem("cx-timezone" ); |
|
2641
|
+ var number = Math.random() // 0.9394456857981651 |
|
2642
|
+ number.toString(36); // '0.xtis06h6' |
|
2643
|
+ var id = number.toString(36).substr(2); // 'xtis06h6' |
|
2644
|
+ localStorage.setItem('botsessionid', id); |
|
2645
|
+ // Keep mobile/responsive chat full-width after reset (do not shrink to content) |
|
2646
|
+ if ($(window).width() <= 480 && globalwpw.settings.obj.mobile_full_screen == 1) { |
|
2647
|
+ $('#wp-chatbot-chat-container').addClass('wp-chatbot-mobile-fs-open').css({ |
|
2648
|
+ 'bottom': '0', |
|
2649
|
+ 'left': '0', |
|
2650
|
+ 'right': '0', |
|
2651
|
+ 'width': '100%', |
|
2652
|
+ 'max-width': '100%' |
|
2653
|
+ }); |
|
2654
|
+ $('#wp-chatbot-board-container').css({'width': '100%', 'max-width': '100%'}); |
|
2655
|
+ $('.slimScrollDiv').css({'width': '100%', 'max-width': '100%'}); |
|
2656
|
+ } |
|
2657
|
+ wpwWelcome.greeting(); |
|
2658
|
+ }); |
|
2659
|
+ $(document).on('click','.qcld-chatbot-formanswer',function(e){ |
|
2660
|
+ e.preventDefault(); |
|
2661
|
+ var answer=$(this).attr('data-form-value'); |
|
2662
|
+ wpwAction.bot(answer); |
|
2663
|
+ }) |
|
2664
|
+ // |
|
2665
|
+ $(document).on('click','.qcld-chatbot-product-category',function(){ |
|
2666
|
+ var catType=$(this).attr('data-category-type'); |
|
2667
|
+ var shopperChoiceCatId=$(this).text()+'#'+$(this).attr('data-category-id'); |
|
2668
|
+ var shopperChoiceCategory=$(this).text(); |
|
2669
|
+ if(catType=='hasChilds'){ |
|
2670
|
+ //Now hide all categories but shopper choice. |
|
2671
|
+ wpwMsg.shopper_choice(shopperChoiceCategory); |
|
2672
|
+ //updating the product steps and bringing the product by category. |
|
2673
|
+ wpwKits.subCats($(this).attr('data-category-id')); |
|
2674
|
+ globalwpw.productStep='search'; |
|
2675
|
+ globalwpw.wildCard=1; |
|
2676
|
+ }else{ |
|
2677
|
+ //Now hide all categories but shopper choice. |
|
2678
|
+ wpwMsg.shopper_choice(shopperChoiceCategory); |
|
2679
|
+ //updating the product steps and bringing the product by category. |
|
2680
|
+ globalwpw.productStep='category'; |
|
2681
|
+ globalwpw.wildCard=1; |
|
2682
|
+ //keeping value in localstorage |
|
2683
|
+ localStorage.setItem("productStep", globalwpw.productStep); |
|
2684
|
+ wpwAction.bot(shopperChoiceCatId); |
|
2685
|
+ } |
|
2686
|
+ }); |
|
2687
|
+ //Product Load More features for product search or category products |
|
2688
|
+ $(document).on('click','#wp-chatbot-loadmore',function (e) { |
|
2689
|
+ $('#wp-chatbot-loadmore-loader').html('<img class="wp-chatbot-comment-loader" src="'+globalwpw.settings.obj.image_path+'loadmore.gif" alt="..." />'); |
|
2690
|
+ var loadMoreDom=$(this); |
|
2691
|
+ var productOffest=loadMoreDom.attr('data-offset'); |
|
2692
|
+ var searchType=loadMoreDom.attr('data-search-type'); |
|
2693
|
+ var searchTerm=loadMoreDom.attr('data-search-term'); |
|
2694
|
+ var data = { 'action': 'qcld_wb_chatbot_load_more','offset': productOffest,'search_type': searchType,'search_term': searchTerm}; |
|
2695
|
+ //Load more ajax handler. |
|
2696
|
+ wpwKits.ajax(data).done(function (response) { |
|
2697
|
+ //Change button text |
|
2698
|
+ $('#wp-chatbot-loadmore-loader').html(''); |
|
2699
|
+ $('.wp-chatbot-products').append(response.html); |
|
2700
|
+ loadMoreDom.attr('data-search-term',response.search_term); |
|
2701
|
+ wpwKits.wpwHistorySave(); |
|
2702
|
+ loadMoreDom.attr('data-offset',response.offset); |
|
2703
|
+ if(response.product_num <= response.per_page){ |
|
2704
|
+ loadMoreDom.hide(); |
|
2705
|
+ //Now show the user infinite. |
|
2706
|
+ setTimeout(function () { |
|
2707
|
+ var searchAgain = wpwKits.randomMsg(globalwpw.settings.obj.product_infinite); |
|
2708
|
+ wpwMsg.single(searchAgain); |
|
2709
|
+ globalwpw.productStep='search'; |
|
2710
|
+ //keeping value in localstorage |
|
2711
|
+ localStorage.setItem("productStep", globalwpw.productStep); |
|
2712
|
+ },globalwpw.settings.wildcardsShowTime); |
|
2713
|
+ } |
|
2714
|
+ //scroll to the last message |
|
2715
|
+ wpwKits.scrollTo(); |
|
2716
|
+ }); |
|
2717
|
+ }); |
|
2718
|
+ //search load more |
|
2719
|
+ $(document).on('click', '.wp-chatbot-loadmore', function(e){ |
|
2720
|
+ e.preventDefault(); |
|
2721
|
+ var obj = $(this); |
|
2722
|
+ |
|
2723
|
+ var keyword = obj.attr('data-keyword'); |
|
2724
|
+ var post_type = obj.attr('data-post_type'); |
|
2725
|
+ var page = obj.attr('data-page'); |
|
2726
|
+ obj.text('Loading...'); |
|
2727
|
+ var data = {'action':'wpbo_search_site_pagination','name':globalwpw.hasNameCookie,'keyword':keyword,'language': globalwpw.settings.obj.language,'type': post_type, 'page': page, 'nonce': qcld_chatbot_obj.nonce}; |
|
2728
|
+ if($(globalwpw.settings.messageLastChild+' .wp-chatbot-comment-loader').length==0){ |
|
2729
|
+ $(globalwpw.settings.messageContainer).append(wpwKits.botPreloader()); |
|
2730
|
+ } |
|
2731
|
+ wpwKits.ajax(data).done(function (res) { |
|
2732
|
+ var json = (res); |
|
2733
|
+ if(json.status=='success'){ |
|
2734
|
+ $('span[data-wildcart="back"]').remove(); |
|
2735
|
+ wpwMsg.single(json.html); |
|
2736
|
+ // Hide the comment loader after response inside parent .wp-chatbot-paragraph |
|
2737
|
+ // Hide the entire li.wp-chatbot-msg if its .wp-chatbot-paragraph only contains the loader image (and is hidden) |
|
2738
|
+ |
|
2739
|
+ setTimeout(function(){ |
|
2740
|
+ if((globalwpw.settings.obj.qcld_disable_repited_startmenu != "1") && (globalwpw.settings.obj.disable_back_to_start != '1' && globalwpw.settings.obj.skip_greetings_and_menu != 1)){ |
|
2741
|
+ wpwMsg.single_nobg('<span class="qcld-chatbot-wildcard qcld_back_to_start" data-wildcart="back">' + wpwKits.randomMsg(globalwpw.settings.obj.back_to_start) + '</span>'); |
|
2742
|
+ } |
|
2743
|
+ },globalwpw.settings.preLoadingTime) |
|
2744
|
+ |
|
2745
|
+ obj.remove(); |
|
2746
|
+ }else{ |
|
2747
|
+ |
|
2748
|
+ if(globalwpw.counter == globalwpw.settings.obj.no_result_attempt_count || globalwpw.settings.obj.no_result_attempt_count == 0 ){ |
|
2749
|
+ |
|
2750
|
+ wpwMsg.single(json.html); |
|
2751
|
+ if(globalwpw.settings.obj.disable_repeatative!=1){ |
|
2752
|
+ if ( wpwKits.render( globalwpw.settings.obj.no_result_attempt_message ) != '' ) { |
|
2753
|
+ setTimeout(function(){ |
|
2754
|
+ wpwMsg.single(wpwKits.render( globalwpw.settings.obj.no_result_attempt_message )); |
|
2755
|
+ },globalwpw.settings.preLoadingTime) |
|
2756
|
+ } else { |
|
2757
|
+ setTimeout(function(){ |
|
2758
|
+ var serviceOffer=wpwKits.randomMsg(globalwpw.settings.obj.support_option_again); |
|
2759
|
+ if((globalwpw.settings.obj.qcld_disable_start_menu != "1")){ |
|
2760
|
+ if(typeof(globalwpw.wildcards) != 'undefined' && (globalwpw.wildcards != '')){ |
|
2761
|
+ console.log(globalwpw.wildcards); |
|
2762
|
+ wpwMsg.double_nobg(serviceOffer,globalwpw.wildcards); |
|
2763
|
+ }else{ |
|
2764
|
+ wpwMsg.single(serviceOffer); |
|
2765
|
+ } |
|
2766
|
+ |
|
2767
|
+ } |
|
2768
|
+ |
|
2769
|
+ },globalwpw.settings.preLoadingTime) |
|
2770
|
+ } |
|
2771
|
+ } |
|
2772
|
+ globalwpw.counter = 0; |
|
2773
|
+ |
|
2774
|
+ }else{ |
|
2775
|
+ globalwpw.counter++; |
|
2776
|
+ wpwTree.df_reply(res); |
|
2777
|
+ } |
|
2778
|
+ |
|
2779
|
+ } |
|
2780
|
+ globalwpw.wildCard=0; |
|
2781
|
+ |
|
2782
|
+ }); |
|
2783
|
+ |
|
2784
|
+ |
|
2785
|
+ }) |
|
2786
|
+ |
|
2787
|
+ //search load more |
|
2788
|
+ $(document).on('click', '.wp-chatbot-loadmore2', function(e){ |
|
2789
|
+ e.preventDefault(); |
|
2790
|
+ var obj = $(this); |
|
2791
|
+ |
|
2792
|
+ var keyword = obj.attr('data-keyword'); |
|
2793
|
+ |
|
2794
|
+ var page = obj.attr('data-page'); |
|
2795
|
+ |
|
2796
|
+ var search_type = obj.attr('data-search-type'); |
|
2797
|
+ obj.text(globalwpw.settings.obj.loading.en_US); |
|
2798
|
+ |
|
2799
|
+ if( search_type == 'default-wp-search' ){ |
|
2800
|
+ var data = {'action':'wpbo_default_search_pagination2','name':globalwpw.hasNameCookie,'keyword':keyword, 'page': page, search_type:'default-wp-search'}; |
|
2801
|
+ }else{ |
|
2802
|
+ var data = {'action':'wpbo_search_site_pagination2','name':globalwpw.hasNameCookie,'keyword':keyword, 'page': page,'nonce': qcld_chatbot_obj.nonce}; |
|
2803
|
+ } |
|
2804
|
+ if($(globalwpw.settings.messageLastChild+' .wp-chatbot-comment-loader').length==0){ |
|
2805
|
+ $(globalwpw.settings.messageContainer).append(wpwKits.botPreloader()); |
|
2806
|
+ } |
|
2807
|
+ wpwKits.ajax(data).done(function (res) { |
|
2808
|
+ var json=$.parseJSON(res); |
|
2809
|
+ if(json.status=='success'){ |
|
2810
|
+ $('span[data-wildcart="back"]').remove(); |
|
2811
|
+ |
|
2812
|
+ wpwMsg.single_nobg(json.html); |
|
2813
|
+ |
|
2814
|
+ setTimeout(function(){ |
|
2815
|
+ if((globalwpw.settings.obj.qcld_disable_repited_startmenu != "1") && (globalwpw.settings.obj.disable_back_to_start != '1' && globalwpw.settings.obj.skip_greetings_and_menu != 1)){ |
|
2816
|
+ wpwMsg.single_nobg('<span class="qcld-chatbot-wildcard qcld_back_to_start" data-wildcart="back">' + wpwKits.randomMsg(globalwpw.settings.obj.back_to_start) + '</span>'); |
|
2817
|
+ } |
|
2818
|
+ },globalwpw.settings.preLoadingTime) |
|
2819
|
+ |
|
2820
|
+ obj.remove(); |
|
2821
|
+ }else{ |
|
2822
|
+ |
|
2823
|
+ if(globalwpw.counter == globalwpw.settings.obj.no_result_attempt_count || globalwpw.settings.obj.no_result_attempt_count == 0 ){ |
|
2824
|
+ |
|
2825
|
+ wpwMsg.single(json.html); |
|
2826
|
+ wpwTree.start_menu_settings(); |
|
2827
|
+ globalwpw.counter = 0; |
|
2828
|
+ |
|
2829
|
+ }else{ |
|
2830
|
+ globalwpw.counter++; |
|
2831
|
+ wpwTree.df_reply(res); |
|
2832
|
+ } |
|
2833
|
+ |
|
2834
|
+ } |
|
2835
|
+ globalwpw.wildCard=0; |
|
2836
|
+ }); |
|
2837
|
+ |
|
2838
|
+ |
|
2839
|
+ }); |
|
2840
|
+ /*Products details part **/ |
|
2841
|
+ // if(globalwpw.settings.obj.open_product_detail!=1){ |
|
2842
|
+ // $(document).on('click','.wp-chatbot-product a',function (e) { |
|
2843
|
+ // e.preventDefault(); |
|
2844
|
+ // $('.wp-chatbot-product-container').addClass('active-chatbot-product-details'); |
|
2845
|
+ // $('.wp-chatbot-product-reload').addClass('wp-chatbot-product-loading').html('<img class="wp-chatbot-product-loader" src="'+globalwpw.settings.obj.image_path+'comment.gif" alt="Loading..." />'); |
|
2846
|
+ // var productId=$(this).attr('wp-chatbot-pid'); |
|
2847
|
+ // var data = { 'action':'qcld_wb_chatbot_product_details', 'wp_chatbot_pid':productId}; |
|
2848
|
+ // //product details ajax handler. |
|
2849
|
+ // wpwKits.ajax(data).done(function (response) { |
|
2850
|
+ // $('.wp-chatbot-product-reload').removeClass('wp-chatbot-product-loading').html(''); |
|
2851
|
+ // $('#wp-chatbot-product-title').html(response.title); |
|
2852
|
+ // $('#wp-chatbot-product-description').html(response.description); |
|
2853
|
+ // $('#wp-chatbot-product-image').html(response.image); |
|
2854
|
+ // $('#wp-chatbot-product-price').html(response.price); |
|
2855
|
+ // $('#wp-chatbot-product-quantity').html(response.quantity); |
|
2856
|
+ // $('#wp-chatbot-product-variable').html(response.variation); |
|
2857
|
+ // $('#wp-chatbot-product-cart-button').html(response.buttton); |
|
2858
|
+ // //Load gallery magnify |
|
2859
|
+ // setTimeout(function () { |
|
2860
|
+ // $('#wp-chatbot-product-image-large-path').magnificPopup({type:'image'}); |
|
2861
|
+ // },1000); |
|
2862
|
+ // //For shortcode handle recenlty view product by ajax as |
|
2863
|
+ // if($('#wp-chatbot-shortcode-template-container').length > 0){ |
|
2864
|
+ // var data = {'action':'qcld_wb_chatbot_recently_viewed_products'}; |
|
2865
|
+ // wpwKits.ajax(data).done(function (response) { |
|
2866
|
+ // $('.wp-chatbot-product-shortcode-container').html(response); |
|
2867
|
+ // $('.chatbot-sidebar .wp-chatbot-products').slimScroll({height: '435px', start: 'top'}); |
|
2868
|
+ // }); |
|
2869
|
+ // } |
|
2870
|
+ // }); |
|
2871
|
+ // }); |
|
2872
|
+ // } |
|
2873
|
+ //Image gallery. |
|
2874
|
+ $(document).on('click','.wp-chatbot-product-image-thumbs-path',function (e) { |
|
2875
|
+ e.preventDefault(); |
|
2876
|
+ var imagePath=$(this).attr('href'); |
|
2877
|
+ $('#wp-chatbot-product-image-large-path').attr('href',imagePath); |
|
2878
|
+ $('#wp-chatbot-product-image-large-src').attr('src',imagePath); |
|
2879
|
+ //handle thumb active one |
|
2880
|
+ $('.wp-chatbot-product-image-thumbs-path').parent().removeClass('wp-chatbot-product-active-image-thumbs'); |
|
2881
|
+ $(this).parent().addClass('wp-chatbot-product-active-image-thumbs'); |
|
2882
|
+ }); |
|
2883
|
+ //Product details close |
|
2884
|
+ $(document).on('click', '.wp-chatbot-product-close', function (e) { |
|
2885
|
+ $('.wp-chatbot-product-container').removeClass('active-chatbot-product-details'); |
|
2886
|
+ }); |
|
2887
|
+ /*add to cart part **/ |
|
2888
|
+ $(document).on("click","#wp-chatbot-add-cart-button",function (e) { |
|
2889
|
+ var pId=$(this).attr('wp-chatbot-product-id'); |
|
2890
|
+ var qnty=$("#vPQuantity").val(); |
|
2891
|
+ var data = {'action': 'qcld_wb_chatbot_add_to_cart','product_id': pId,'quantity': qnty }; |
|
2892
|
+ //add to cart ajax handler. |
|
2893
|
+ wpwKits.ajax(data).done(function (response) { |
|
2894
|
+ //Change button text |
|
2895
|
+ if(response=="simple"){ |
|
2896
|
+ //Showing cart. |
|
2897
|
+ wpwKits.showCart(); |
|
2898
|
+ //handle the active tab on chat board. |
|
2899
|
+ $('.wp-chatbot-operation-option').each(function(){ |
|
2900
|
+ if($(this).attr('data-option')=='cart'){ |
|
2901
|
+ $(this).parent().addClass('wp-chatbot-operation-active'); |
|
2902
|
+ }else{ |
|
2903
|
+ $(this).parent().removeClass('wp-chatbot-operation-active'); |
|
2904
|
+ } |
|
2905
|
+ }); |
|
2906
|
+ } |
|
2907
|
+ //Hide the shortcode and chat ui product details. |
|
2908
|
+ $('.wp-chatbot-product-container').removeClass('active-chatbot-product-details'); |
|
2909
|
+ }); |
|
2910
|
+ }); |
|
2911
|
+ //Add to cart operation for variable product. |
|
2912
|
+ $(document).on('click','#wp-chatbot-variation-add-to-cart',function(event) { |
|
2913
|
+ event.preventDefault(); |
|
2914
|
+ var pId=$(this).attr('wp-chatbot-product-id'); |
|
2915
|
+ var quanity=$('#vPQuantity').val(); |
|
2916
|
+ var variation_id=$(this).attr('variation_id'); |
|
2917
|
+ var attributes=new Array(); |
|
2918
|
+ $.each($("#wp-chatbot-variation-data select"), function(){ |
|
2919
|
+ var attribute = $(this).attr('name')+'#'+ $(this).find('option:selected').text(); |
|
2920
|
+ attributes.push(attribute); |
|
2921
|
+ }); |
|
2922
|
+ var data = { |
|
2923
|
+ 'action': 'qcld_variable_add_to_cart', |
|
2924
|
+ 'p_id': pId, |
|
2925
|
+ 'quantity': quanity, |
|
2926
|
+ 'variations_id':variation_id, |
|
2927
|
+ 'attributes':attributes |
|
2928
|
+ }; |
|
2929
|
+ //add to cart ajax handler. |
|
2930
|
+ wpwKits.ajax(data).done(function (response) { |
|
2931
|
+ //Change button text |
|
2932
|
+ if(response=="variable"){ |
|
2933
|
+ //Showing cart. |
|
2934
|
+ wpwKits.showCart(); |
|
2935
|
+ //handle the active tab on chat board. |
|
2936
|
+ //handle the active tab on chat board. |
|
2937
|
+ $('.wp-chatbot-operation-option').each(function(){ |
|
2938
|
+ if($(this).attr('data-option')=='cart'){ |
|
2939
|
+ $(this).parent().addClass('wp-chatbot-operation-active'); |
|
2940
|
+ }else{ |
|
2941
|
+ $(this).parent().removeClass('wp-chatbot-operation-active'); |
|
2942
|
+ } |
|
2943
|
+ }); |
|
2944
|
+ } |
|
2945
|
+ //Hide the shortcode and chat ui product details. |
|
2946
|
+ $('.wp-chatbot-product-container').removeClass('active-chatbot-product-details'); |
|
2947
|
+ }); |
|
2948
|
+ }); |
|
2949
|
+ //Update cart. |
|
2950
|
+ $(document).on("change", ".qcld-wp-chatbot-cart-item-qnty", function () { |
|
2951
|
+ //Update editor only for chat ui |
|
2952
|
+ if($('#wp-chatbot-shortcode-template-container').length == 0) { |
|
2953
|
+ wpwKits.disableEditor(wpwKits.randomMsg(globalwpw.settings.obj.cart_updating)); |
|
2954
|
+ } |
|
2955
|
+ var currentItem=$(this); |
|
2956
|
+ setTimeout(function () { |
|
2957
|
+ var item_key=currentItem.attr('data-cart-item'); |
|
2958
|
+ var qnty=currentItem.val(); |
|
2959
|
+ var data = {'action': 'qcld_wb_chatbot_update_cart_item_number','cart_item_key':item_key,'qnty':qnty}; |
|
2960
|
+ wpwKits.ajax(data).done(function () { |
|
2961
|
+ //Showing cart. |
|
2962
|
+ wpwKits.showCart(); |
|
2963
|
+ }); |
|
2964
|
+ }, globalwpw.settings.preLoadingTime); |
|
2965
|
+ }); |
|
2966
|
+ //remove the cart item from global cart. |
|
2967
|
+ $(document).on("click", ".wp-chatbot-remove-cart-item", function () { |
|
2968
|
+ //Update editor only for chat ui |
|
2969
|
+ if($('#wp-chatbot-shortcode-template-container').length == 0) { |
|
2970
|
+ wpwKits.disableEditor(wpwKits.randomMsg(globalwpw.settings.obj.cart_removing)); |
|
2971
|
+ } |
|
2972
|
+ var item=$(this).attr('data-cart-item'); |
|
2973
|
+ var data = {'action': 'qcld_wb_chatbot_cart_item_remove', 'cart_item':item }; |
|
2974
|
+ wpwKits.ajax(data).done(function () { |
|
2975
|
+ //Showing cart. |
|
2976
|
+ wpwKits.showCart(); |
|
2977
|
+ }) |
|
2978
|
+ }); |
|
2979
|
+ /*Support query answering.. **/ |
|
2980
|
+ $(document).on('click','.qcld-chatbot-support-items',function (e) { |
|
2981
|
+ var shopperChoose=$(this).text(); |
|
2982
|
+ var queryIndex=$(this).attr('data-query-index'); |
|
2983
|
+ wpwMsg.shopper_choice(shopperChoose); |
|
2984
|
+ //Now answering the query. |
|
2985
|
+ var queryAns=globalwpw.settings.obj.support_ans[queryIndex]; |
|
2986
|
+ wpwMsg.single(queryAns); |
|
2987
|
+ //Asking email after showing answer. |
|
2988
|
+ var orPhoneSuggest=''; |
|
2989
|
+ setTimeout(function(){ |
|
2990
|
+ if(globalwpw.settings.obj.call_sup!=1) { |
|
2991
|
+ orPhoneSuggest = '<span class="qcld-chatbot-suggest-phone" >' + wpwKits.randomMsg(globalwpw.settings.obj.support_phone) + '</span>'; |
|
2992
|
+ } |
|
2993
|
+ var orEmailSuggest='<span class="qcld-chatbot-suggest-email">'+wpwKits.randomMsg(globalwpw.settings.obj.support_email)+'</span>'; |
|
2994
|
+ wpwKits.suggestEmail(orPhoneSuggest+orEmailSuggest); |
|
2995
|
+ },globalwpw.settings.wildcardsShowTime); |
|
2996
|
+ }); |
|
2997
|
+ /*Support Email **/ |
|
2998
|
+ $(document).on('click','.qcld-chatbot-suggest-email',function (e) { |
|
2999
|
+ var shopperChoice=$(this).text(); |
|
3000
|
+ wpwMsg.shopper_choice(shopperChoice); |
|
3001
|
+ //Then ask email address |
|
3002
|
+ if(typeof(globalwpw.hasNameCookie)=='undefined'|| globalwpw.hasNameCookie==''){ |
|
3003
|
+ var shopperName= globalwpw.settings.obj.shopper_demo_name; |
|
3004
|
+ }else{ |
|
3005
|
+ var shopperName=globalwpw.hasNameCookie; |
|
3006
|
+ } |
|
3007
|
+ var ask_msg = wpwKits.randomMsg(globalwpw.settings.obj.asking_email); |
|
3008
|
+ var askEmail = (globalwpw.settings.obj.skip_wp_greetings=='1' || globalwpw.settings.obj.skip_greetings_and_menu =='1') ? wpwKits.randomMsg(globalwpw.settings.obj.hello)+' '+ ask_msg : wpwKits.randomMsg(globalwpw.settings.obj.hello) + ' '+shopperName+'! '+ ask_msg; |
|
3009
|
+ wpwMsg.single(askEmail); |
|
3010
|
+ //Now updating the support part as . |
|
3011
|
+ globalwpw.supportStep='email'; |
|
3012
|
+ globalwpw.wildCard=1; |
|
3013
|
+ //keeping value in localstorage |
|
3014
|
+ localStorage.setItem("wildCard", globalwpw.wildCard); |
|
3015
|
+ localStorage.setItem("supportStep", globalwpw.supportStep); |
|
3016
|
+ }); |
|
3017
|
+ /*site Search*/ |
|
3018
|
+ $(document).on('click','.qcld-chatbot-site-search',function (e) { |
|
3019
|
+ var shopperChoice=$(this).text(); |
|
3020
|
+ wpwMsg.shopper_choice(shopperChoice); |
|
3021
|
+ //Then ask email address |
|
3022
|
+ if(typeof(globalwpw.hasNameCookie)=='undefined'|| globalwpw.hasNameCookie==''){ |
|
3023
|
+ var shopperName= globalwpw.settings.obj.shopper_demo_name; |
|
3024
|
+ }else{ |
|
3025
|
+ var shopperName=globalwpw.hasNameCookie; |
|
3026
|
+ } |
|
3027
|
+ var ask_msg = wp_chatbot_obj.search_keyword; |
|
3028
|
+ var askEmail = (globalwpw.settings.obj.skip_wp_greetings=='1' || globalwpw.settings.obj.skip_greetings_and_menu =='1') ? 'Hello ' + ask_msg : 'Hello '+shopperName+'! '+ ask_msg; |
|
3029
|
+ wpwMsg.single(askEmail); |
|
3030
|
+ //Now updating the support part as . |
|
3031
|
+ globalwpw.supportStep='search'; |
|
3032
|
+ globalwpw.wildCard=1; |
|
3033
|
+ //keeping value in localstorage |
|
3034
|
+ localStorage.setItem("wildCard", globalwpw.wildCard); |
|
3035
|
+ localStorage.setItem("supportStep", globalwpw.supportStep); |
|
3036
|
+ }); |
|
3037
|
+ /*Support Phone **/ |
|
3038
|
+ $(document).on('click','.qcld-chatbot-suggest-phone',function (e) { |
|
3039
|
+ var shopperChoice=$(this).text(); |
|
3040
|
+ wpwMsg.shopper_choice(shopperChoice); |
|
3041
|
+ //Then ask email address |
|
3042
|
+ if(typeof(globalwpw.hasNameCookie)=='undefined'|| globalwpw.hasNameCookie==''){ |
|
3043
|
+ var shopperName= globalwpw.settings.obj.shopper_demo_name; |
|
3044
|
+ }else{ |
|
3045
|
+ var shopperName=globalwpw.hasNameCookie; |
|
3046
|
+ } |
|
3047
|
+ var ask_msg = wpwKits.randomMsg(globalwpw.settings.obj.asking_phone); |
|
3048
|
+ var askEmail = (globalwpw.settings.obj.skip_wp_greetings=='1' || globalwpw.settings.obj.skip_greetings_and_menu =='1') ? 'Hello ' + ask_msg : 'Hello '+shopperName+'! '+ ask_msg; |
|
3049
|
+ wpwMsg.single(askEmail); |
|
3050
|
+ //Now updating the support part as . |
|
3051
|
+ globalwpw.supportStep='phone'; |
|
3052
|
+ globalwpw.wildCard=1; |
|
3053
|
+ //keeping value in localstorage |
|
3054
|
+ localStorage.setItem("wildCard", globalwpw.wildCard); |
|
3055
|
+ localStorage.setItem("supportStep", globalwpw.supportStep); |
|
3056
|
+ }); |
|
3057
|
+ //Show chat,cart and recently view products by click event. |
|
3058
|
+ $(document).on('click','.wp-chatbot-operation-option',function (e) { |
|
3059
|
+ e.preventDefault(); |
|
3060
|
+ var oppt=$(this).attr('data-option'); |
|
3061
|
+ if(oppt=='recent' && globalwpw.wpwIsWorking==0){ |
|
3062
|
+ wpwKits.disableEditor(globalwpw.settings.obj.sys_key_product); |
|
3063
|
+ var data = {'action':'qcld_wb_chatbot_recently_viewed_products'}; |
|
3064
|
+ wpwKits.ajax(data).done(function (response) { |
|
3065
|
+ $(globalwpw.settings.messageWrapper).html(response); |
|
3066
|
+ }); |
|
3067
|
+ //First remove wp-chatbot-operation-active class from all selector |
|
3068
|
+ $('.wp-chatbot-operation-option').parent().removeClass('wp-chatbot-operation-active'); |
|
3069
|
+ //then add the active class to current element. |
|
3070
|
+ $(this).parent().addClass('wp-chatbot-operation-active'); |
|
3071
|
+ }else if(oppt=='chat' && globalwpw.wpwIsWorking==0){ |
|
3072
|
+ $(globalwpw.settings.messageWrapper).html(localStorage.getItem("wpwHitory")); |
|
3073
|
+ wpwKits.scrollTo(); |
|
3074
|
+ wpwKits.enableEditor(wpwKits.randomMsg(globalwpw.settings.obj.send_a_msg)); |
|
3075
|
+ //First remove wp-chatbot-operation-active class from all selector |
|
3076
|
+ $('.wp-chatbot-operation-option').parent().removeClass('wp-chatbot-operation-active'); |
|
3077
|
+ //then add the active class to current element. |
|
3078
|
+ $(this).parent().addClass('wp-chatbot-operation-active'); |
|
3079
|
+ } else if(oppt=='cart' && globalwpw.wpwIsWorking==0){ |
|
3080
|
+ wpwKits.showCart(); |
|
3081
|
+ //First remove wp-chatbot-operation-active class from all selector |
|
3082
|
+ $('.wp-chatbot-operation-option').parent().removeClass('wp-chatbot-operation-active'); |
|
3083
|
+ //then add the active class to current element. |
|
3084
|
+ $(this).parent().addClass('wp-chatbot-operation-active'); |
|
3085
|
+ } else if(oppt=='help' && globalwpw.wpwIsWorking==0){ |
|
3086
|
+ if( $('.wp-chatbot-messages-container').length==0) { |
|
3087
|
+ //if from other nob then goo to the chat window |
|
3088
|
+ $(globalwpw.settings.messageWrapper).html(localStorage.getItem("wpwHitory")); |
|
3089
|
+ //Showing help message |
|
3090
|
+ setTimeout(function () { |
|
3091
|
+ wpwKits.scrollTo(); |
|
3092
|
+ var helpWelcome = wpwKits.randomMsg(globalwpw.settings.obj.help_welcome); |
|
3093
|
+ var helpMsg = wpwKits.decodehtml(wpwKits.randomMsg(globalwpw.settings.obj.help_msg)); |
|
3094
|
+ wpwMsg.double(helpWelcome,helpMsg); |
|
3095
|
+ //dialogflow |
|
3096
|
+ if(globalwpw.settings.obj.ai_df_enable==1 && globalwpw.df_status_lock==0){ |
|
3097
|
+ globalwpw.wildCard=0; |
|
3098
|
+ globalwpw.ai_step=1; |
|
3099
|
+ localStorage.setItem("wildCard", globalwpw.wildCard); |
|
3100
|
+ localStorage.setItem("aiStep", globalwpw.ai_step); |
|
3101
|
+ } |
|
3102
|
+ },globalwpw.settings.preLoadingTime); |
|
3103
|
+ }else{ |
|
3104
|
+ //Showing help message on chat self window. |
|
3105
|
+ var helpWelcome = wpwKits.randomMsg(globalwpw.settings.obj.help_welcome); |
|
3106
|
+ var helpMsg = wpwKits.randomMsg(globalwpw.settings.obj.help_msg); |
|
3107
|
+ wpwMsg.double(helpWelcome,helpMsg); |
|
3108
|
+ //dialogflow |
|
3109
|
+ if(globalwpw.settings.obj.ai_df_enable==1 && globalwpw.df_status_lock==0){ |
|
3110
|
+ globalwpw.wildCard=0; |
|
3111
|
+ globalwpw.ai_step=1; |
|
3112
|
+ localStorage.setItem("wildCard", globalwpw.wildCard); |
|
3113
|
+ localStorage.setItem("aiStep", globalwpw.ai_step); |
|
3114
|
+ } |
|
3115
|
+ } |
|
3116
|
+ //First remove wp-chatbot-operation-active class from all selector |
|
3117
|
+ $('.wp-chatbot-operation-option').parent().removeClass('wp-chatbot-operation-active'); |
|
3118
|
+ //then add the active class to current element. |
|
3119
|
+ $(this).parent().addClass('wp-chatbot-operation-active'); |
|
3120
|
+ } else if(oppt=='support' && globalwpw.wpwIsWorking==0){ |
|
3121
|
+ if( $('.wp-chatbot-messages-container').length==0) { |
|
3122
|
+ //if from other nob then goo to the chat window |
|
3123
|
+ $(globalwpw.settings.messageWrapper).html(localStorage.getItem("wpwHitory")); |
|
3124
|
+ //Showing help message |
|
3125
|
+ setTimeout(function () { |
|
3126
|
+ wpwKits.scrollTo(); |
|
3127
|
+ globalwpw.wildCard=1; |
|
3128
|
+ globalwpw.supportStep='welcome'; |
|
3129
|
+ wpwTree.support(globalwpw.settings.obj.sys_key_support.toLowerCase()); |
|
3130
|
+ },globalwpw.settings.preLoadingTime); |
|
3131
|
+ }else{ |
|
3132
|
+ //Showing help message on chat self window. |
|
3133
|
+ globalwpw.wildCard=1; |
|
3134
|
+ globalwpw.supportStep='welcome'; |
|
3135
|
+ wpwTree.support(globalwpw.settings.obj.sys_key_support.toLowerCase()); |
|
3136
|
+ } |
|
3137
|
+ //First remove wp-chatbot-operation-active class from all selector |
|
3138
|
+ $('.wp-chatbot-operation-option').parent().removeClass('wp-chatbot-operation-active'); |
|
3139
|
+ //then add the active class to current element. |
|
3140
|
+ $(this).parent().addClass('wp-chatbot-operation-active'); |
|
3141
|
+ } |
|
3142
|
+ //show chat wrapper and hide cart-checkout wrapper |
|
3143
|
+ $(globalwpw.settings.messageWrapper).show(); |
|
3144
|
+ $('#wp-chatbot-checkout-short-code').hide(); |
|
3145
|
+ $('#wp-chatbot-cart-short-code').hide(); |
|
3146
|
+ }); |
|
3147
|
+ $(document).on('click','.qcld-chatbot-reset-btn',function (e) { |
|
3148
|
+ e.preventDefault(); |
|
3149
|
+ var actionType=$(this).attr('reset-data'); |
|
3150
|
+ if(actionType=='yes'){ |
|
3151
|
+ |
|
3152
|
+ $('#wp-chatbot-messages-container').html(''); |
|
3153
|
+ localStorage.removeItem('shopper'); |
|
3154
|
+ globalwpw.wildCard=0; |
|
3155
|
+ globalwpw.ai_step=0; |
|
3156
|
+ localStorage.setItem("wildCard", globalwpw.wildCard); |
|
3157
|
+ localStorage.setItem("aiStep", globalwpw.ai_step); |
|
3158
|
+ globalwpw.formfieldid = ''; |
|
3159
|
+ localStorage.setItem("formfieldid", globalwpw.formfieldid); |
|
3160
|
+ globalwpw.formStep='welcome'; |
|
3161
|
+ localStorage.setItem("formStep", globalwpw.formStep); |
|
3162
|
+ globalwpw.formid=''; |
|
3163
|
+ localStorage.setItem("formid", globalwpw.formid); |
|
3164
|
+ globalwpw.formentry = 0; |
|
3165
|
+ localStorage.setItem("formentry", globalwpw.formentry); |
|
3166
|
+ localStorage.removeItem("cx-name" ); |
|
3167
|
+ localStorage.removeItem("cx-diaplayname" ); |
|
3168
|
+ localStorage.removeItem("cx-languagecode" ); |
|
3169
|
+ localStorage.removeItem("cx-timezone" ); |
|
3170
|
+ var number = Math.random() // 0.9394456857981651 |
|
3171
|
+ number.toString(36); // '0.xtis06h6' |
|
3172
|
+ var id = number.toString(36).substr(2); // 'xtis06h6' |
|
3173
|
+ localStorage.setItem('botsessionid', id); |
|
3174
|
+ wpwWelcome.greeting(); |
|
3175
|
+ } else if(actionType=='no'){ |
|
3176
|
+ wpwAction.bot(globalwpw.settings.obj.sys_key_help.toLowerCase()); |
|
3177
|
+ } |
|
3178
|
+ }); |
|
3179
|
+ return this; |
|
3180
|
+ }; |
|
3181
|
+ //Deafault value for wpwbot.If nothing passes from the work station |
|
3182
|
+ //Then defaults value will be used. |
|
3183
|
+ $.wpwbot.defaults={ |
|
3184
|
+ obj:{}, |
|
3185
|
+ editor_handler:0, |
|
3186
|
+ sendButton:'#wp-chatbot-send-message', |
|
3187
|
+ messageEditor:'#wp-chatbot-editor', |
|
3188
|
+ messageContainer:'#wp-chatbot-messages-container', |
|
3189
|
+ messageWrapper:'.wp-chatbot-messages-wrapper', |
|
3190
|
+ botContainer:'.wp-chatbot-ball-inner', |
|
3191
|
+ messageLastChild:'#wp-chatbot-messages-container li:last', |
|
3192
|
+ messageLastBot:'#wp-chatbot-messages-container .wp-chatbot-msg:last .wp-chatbot-paragraph', |
|
3193
|
+ preLoadingTime:0, |
|
3194
|
+ wildcardsShowTime:5000, |
|
3195
|
+ } |
|
3196
|
+ |
|
3197
|
+ document.addEventListener("click", function(e) { |
|
3198
|
+ // Toggle share menu |
|
3199
|
+ if (e.target.closest(".share-toggle")) { |
|
3200
|
+ e.preventDefault(); |
|
3201
|
+ let menu = e.target.closest(".qcld-share").querySelector(".share-menu"); |
|
3202
|
+ menu.style.display = menu.style.display === "none" ? "block" : "none"; |
|
3203
|
+ } |
|
3204
|
+ |
|
3205
|
+ // Find message content dynamically |
|
3206
|
+ let msgItem = e.target.closest(".wp-chatbot-msg"); |
|
3207
|
+ if (!msgItem) return; |
|
3208
|
+ |
|
3209
|
+ let msgContent = msgItem.querySelector(".wp-chatbot-paragraph"); |
|
3210
|
+ if (!msgContent) return; |
|
3211
|
+ |
|
3212
|
+ // Extract plain text |
|
3213
|
+ let msgText = msgContent.innerText.trim(); |
|
3214
|
+ let shareSite = window.location.origin; // Get the site URL dynamically (e.g., "https://www.example.com") |
|
3215
|
+ // Ensure a trailing slash if it's meant to represent the root of the site |
|
3216
|
+ if (!shareSite.endsWith('/')) { |
|
3217
|
+ shareSite += '/'; |
|
3218
|
+ } |
|
3219
|
+ let fullMsg = `${msgText}\n-- ${shareSite}`; |
|
3220
|
+ let encodedMsg = encodeURIComponent(fullMsg); |
|
3221
|
+ |
|
3222
|
+ // Facebook (requires App ID) |
|
3223
|
+ if (e.target.closest(".share-fb")) { |
|
3224
|
+ e.preventDefault(); |
|
3225
|
+ |
|
3226
|
+ // You must include a URL even if you're just sharing text |
|
3227
|
+ const shareURL = encodeURIComponent(window.location.href); // or your chatbot page URL |
|
3228
|
+ const fbShareURL = "https://www.facebook.com/sharer/sharer.php?u=" + shareURL + ""e=" + encodedMsg; |
|
3229
|
+ |
|
3230
|
+ window.open(fbShareURL, "_blank", "width=600,height=400"); |
|
3231
|
+ } |
|
3232
|
+ |
|
3233
|
+ // WhatsApp |
|
3234
|
+ if (e.target.closest(".share-wa")) { |
|
3235
|
+ e.preventDefault(); |
|
3236
|
+ window.open("https://wa.me/?text=" + encodedMsg, "_blank"); |
|
3237
|
+ } |
|
3238
|
+ |
|
3239
|
+ // X (Twitter) |
|
3240
|
+ if (e.target.closest(".share-x")) { |
|
3241
|
+ e.preventDefault(); |
|
3242
|
+ window.open("https://twitter.com/intent/tweet?text=" + encodedMsg, "_blank"); |
|
3243
|
+ } |
|
3244
|
+ |
|
3245
|
+ // Email |
|
3246
|
+ if (e.target.closest(".share-email")) { |
|
3247
|
+ e.preventDefault(); |
|
3248
|
+ window.location.href = "mailto:?subject=Chatbot Message&body=" + encodedMsg; |
|
3249
|
+ } |
|
3250
|
+ }); |
|
3251
|
+ jQuery(document).ready(function($) { |
|
3252
|
+ |
|
3253
|
+ let reportedMessage = ""; |
|
3254
|
+ let modalElements = {}; // Store references to modal elements |
|
3255
|
+ let isModalInitialized = false; // Flag to prevent re-attaching listeners |
|
3256
|
+ |
|
3257
|
+ /** |
|
3258
|
+ * Initializes the report modal by finding its elements and attaching event listeners. |
|
3259
|
+ * This function is designed to be called only once, the first time the report icon is clicked, |
|
3260
|
+ * to ensure all DOM elements are available. |
|
3261
|
+ * @returns {boolean} True if initialization was successful, false otherwise. |
|
3262
|
+ */ |
|
3263
|
+ function setupReportModal() { |
|
3264
|
+ if (isModalInitialized) { |
|
3265
|
+ return true; // Already initialized |
|
3266
|
+ } |
|
3267
|
+ |
|
3268
|
+ const modal = document.getElementById("wpbot-report-modal"); |
|
3269
|
+ const emailInput = document.getElementById("wpbot-report-email"); |
|
3270
|
+ const textInput = document.getElementById("wpbot-report-text"); |
|
3271
|
+ const cancelBtn = document.getElementById("wpbot-report-cancel"); |
|
3272
|
+ const reportForm = document.getElementById("wpbot-report-form"); |
|
3273
|
+ |
|
3274
|
+ if (!modal || !emailInput || !textInput || !cancelBtn || !reportForm) { |
|
3275
|
+ console.error("❌ One or more modal elements missing in DOM. Cannot initialize report modal."); |
|
3276
|
+ return false; // Initialization failed |
|
3277
|
+ } |
|
3278
|
+ |
|
3279
|
+ // Store references to the elements |
|
3280
|
+ modalElements = { modal, emailInput, textInput, cancelBtn, reportForm }; |
|
3281
|
+ |
|
3282
|
+ // Attach event listener for the cancel button |
|
3283
|
+ modalElements.cancelBtn.addEventListener("click", function() { |
|
3284
|
+ modalElements.modal.style.display = "none"; |
|
3285
|
+ }); |
|
3286
|
+ |
|
3287
|
+ // Attach event listener for the form submission |
|
3288
|
+ modalElements.reportForm.addEventListener("submit", function(e) { |
|
3289
|
+ e.preventDefault(); |
|
3290
|
+ |
|
3291
|
+ let email = modalElements.emailInput.value.trim(); |
|
3292
|
+ let reportText = modalElements.textInput.value.trim(); |
|
3293
|
+ |
|
3294
|
+ if (!email || !reportText) { |
|
3295
|
+ alert("Please fill in both fields."); |
|
3296
|
+ return; |
|
3297
|
+ } |
|
3298
|
+ |
|
3299
|
+ // Save email to localStorage |
|
3300
|
+ localStorage.setItem("shopperemail", email); |
|
3301
|
+ |
|
3302
|
+ // Build meta info for the report |
|
3303
|
+ let meta = "Source URL: " + window.location.href + " | User Agent: " + navigator.userAgent; |
|
3304
|
+ |
|
3305
|
+ // Send report via AJAX |
|
3306
|
+ $.post(wp_chatbot_obj.ajax_url, { |
|
3307
|
+ action: "wpbot_save_report", |
|
3308
|
+ user_id: globalwpw.settings.obj.current_user_id, |
|
3309
|
+ conversation_id: 3, |
|
3310
|
+ message: reportedMessage, // Use the message captured when the icon was clicked |
|
3311
|
+ report_text: reportText, |
|
3312
|
+ email: email, |
|
3313
|
+ meta_info: meta |
|
3314
|
+ }, function(response) { |
|
3315
|
+ if (response.success) { |
|
3316
|
+ console.log("Report sent successfully."); |
|
3317
|
+ // The original line `jQuery(e.target.closest(".fa fa-commenting-o")).addClass("submitted");` |
|
3318
|
+ // was incorrect as `e.target` here refers to the form, not the original icon. |
|
3319
|
+ // To mark the icon, a reference to it would need to be stored when it was clicked. |
|
3320
|
+ } else { |
|
3321
|
+ console.log("Failed to send report."); |
|
3322
|
+ } |
|
3323
|
+ modalElements.modal.style.display = "none"; // Hide modal after submission |
|
3324
|
+ }); |
|
3325
|
+ }); |
|
3326
|
+ |
|
3327
|
+ isModalInitialized = true; // Mark as initialized |
|
3328
|
+ return true; // Initialization successful |
|
3329
|
+ } |
|
3330
|
+ |
|
3331
|
+ // Event listener for clicks on the document to detect report icon clicks |
|
3332
|
+ document.addEventListener("click", function(e) { |
|
3333
|
+ if (e.target.closest(".fa-commenting-o")) { |
|
3334
|
+ e.preventDefault(); |
|
3335
|
+ console.log("Report icon clicked"); |
|
3336
|
+ |
|
3337
|
+ // Attempt to initialize the modal elements and listeners if not already done. |
|
3338
|
+ // This ensures elements are looked up only when needed, making it more robust |
|
3339
|
+ // against timing issues if the modal HTML is loaded asynchronously or late. |
|
3340
|
+ if (!setupReportModal()) { |
|
3341
|
+ return; // If initialization failed (elements not found), stop here. |
|
3342
|
+ } |
|
3343
|
+ |
|
3344
|
+ // Now that we are sure modal elements are available, proceed to open the modal. |
|
3345
|
+ let msgItem = e.target.closest(".wp-chatbot-msg"); |
|
3346
|
+ if (msgItem) { |
|
3347
|
+ reportedMessage = msgItem.querySelector(".wp-chatbot-paragraph").innerText.trim(); |
|
3348
|
+ } else { |
|
3349
|
+ reportedMessage = ""; // Fallback if message item not found |
|
3350
|
+ } |
|
3351
|
+ |
|
3352
|
+ // Prefill email from localStorage if available |
|
3353
|
+ let shopperEmail = localStorage.getItem("shopperemail"); |
|
3354
|
+ modalElements.emailInput.value = shopperEmail ? shopperEmail : ""; |
|
3355
|
+ |
|
3356
|
+ // Clear previous report text |
|
3357
|
+ modalElements.textInput.value = ""; |
|
3358
|
+ |
|
3359
|
+ // Display the modal |
|
3360
|
+ modalElements.modal.style.display = "block"; |
|
3361
|
+ } |
|
3362
|
+ }); |
|
3363
|
+ }); |
|
3364
|
+ jQuery(document).on('click', '.qc_wpbot_chat_link', function (e) { |
|
3365
|
+ console.log("Chat link clicked"); |
|
3366
|
+ e.preventDefault(); |
|
3367
|
+ jQuery("#wp-chatbot-ball").trigger("click"); |
|
3368
|
+ jQuery("#wp-chatbot-chat-container").show(); |
|
3369
|
+ }); |
|
3370
|
+ document.addEventListener("click", function (e) { |
|
3371
|
+ const likeIcon = e.target.closest(".dashicons-thumbs-up"); |
|
3372
|
+ const dislikeIcon = e.target.closest(".dashicons-thumbs-down"); |
|
3373
|
+ |
|
3374
|
+ if (!likeIcon && !dislikeIcon) return; // only handle like/dislike clicks |
|
3375
|
+ e.preventDefault(); |
|
3376
|
+ |
|
3377
|
+ const msgItem = e.target.closest(".wp-chatbot-msg"); |
|
3378
|
+ const feedbackContainer = jQuery(msgItem).find(".qcld-like-dislike-icon"); |
|
3379
|
+ const likeAnchor = jQuery(msgItem).find(".dashicons-thumbs-up").parent("a"); |
|
3380
|
+ const dislikeAnchor = jQuery(msgItem).find(".dashicons-thumbs-down").parent("a"); |
|
3381
|
+ |
|
3382
|
+ let feedbackType = ""; |
|
3383
|
+ let isToggleOff = false; |
|
3384
|
+ |
|
3385
|
+ if (likeIcon) { |
|
3386
|
+ // If like is already active → toggle it off |
|
3387
|
+ if (likeAnchor.hasClass("liked")) { |
|
3388
|
+ likeAnchor.removeClass("liked"); |
|
3389
|
+ likeIcon.classList.remove("liked"); |
|
3390
|
+ isToggleOff = true; |
|
3391
|
+ } else { |
|
3392
|
+ // Activate like, deactivate dislike |
|
3393
|
+ likeAnchor.addClass("liked"); |
|
3394
|
+ likeIcon.classList.add("liked"); |
|
3395
|
+ dislikeAnchor.removeClass("disliked"); |
|
3396
|
+ jQuery(msgItem).find(".dashicons-thumbs-down").removeClass("disliked"); |
|
3397
|
+ feedbackType = "like"; |
|
3398
|
+ } |
|
3399
|
+ } else if (dislikeIcon) { |
|
3400
|
+ // If dislike is already active → toggle it off |
|
3401
|
+ if (dislikeAnchor.hasClass("disliked")) { |
|
3402
|
+ dislikeAnchor.removeClass("disliked"); |
|
3403
|
+ dislikeIcon.classList.remove("disliked"); |
|
3404
|
+ isToggleOff = true; |
|
3405
|
+ } else { |
|
3406
|
+ // Activate dislike, deactivate like |
|
3407
|
+ dislikeAnchor.addClass("disliked"); |
|
3408
|
+ dislikeIcon.classList.add("disliked"); |
|
3409
|
+ likeAnchor.removeClass("liked"); |
|
3410
|
+ jQuery(msgItem).find(".fa-thumbs-o-up").removeClass("liked"); |
|
3411
|
+ feedbackType = "dislike"; |
|
3412
|
+ } |
|
3413
|
+ } |
|
3414
|
+ |
|
3415
|
+ // 🔹 Only send feedback if toggled ON |
|
3416
|
+ if (!isToggleOff && feedbackType) { |
|
3417
|
+ let message = msgItem.querySelector(".wp-chatbot-paragraph").innerText.trim(); |
|
3418
|
+ let meta = |
|
3419
|
+ "Source URL: " + |
|
3420
|
+ window.location.href + |
|
3421
|
+ " | User Agent: " + |
|
3422
|
+ navigator.userAgent; |
|
3423
|
+ |
|
3424
|
+ jQuery.post( |
|
3425
|
+ wp_chatbot_obj.ajax_url, |
|
3426
|
+ { |
|
3427
|
+ action: "wpbot_save_feedback", |
|
3428
|
+ user_id: globalwpw.settings.obj.current_user_id, |
|
3429
|
+ conversation_id: 3, |
|
3430
|
+ message: message, |
|
3431
|
+ feedback: feedbackType, |
|
3432
|
+ meta_info: meta, |
|
3433
|
+ }, |
|
3434
|
+ function (response) { |
|
3435
|
+ if (response.success) { |
|
3436
|
+ console.log("Feedback saved:", feedbackType); |
|
3437
|
+ } else { |
|
3438
|
+ console.log("Failed to save feedback."); |
|
3439
|
+ } |
|
3440
|
+ } |
|
3441
|
+ ); |
|
3442
|
+ } else { |
|
3443
|
+ console.log("Feedback toggled off, not saving."); |
|
3444
|
+ } |
|
3445
|
+ }); |
|
3446
|
+ |
|
3447
|
+// --------------------------------------------------------------------------- |
|
3448
|
+// Streaming helpers |
|
3449
|
+// --------------------------------------------------------------------------- |
|
3450
|
+ |
|
3451
|
+function qcldInlineMarkdown(text) { |
|
3452
|
+ text = text.replace(/`([^`]+)`/g, '<code>$1</code>'); |
|
3453
|
+ text = text.replace(/\*\*([^*]+)\*\*/g, '<strong>$1</strong>'); |
|
3454
|
+ text = text.replace(/__([^_]+)__/g, '<strong>$1</strong>'); |
|
3455
|
+ text = text.replace(/\*([^*\n]+)\*/g, '<em>$1</em>'); |
|
3456
|
+ text = text.replace(/_([^_\n]+)_/g, '<em>$1</em>'); |
|
3457
|
+ text = text.replace(/\[([^\]]+)\]\((https?:\/\/[^\s)]+)\)/g, |
|
3458
|
+ '<a href="$2" target="_blank" rel="noopener noreferrer">$1</a>'); |
|
3459
|
+ return text; |
|
3460
|
+} |
|
3461
|
+ |
|
3462
|
+function qcldParseMarkdown(text) { |
|
3463
|
+ if (!text) { return ''; } |
|
3464
|
+ var lines = text.split('\n'); |
|
3465
|
+ var html = ''; |
|
3466
|
+ var inCode = false; |
|
3467
|
+ var inUL = false; |
|
3468
|
+ var inOL = false; |
|
3469
|
+ var codeLines = []; |
|
3470
|
+ |
|
3471
|
+ function closeList() { |
|
3472
|
+ if (inUL) { html += '</ul>'; inUL = false; } |
|
3473
|
+ if (inOL) { html += '</ol>'; inOL = false; } |
|
3474
|
+ } |
|
3475
|
+ |
|
3476
|
+ for (var i = 0; i < lines.length; i++) { |
|
3477
|
+ var line = lines[i]; |
|
3478
|
+ |
|
3479
|
+ // Fenced code block toggle |
|
3480
|
+ if (/^```/.test(line)) { |
|
3481
|
+ if (inCode) { |
|
3482
|
+ html += '<pre><code>' + codeLines.join('\n').replace(/</g,'<').replace(/>/g,'>') + '</code></pre>'; |
|
3483
|
+ codeLines = []; |
|
3484
|
+ inCode = false; |
|
3485
|
+ } else { |
|
3486
|
+ closeList(); |
|
3487
|
+ inCode = true; |
|
3488
|
+ } |
|
3489
|
+ continue; |
|
3490
|
+ } |
|
3491
|
+ if (inCode) { codeLines.push(line); continue; } |
|
3492
|
+ |
|
3493
|
+ // Headings |
|
3494
|
+ var hm = line.match(/^(#{1,6})\s+(.*)/); |
|
3495
|
+ if (hm) { |
|
3496
|
+ closeList(); |
|
3497
|
+ var lvl = hm[1].length; |
|
3498
|
+ html += '<h' + lvl + '>' + qcldInlineMarkdown(hm[2]) + '</h' + lvl + '>'; |
|
3499
|
+ continue; |
|
3500
|
+ } |
|
3501
|
+ |
|
3502
|
+ // Horizontal rule |
|
3503
|
+ if (/^---+$/.test(line.trim())) { |
|
3504
|
+ closeList(); |
|
3505
|
+ html += '<hr>'; |
|
3506
|
+ continue; |
|
3507
|
+ } |
|
3508
|
+ |
|
3509
|
+ // Unordered list |
|
3510
|
+ var ulm = line.match(/^\s*[-*+]\s+(.*)/); |
|
3511
|
+ if (ulm) { |
|
3512
|
+ if (inOL) { html += '</ol>'; inOL = false; } |
|
3513
|
+ if (!inUL) { html += '<ul>'; inUL = true; } |
|
3514
|
+ html += '<li>' + qcldInlineMarkdown(ulm[1]) + '</li>'; |
|
3515
|
+ continue; |
|
3516
|
+ } |
|
3517
|
+ |
|
3518
|
+ // Ordered list |
|
3519
|
+ var olm = line.match(/^\s*\d+\.\s+(.*)/); |
|
3520
|
+ if (olm) { |
|
3521
|
+ if (inUL) { html += '</ul>'; inUL = false; } |
|
3522
|
+ if (!inOL) { html += '<ol>'; inOL = true; } |
|
3523
|
+ html += '<li>' + qcldInlineMarkdown(olm[1]) + '</li>'; |
|
3524
|
+ continue; |
|
3525
|
+ } |
|
3526
|
+ |
|
3527
|
+ // Blank line |
|
3528
|
+ if (line.trim() === '') { |
|
3529
|
+ closeList(); |
|
3530
|
+ html += '<br>'; |
|
3531
|
+ continue; |
|
3532
|
+ } |
|
3533
|
+ |
|
3534
|
+ // Normal line |
|
3535
|
+ closeList(); |
|
3536
|
+ html += qcldInlineMarkdown(line) + '<br>'; |
|
3537
|
+ } |
|
3538
|
+ |
|
3539
|
+ if (inCode) { html += '<pre><code>' + codeLines.join('\n') + '</code></pre>'; } |
|
3540
|
+ closeList(); |
|
3541
|
+ return html; |
|
3542
|
+} |
|
3543
|
+ |
|
3544
|
+function qcldTypeCharacterByCharacter($target, text, speed, onComplete) { |
|
3545
|
+ speed = speed || 10; |
|
3546
|
+ onComplete = onComplete || function(){}; |
|
3547
|
+ |
|
3548
|
+ var i = 0; |
|
3549
|
+ function type() { |
|
3550
|
+ if (i < text.length) { |
|
3551
|
+ $target.append(document.createTextNode(text.charAt(i))); |
|
3552
|
+ i++; |
|
3553
|
+ setTimeout(type, speed); |
|
3554
|
+ } else { |
|
3555
|
+ onComplete(); |
|
3556
|
+ } |
|
3557
|
+ } |
|
3558
|
+ type(); |
|
3559
|
+} |
|
3560
|
+ |
|
3561
|
+function qcldStreamOpenAI(dataObj) { |
|
3562
|
+ fetch(qcld_chatbot_obj.stream_endpoint, { |
|
3563
|
+ method: 'POST', |
|
3564
|
+ headers: { 'Content-Type': 'application/x-www-form-urlencoded' }, |
|
3565
|
+ body: new URLSearchParams(dataObj) |
|
3566
|
+ }) |
|
3567
|
+ .then(function(response) { |
|
3568
|
+ if (!response.ok || !response.body) { |
|
3569
|
+ throw new Error('Network response was not OK or empty body'); |
|
3570
|
+ } |
|
3571
|
+ |
|
3572
|
+ var reader = response.body.getReader(); |
|
3573
|
+ var decoder = new TextDecoder('utf-8'); |
|
3574
|
+ var buffer = ''; |
|
3575
|
+ var queue = []; |
|
3576
|
+ var isTyping = false; |
|
3577
|
+ var streamEnded = false; |
|
3578
|
+ var msgBuffer = ''; |
|
3579
|
+ |
|
3580
|
+ function finalize() { |
|
3581
|
+ var finalMsg = msgBuffer; |
|
3582
|
+ var isFormInProgress = qcldIsAiFormInProgress(); |
|
3583
|
+ |
|
3584
|
+ // The streaming endpoint never receives __AI_FORM_IN_PROGRESS__ markers |
|
3585
|
+ // (those are only added by the non-streaming PHP handler). So we also |
|
3586
|
+ // check whether the original request was sent with an active AI action. |
|
3587
|
+ if (dataObj.active_ai_action && dataObj.active_ai_action !== '') { |
|
3588
|
+ isFormInProgress = true; |
|
3589
|
+ } |
|
3590
|
+ |
|
3591
|
+ if (finalMsg.indexOf('__AI_FORM_IN_PROGRESS__') !== -1) { |
|
3592
|
+ isFormInProgress = true; |
|
3593
|
+ finalMsg = finalMsg.replace(/__AI_FORM_IN_PROGRESS__/g, '').trim(); |
|
3594
|
+ } |
|
3595
|
+ |
|
3596
|
+ // qcldIsAiFormInProgress() above only reflects context from BEFORE this |
|
3597
|
+ // response. If this response itself carries the AI_FORM_DATA completion |
|
3598
|
+ // block, the form is done as of now regardless of that stale history. |
|
3599
|
+ var isFormCompletion = finalMsg.indexOf('AI_FORM_DATA') !== -1; |
|
3600
|
+ if (isFormCompletion) { |
|
3601
|
+ isFormInProgress = false; |
|
3602
|
+ } |
|
3603
|
+ |
|
3604
|
+ finalMsg = wpwMsg.oncommand_filter(finalMsg); |
|
3605
|
+ |
|
3606
|
+ if (typeof globalwpw !== 'undefined' && typeof globalwpw.aiContext !== 'undefined') { |
|
3607
|
+ globalwpw.aiContext.push({role: 'assistant', content: finalMsg}); |
|
3608
|
+ if (globalwpw.aiContext.length > 10) { |
|
3609
|
+ globalwpw.aiContext.shift(); |
|
3610
|
+ } |
|
3611
|
+ } |
|
3612
|
+ |
|
3613
|
+ // Replace raw typed text with formatted HTML |
|
3614
|
+ var $para = jQuery('.wp-chatbot-msg').last().find('.wp-chatbot-paragraph'); |
|
3615
|
+ if (finalMsg.trim()) { |
|
3616
|
+ $para.html(qcldParseMarkdown(finalMsg)); |
|
3617
|
+ } |
|
3618
|
+ // Reactions (like/dislike/report/share) don't apply to the form |
|
3619
|
+ // completion summary card itself, only to normal AI chat replies. |
|
3620
|
+ if (!isFormInProgress && !isFormCompletion) { |
|
3621
|
+ jQuery(globalwpw.settings.messageContainer) |
|
3622
|
+ .find('.wp-chatbot-msg:last .qcld-like-dislike-icon') |
|
3623
|
+ .css('display', 'block'); |
|
3624
|
+ } |
|
3625
|
+ |
|
3626
|
+ if(!isFormInProgress && (globalwpw.settings.obj.qcld_disable_repited_startmenu != "1") && ((globalwpw.settings.obj.disable_back_to_start != '1' && globalwpw.settings.obj.skip_greetings_and_menu != 1))){ |
|
3627
|
+ wpwMsg.single_nobg( |
|
3628
|
+ '<span class="qcld-chatbot-wildcard qcld_back_to_start" data-wildcart="back">' + |
|
3629
|
+ wpwKits.randomMsg(globalwpw.settings.obj.back_to_start) + |
|
3630
|
+ '</span>' |
|
3631
|
+ ); |
|
3632
|
+ } |
|
3633
|
+ setTimeout(function() { |
|
3634
|
+ jQuery(globalwpw.settings.botContainer) |
|
3635
|
+ .stop(true) |
|
3636
|
+ .animate({ scrollTop: jQuery(globalwpw.settings.botContainer)[0].scrollHeight }, 400); |
|
3637
|
+ }, 150); |
|
3638
|
+ wpwKits.scrollTo(); |
|
3639
|
+ } |
|
3640
|
+ |
|
3641
|
+ function processQueue() { |
|
3642
|
+ if (isTyping || queue.length === 0) { |
|
3643
|
+ if (streamEnded && !isTyping && queue.length === 0) { |
|
3644
|
+ finalize(); |
|
3645
|
+ } |
|
3646
|
+ return; |
|
3647
|
+ } |
|
3648
|
+ |
|
3649
|
+ isTyping = true; |
|
3650
|
+ var nextChunk = queue.shift(); |
|
3651
|
+ msgBuffer += nextChunk; |
|
3652
|
+ |
|
3653
|
+ // If we've started receiving the data block or internal flags, hide it from the UI! |
|
3654
|
+ // We use '__AI_' as the trigger so it stops rendering even partial tags like '__AI_FORM_DATA__' or '__AI_FORM_IN_PROGRESS__'. |
|
3655
|
+ if (msgBuffer.indexOf('__AI_') !== -1) { |
|
3656
|
+ isTyping = false; |
|
3657
|
+ processQueue(); |
|
3658
|
+ return; |
|
3659
|
+ } |
|
3660
|
+ |
|
3661
|
+ var $para = jQuery('.wp-chatbot-msg').last().find('.wp-chatbot-paragraph'); |
|
3662
|
+ if ($para.length) { |
|
3663
|
+ $para.find('.wp-chatbot-comment-loader').remove(); |
|
3664
|
+ var $span = jQuery('<span>'); |
|
3665
|
+ $para.append($span); |
|
3666
|
+ qcldTypeCharacterByCharacter($span, nextChunk, 10, function() { |
|
3667
|
+ isTyping = false; |
|
3668
|
+ processQueue(); |
|
3669
|
+ wpwKits.scrollTo(); |
|
3670
|
+ }); |
|
3671
|
+ } else { |
|
3672
|
+ isTyping = false; |
|
3673
|
+ processQueue(); |
|
3674
|
+ } |
|
3675
|
+ } |
|
3676
|
+ |
|
3677
|
+ function read() { |
|
3678
|
+ reader.read().then(function(result) { |
|
3679
|
+ if (result.done) { return; } |
|
3680
|
+ |
|
3681
|
+ buffer += decoder.decode(result.value, { stream: true }); |
|
3682
|
+ var lines = buffer.split('\n'); |
|
3683
|
+ buffer = lines.pop(); |
|
3684
|
+ |
|
3685
|
+ for (var i = 0; i < lines.length; i++) { |
|
3686
|
+ var line = lines[i].trim(); |
|
3687
|
+ if (!line) { continue; } |
|
3688
|
+ if (line.indexOf('data:') === 0) { |
|
3689
|
+ var jsonStr = line.replace(/^data:\s*/, ''); |
|
3690
|
+ if (jsonStr === '[DONE]') { |
|
3691
|
+ streamEnded = true; |
|
3692
|
+ if (!isTyping && queue.length === 0) { finalize(); } |
|
3693
|
+ return; |
|
3694
|
+ } |
|
3695
|
+ try { |
|
3696
|
+ var parsed = JSON.parse(jsonStr); |
|
3697
|
+ var content = ''; |
|
3698
|
+ if (parsed.choices && parsed.choices[0] && parsed.choices[0].delta) { |
|
3699
|
+ content = parsed.choices[0].delta.content || ''; |
|
3700
|
+ } else if (parsed.delta && parsed.delta.content) { |
|
3701
|
+ content = parsed.delta.content; |
|
3702
|
+ } |
|
3703
|
+ if (content) { |
|
3704
|
+ queue.push(content); |
|
3705
|
+ processQueue(); |
|
3706
|
+ wpwKits.scrollTo(); |
|
3707
|
+ } |
|
3708
|
+ } catch(e) { |
|
3709
|
+ console.warn('Streaming parse error:', e, jsonStr); |
|
3710
|
+ } |
|
3711
|
+ } |
|
3712
|
+ } |
|
3713
|
+ read(); |
|
3714
|
+ }).catch(function(err) { console.error('Stream read error:', err); }); |
|
3715
|
+ } |
|
3716
|
+ |
|
3717
|
+ read(); |
|
3718
|
+ }) |
|
3719
|
+ .catch(function(err) { console.error('Stream fetch error:', err); }); |
|
3720
|
+} |
|
3721
|
+ |
|
3722
|
+})(jQuery); |