Changeset 3421683
- Timestamp:
- 12/17/2025 09:37:27 AM (4 months ago)
- Location:
- wpiko-chatbot
- Files:
-
- 68 added
- 6 edited
-
tags/1.0.7 (added)
-
tags/1.0.7/admin (added)
-
tags/1.0.7/admin/admin-page.php (added)
-
tags/1.0.7/admin/css (added)
-
tags/1.0.7/admin/css/admin-style.css (added)
-
tags/1.0.7/admin/css/ai-configuration.css (added)
-
tags/1.0.7/admin/css/conversation-mobile-style.css (added)
-
tags/1.0.7/admin/css/conversation-style.css (added)
-
tags/1.0.7/admin/css/dashboard-style.css (added)
-
tags/1.0.7/admin/css/file-management.css (added)
-
tags/1.0.7/admin/css/modal-style.css (added)
-
tags/1.0.7/admin/css/plugin-header.css (added)
-
tags/1.0.7/admin/css/transcript-styles.css (added)
-
tags/1.0.7/admin/includes (added)
-
tags/1.0.7/admin/includes/plugin-header.php (added)
-
tags/1.0.7/admin/js (added)
-
tags/1.0.7/admin/js/admin-script.js (added)
-
tags/1.0.7/admin/js/conversations.js (added)
-
tags/1.0.7/admin/js/dashboard.js (added)
-
tags/1.0.7/admin/js/file-management.js (added)
-
tags/1.0.7/admin/js/files-list.js (added)
-
tags/1.0.7/admin/js/modal-handlers.js (added)
-
tags/1.0.7/admin/js/models-info.js (added)
-
tags/1.0.7/admin/js/responses-api.js (added)
-
tags/1.0.7/admin/sections (added)
-
tags/1.0.7/admin/sections/ai-configuration-section.php (added)
-
tags/1.0.7/admin/sections/api-key-section.php (added)
-
tags/1.0.7/admin/sections/chatbot-menu-section.php (added)
-
tags/1.0.7/admin/sections/chatbot-style-section.php (added)
-
tags/1.0.7/admin/sections/conversations-section.php (added)
-
tags/1.0.7/admin/sections/dashboard-section.php (added)
-
tags/1.0.7/admin/sections/error-messages-section.php (added)
-
tags/1.0.7/admin/sections/floating-chatbot-section.php (added)
-
tags/1.0.7/admin/sections/questions-section.php (added)
-
tags/1.0.7/admin/sections/shortcode-chatbot-section.php (added)
-
tags/1.0.7/admin/templates (added)
-
tags/1.0.7/admin/templates/admin-wrapper.php (added)
-
tags/1.0.7/admin/templates/file-management.php (added)
-
tags/1.0.7/assets (added)
-
tags/1.0.7/assets/images (added)
-
tags/1.0.7/assets/images/chatbot-icon.png (added)
-
tags/1.0.7/chatbot-interface.php (added)
-
tags/1.0.7/css (added)
-
tags/1.0.7/css/frontend-transcript-styles.css (added)
-
tags/1.0.7/css/wpiko-chatbot.css (added)
-
tags/1.0.7/includes (added)
-
tags/1.0.7/includes/api-helpers.php (added)
-
tags/1.0.7/includes/cache-management.php (added)
-
tags/1.0.7/includes/conversation-handler.php (added)
-
tags/1.0.7/includes/conversation-translation.php (added)
-
tags/1.0.7/includes/files-list-handler.php (added)
-
tags/1.0.7/includes/floating-chatbot.php (added)
-
tags/1.0.7/includes/instructions-handler.php (added)
-
tags/1.0.7/includes/logging.php (added)
-
tags/1.0.7/includes/markdown-handler.php (added)
-
tags/1.0.7/includes/responses-api.php (added)
-
tags/1.0.7/includes/sound-functions.php (added)
-
tags/1.0.7/includes/transcript-generator.php (added)
-
tags/1.0.7/index.php (added)
-
tags/1.0.7/js (added)
-
tags/1.0.7/js/chatbot-sound.js (added)
-
tags/1.0.7/js/howler.min.js (added)
-
tags/1.0.7/js/wpiko-chatbot.js (added)
-
tags/1.0.7/readme.txt (added)
-
tags/1.0.7/sounds (added)
-
tags/1.0.7/sounds/error-notification.wav (added)
-
tags/1.0.7/sounds/message-notification.wav (added)
-
tags/1.0.7/wpiko-chatbot.php (added)
-
trunk/admin/js/models-info.js (modified) (13 diffs)
-
trunk/admin/js/responses-api.js (modified) (17 diffs)
-
trunk/admin/sections/ai-configuration-section.php (modified) (2 diffs)
-
trunk/includes/responses-api.php (modified) (5 diffs)
-
trunk/readme.txt (modified) (2 diffs)
-
trunk/wpiko-chatbot.php (modified) (17 diffs)
Legend:
- Unmodified
- Added
- Removed
-
wpiko-chatbot/trunk/admin/js/models-info.js
r3353266 r3421683 5 5 */ 6 6 7 jQuery(document).ready(function ($) {7 jQuery(document).ready(function ($) { 8 8 console.log('Models Info script loaded'); 9 9 10 10 // Model information data based on provided table 11 11 const modelsData = { 12 'gpt-5.2': { 13 displayName: 'GPT-5.2', 14 description: 'The best model for coding and agentic tasks across industries', 15 reasoning: 4, 16 intelligence: null, 17 speed: 4, 18 contextWindow: '400,000', 19 maxOutputTokens: '128,000', 20 cost: 'Premium flagship +', 21 badge: 'Latest' 22 }, 23 'gpt-5.2-chat-latest': { 24 displayName: 'GPT-5.2 Chat', 25 description: 'GPT-5.2 model used in ChatGPT', 26 reasoning: null, 27 intelligence: 3, 28 speed: 3, 29 contextWindow: '128,000', 30 maxOutputTokens: '16,384', 31 cost: 'Premium flagship +', 32 badge: 'Best Chat' 33 }, 34 'gpt-5.1': { 35 displayName: 'GPT-5.1', 36 description: 'The best model for coding and agentic tasks with configurable reasoning effort', 37 reasoning: 4, 38 intelligence: null, 39 speed: 4, 40 contextWindow: '400,000', 41 maxOutputTokens: '128,000', 42 cost: 'Premium flagship', 43 badge: 'Enhanced' 44 }, 45 'gpt-5.1-chat-latest': { 46 displayName: 'GPT-5.1 Chat', 47 description: 'GPT-5.1 model used in ChatGPT', 48 reasoning: null, 49 intelligence: 3, 50 speed: 3, 51 contextWindow: '128,000', 52 maxOutputTokens: '16,384', 53 cost: 'Premium flagship', 54 badge: 'Conversational' 55 }, 12 56 'gpt-5': { 13 57 displayName: 'GPT-5', 14 58 description: 'The best model for coding and agentic tasks across domains', 15 59 reasoning: 4, 16 intelligence: 3,60 intelligence: null, 17 61 speed: 3, 18 62 contextWindow: '400,000', … … 25 69 description: 'A faster, cost-efficient version of GPT-5 for well-defined tasks', 26 70 reasoning: 3, 27 intelligence: 4,71 intelligence: null, 28 72 speed: 4, 29 73 contextWindow: '400,000', … … 36 80 description: 'Fastest, most cost-efficient version of GPT-5', 37 81 reasoning: 2, 38 intelligence: 5,82 intelligence: null, 39 83 speed: 5, 40 84 contextWindow: '400,000', … … 135 179 </div> 136 180 ` : ''} 137 ${model Key.startsWith('gpt-4.1')? `181 ${model.intelligence !== null ? ` 138 182 <div class="wpiko-spec-item"> 139 183 <span class="wpiko-spec-label">Intelligence</span> … … 180 224 function updateModelInfo(selectedModel) { 181 225 let $modelInfoContainer = $('#wpiko-responses-model-info'); 182 226 183 227 if (!$modelInfoContainer.length) { 184 228 // Create the container if it doesn't exist … … 206 250 function initializeModelInfo() { 207 251 const $modelSelect = $('#responses_model'); 208 252 209 253 if ($modelSelect.length) { 210 254 // Show info for initially selected model … … 215 259 216 260 // Handle model selection changes 217 $modelSelect.on('change', function () {261 $modelSelect.on('change', function () { 218 262 const selectedModel = $(this).val(); 219 263 updateModelInfo(selectedModel); 220 264 221 265 // Add a subtle animation 222 266 $('#wpiko-responses-model-info').hide().fadeIn(300); … … 244 288 // This could be expanded to show a comparison table of all models 245 289 // For now, we'll just expose the function for potential future use 246 window.wpikoModelsComparison = function () {290 window.wpikoModelsComparison = function () { 247 291 const models = Object.keys(modelsData); 248 292 console.log('Available models for comparison:', models); … … 256 300 function initializeWhenResponsesVisible() { 257 301 const $responsesSection = $('#responses-api-settings'); 258 302 259 303 if ($responsesSection.is(':visible')) { 260 304 initializeModelInfo(); … … 262 306 263 307 // Watch for API type changes 264 $('input[name="api_type"]').on('change', function () {308 $('input[name="api_type"]').on('change', function () { 265 309 if ($(this).val() === 'responses' && $(this).is(':checked')) { 266 setTimeout(function () {310 setTimeout(function () { 267 311 initializeModelInfo(); 268 312 }, 100); … … 271 315 272 316 // Watch for save button that shows/hides sections 273 $('#save_api_type').on('click', function () {274 setTimeout(function () {317 $('#save_api_type').on('click', function () { 318 setTimeout(function () { 275 319 const $responsesSection = $('#responses-api-settings'); 276 320 if ($responsesSection.is(':visible')) { … … 287 331 // Expose modelsData globally for debugging/development 288 332 window.wpikoModelsData = modelsData; 289 333 290 334 // Add debug function for console testing 291 window.wpikoDebugModels = function () {335 window.wpikoDebugModels = function () { 292 336 console.log('=== Wpiko Chatbot Models Debug Info ==='); 293 337 console.log('Available models:', Object.keys(modelsData)); … … 297 341 console.log('Full models data:', modelsData); 298 342 }; 299 343 300 344 // Log successful initialization 301 345 console.log('Wpiko Chatbot Models Info initialized with', Object.keys(modelsData).length, 'models'); -
wpiko-chatbot/trunk/admin/js/responses-api.js
r3373160 r3421683 1 jQuery(document).ready(function ($) {2 1 jQuery(document).ready(function ($) { 2 3 3 // Handle System Instructions tab switching 4 $('.instructions-tabs .nav-tab').on('click', function (e) {4 $('.instructions-tabs .nav-tab').on('click', function (e) { 5 5 e.preventDefault(); 6 6 7 7 var tabId = $(this).data('tab'); 8 8 9 9 // Remove active class from all tabs and add to clicked tab 10 10 $('.instructions-tabs .nav-tab').removeClass('nav-tab-active'); 11 11 $(this).addClass('nav-tab-active'); 12 12 13 13 // Hide all tab content and show the selected one 14 14 $('.tab-content').hide(); 15 15 $('#' + tabId + '-tab').show(); 16 16 }); 17 17 18 18 // Function to update main instructions dynamically for Responses API 19 19 function updateResponsesMainInstructions() { … … 23 23 var assistantTone = $('#responses_assistant_tone option:selected').text(); 24 24 var assistantStyle = $('#responses_assistant_style option:selected').text(); 25 25 26 26 // NOTE: This instruction template is also defined in includes/instructions-handler.php 27 27 // If you modify this template, make sure to update both files to keep them in sync 28 28 var mainInstructions = "You are an " + assistantType + " for the website " + websiteName + ". " + 29 "The website specializes in " + websiteSpecialization + ". " +30 "Your goal is to provide helpful, accurate, and engaging responses to user queries " +31 "while maintaining a " + assistantTone + " and " + assistantStyle + " tone. " +32 "Always respond as if you are a helpful member of the website team.";33 29 "The website specializes in " + websiteSpecialization + ". " + 30 "Your goal is to provide helpful, accurate, and engaging responses to user queries " + 31 "while maintaining a " + assistantTone + " and " + assistantStyle + " tone. " + 32 "Always respond as if you are a helpful member of the website team."; 33 34 34 $('#responses_main_system_instructions').val(mainInstructions); 35 35 } 36 36 37 37 // Update instructions when fields change 38 38 $('#responses_website_specialization').on('input', updateResponsesMainInstructions); … … 41 41 $('#responses_assistant_tone').on('change', updateResponsesMainInstructions); 42 42 $('#responses_assistant_style').on('change', updateResponsesMainInstructions); 43 43 44 44 // Initialize instructions on page load 45 45 updateResponsesMainInstructions(); 46 46 47 47 // Handle Vector Store refresh 48 $(document).on('click', '.vector-store-refresh-btn', function (e) {48 $(document).on('click', '.vector-store-refresh-btn', function (e) { 49 49 e.preventDefault(); 50 50 51 51 var $button = $(this); 52 52 var $vectorStoreInfo = $button.closest('.vector-store-info'); 53 53 54 54 // Disable button and show loading state 55 55 $button.prop('disabled', true); 56 56 var $icon = $button.find('.dashicons'); 57 57 $icon.css('animation', 'rotation 1s infinite linear'); 58 58 59 59 $.ajax({ 60 60 url: wpikoChatbotAdmin.ajax_url, … … 64 64 security: wpikoChatbotAdmin.nonce 65 65 }, 66 success: function (response) {66 success: function (response) { 67 67 if (response.success && response.data) { 68 68 var data = response.data; … … 78 78 var statusClass = status === 'completed' ? 'status-active' : 'status-processing'; 79 79 var statusText = status.charAt(0).toUpperCase() + status.slice(1); 80 80 81 81 // Update the Vector Store information 82 82 var html = '<div class="vector-store-header">' + … … 113 113 '</div>' + 114 114 '</div>'; 115 115 116 116 $vectorStoreInfo.removeClass('vector-store-error').html(html); 117 117 } else if (response.data && response.data.not_found) { … … 138 138 '<p>A new Vector Store will be automatically created when you upload your first file.</p>' + 139 139 '</div>'; 140 140 141 141 $vectorStoreInfo.addClass('vector-store-error').html(html); 142 142 } else { … … 144 144 } 145 145 }, 146 error: function () {146 error: function () { 147 147 alert('Connection error occurred while trying to refresh Vector Store information.'); 148 148 }, 149 complete: function () {149 complete: function () { 150 150 // Re-enable button and stop animation 151 151 $button.prop('disabled', false); … … 154 154 }); 155 155 }); 156 156 157 157 // Handle Vector Store deletion 158 $(document).on('click', '.vector-store-delete-btn', function (e) {158 $(document).on('click', '.vector-store-delete-btn', function (e) { 159 159 e.preventDefault(); 160 160 161 161 var confirmed = confirm( 162 162 'Are you sure you want to delete the Vector Store?\n\n' + … … 168 168 'Click OK to delete or Cancel to keep it.' 169 169 ); 170 170 171 171 if (!confirmed) { 172 172 return; 173 173 } 174 174 175 175 var $button = $(this); 176 176 var $vectorStoreInfo = $button.closest('.vector-store-info'); 177 177 178 178 // Disable button and show loading state 179 179 $button.prop('disabled', true); 180 180 $button.find('.dashicons').removeClass('dashicons-trash').addClass('dashicons-update').css('animation', 'rotation 1s infinite linear'); 181 181 182 182 $.ajax({ 183 183 url: wpikoChatbotAdmin.ajax_url, … … 187 187 security: wpikoChatbotAdmin.nonce 188 188 }, 189 success: function (response) {189 success: function (response) { 190 190 if (response.success) { 191 191 var message = response.data.message || 'Vector Store has been deleted.'; … … 196 196 '</div>' 197 197 ); 198 198 199 199 // Reload page after 2 seconds 200 setTimeout(function () {200 setTimeout(function () { 201 201 location.reload(); 202 202 }, 2000); … … 207 207 } 208 208 }, 209 error: function () {209 error: function () { 210 210 alert('Connection error occurred while trying to delete the Vector Store.'); 211 211 $button.prop('disabled', false); … … 214 214 }); 215 215 }); 216 216 217 217 // Handle Responses API configuration save 218 $('#save_responses_config').on('click', function () {218 $('#save_responses_config').on('click', function () { 219 219 var $button = $(this); 220 220 var $status = $('#responses_save_status'); 221 221 222 222 $button.prop('disabled', true).text('Saving...'); 223 223 $status.removeClass('success error').addClass('info').text('Saving configuration...'); 224 224 225 225 var data = { 226 226 action: 'wpiko_chatbot_update_responses_config', … … 237 237 orders_system_instructions: $('#responses_orders_system_instructions').val() 238 238 }; 239 240 $.post(wpikoChatbotAdmin.ajax_url, data, function (response) {239 240 $.post(wpikoChatbotAdmin.ajax_url, data, function (response) { 241 241 if (response.success) { 242 242 $status.removeClass('error info').addClass('success').text('Configuration saved successfully!'); 243 setTimeout(function () {244 $status.removeClass('success error info').text(''); 243 setTimeout(function () { 244 $status.removeClass('success error info').text(''); 245 245 }, 3000); 246 246 } else { 247 247 $status.removeClass('success info').addClass('error').text('Error: ' + response.data.message); 248 248 } 249 }).fail(function () {249 }).fail(function () { 250 250 $status.removeClass('success info').addClass('error').text('Connection error occurred.'); 251 }).always(function () {251 }).always(function () { 252 252 $button.prop('disabled', false).text('Save Configuration'); 253 253 }); … … 255 255 256 256 // Handle model selection changes to show model information 257 $('#responses_model').on('change', function () {257 $('#responses_model').on('change', function () { 258 258 var selectedModel = $(this).val(); 259 259 260 260 // Remove any existing model info 261 261 $('#responses_model').next('.model-info').remove(); 262 262 263 263 // Model information based on the provided documentation 264 264 var modelInfo = ''; 265 switch (selectedModel) {265 switch (selectedModel) { 266 266 case 'gpt-4.1': 267 modelInfo = '<div class="model-info"><p><strong>GPT-4.1:</strong> Latest high-performance model with enhanced reasoning capabilities and tool support. Ideal for complex tasks requiring deep analysis.</p></div>';267 modelInfo = '<div class="model-info"><p><strong>GPT-4.1:</strong> High-performance model with enhanced capabilities and tool support. Ideal for complex tasks.</p></div>'; 268 268 break; 269 269 case 'gpt-4.1-mini': … … 280 280 break; 281 281 case 'gpt-5-nano': 282 modelInfo = '<div class="model-info"><p><strong>GPT-5 Nano:</strong> Efficient GPT-5 variant optimized for speed and cost-effectiveness while maintaining quality responses.</p></div>'; 282 modelInfo = '<div class=\"model-info\"><p><strong>GPT-5 Nano:</strong> Efficient GPT-5 variant optimized for speed and cost-effectiveness while maintaining quality responses.</p></div>'; 283 break; 284 case 'gpt-5.1': 285 modelInfo = '<div class=\"model-info\"><p><strong>GPT-5.1:</strong> Enhanced GPT-5 with improved intelligence and better instruction-following capabilities. </p></div>'; 286 break; 287 case 'gpt-5.1-chat-latest': 288 modelInfo = '<div class=\"model-info\"><p><strong>GPT-5.1 Chat:</strong> Optimized for natural conversations with warmer, more engaging responses.</p></div>'; 289 break; 290 case 'gpt-5.2': 291 modelInfo = '<div class=\"model-info\"><p><strong>GPT-5.2:</strong> Most capable model for professional knowledge work. </p></div>'; 292 break; 293 case 'gpt-5.2-chat-latest': 294 modelInfo = '<div class=\"model-info\"><p><strong>GPT-5.2 Chat:</strong> Latest conversational model with superior quality and trustworthiness.</p></div>'; 283 295 break; 284 296 } 285 297 286 298 if (modelInfo) { 287 299 $(this).after(modelInfo); 288 300 } 289 301 }); 290 302 291 303 // Trigger model info display on page load 292 304 $('#responses_model').trigger('change'); -
wpiko-chatbot/trunk/admin/sections/ai-configuration-section.php
r3373160 r3421683 4 4 } 5 5 6 function wpiko_chatbot_ai_configuration_section() { 6 function wpiko_chatbot_ai_configuration_section() 7 { 7 8 8 9 if (isset($_POST['action']) && $_POST['action'] == 'save_ai_configuration') { 9 10 check_admin_referer('save_ai_configuration', 'ai_configuration_nonce'); 10 11 11 12 // Update Responses API settings 12 13 if (isset($_POST['responses_model'])) { 13 14 update_option('wpiko_chatbot_responses_model', sanitize_text_field(wp_unslash($_POST['responses_model']))); 14 15 } 15 16 16 17 echo '<div class="updated"><p>AI Configuration updated successfully.</p></div>'; 17 18 } 18 19 19 20 $responses_model = get_option('wpiko_chatbot_responses_model', 'gpt-4.1-mini'); 20 21 ?> 21 22 <div class="ai-configuration-section"> 22 23 <?php 23 24 <?php 24 25 // Action hook for adding content after AI configuration title (e.g., WooCommerce integration state) 25 26 do_action('wpiko_chatbot_after_ai_configuration_title'); 26 27 ?> 27 28 28 29 <form method="post" action="" name="ai_configuration_form" id="ai_configuration_form"> 29 30 <?php wp_nonce_field('save_ai_configuration', 'ai_configuration_nonce'); ?> 30 31 <!-- Responses API Settings --> 32 <div id="responses-api-settings" style="display: block;"> 33 <div class="responses-api-section"> 34 <h3><span class="dashicons dashicons-admin-generic"></span> AI Configuration</h3> 35 <p class="description">Set up your AI chatbot settings to customize how it interacts with your website visitors.</p> 36 37 <table class="form-table"> 38 <tr valign="top"> 39 <th scope="row">Model</th> 40 <td> 41 <select name="responses_model" id="responses_model"> 42 <?php 43 // Latest models only (per provided documentation) 44 $available_models = array( 45 'gpt-4.1' => 'GPT-4.1', 46 'gpt-4.1-mini' => 'GPT-4.1 Mini', 47 'gpt-4.1-nano' => 'GPT-4.1 Nano', 48 'gpt-5' => 'GPT-5', 49 'gpt-5-mini' => 'GPT-5 Mini', 50 'gpt-5-nano' => 'GPT-5 Nano' 51 ); 52 foreach ($available_models as $model_value => $model_label) { 53 printf('<option value="%s" %s>%s</option>', 54 esc_attr($model_value), 55 selected($model_value, $responses_model, false), 56 esc_html($model_label) 57 ); 58 } 59 ?> 60 </select> 61 62 <!-- Dynamic model information will be inserted here by JavaScript --> 63 <div id="wpiko-responses-model-info"></div> 64 <p class="description">Select one of the latest OpenAI models. Detailed information will appear when you select a model.</p> 65 </td> 66 </tr> 67 <tr valign="top"> 68 <th scope="row">System Instructions</th> 69 <td> 70 <div class="instructions-tabs"> 71 <ul class="nav-tab-wrapper"> 72 <li><a href="#" class="nav-tab nav-tab-active" data-tab="responses-basic">Basic Instructions</a></li> 73 <li><a href="#" class="nav-tab" data-tab="responses-advanced">Advanced Instructions</a></li> 74 </ul> 75 76 <div class="tab-content" id="responses-basic-tab" style="display: block;"> 77 <table class="form-table"> 78 <tr valign="top"> 79 <td> 80 <div class="structured-instructions"> 81 82 <div class="instruction-field assistant-type-field"> 83 <label>You are an</label> 84 <input type="text" name="responses_assistant_type" id="responses_assistant_type" class="medium-text" 85 value="<?php echo esc_attr(get_option('wpiko_chatbot_responses_assistant_type', get_option('wpiko_chatbot_assistant_type', 'AI assistant'))); ?>" 86 placeholder="AI assistant"> 87 <span>for the website <strong class="website-name"><?php echo esc_html(get_bloginfo('name')); ?></strong>.</span> 88 </div> 89 90 <div class="instruction-field"> 91 <label>The website specializes in:</label> 92 <input type="text" name="responses_website_specialization" id="responses_website_specialization" class="medium-text" 93 value="<?php echo esc_attr(get_option('wpiko_chatbot_responses_website_specialization', get_option('wpiko_chatbot_website_specialization', ''))); ?>" 94 placeholder="e.g., web development, digital marketing, etc."> 95 </div> 96 97 <div class="instruction-field"> 98 <label>Assistant Tone:</label> 99 <select name="responses_assistant_tone" id="responses_assistant_tone"> 100 <?php 101 $tones = array( 102 'friendly' => 'Friendly', 103 'casual' => 'Casual', 104 'professional' => 'Professional', 105 'formal' => 'Formal', 106 'humorous' => 'Humorous', 107 'educational' => 'Educational', 108 'enthusiastic' => 'Enthusiastic' 109 ); 110 $selected_tone = get_option('wpiko_chatbot_responses_assistant_tone', get_option('wpiko_chatbot_assistant_tone', 'friendly')); 111 foreach ($tones as $value => $label) { 112 printf('<option value="%s" %s>%s</option>', 113 esc_attr($value), 114 selected($value, $selected_tone, false), 115 esc_html($label) 116 ); 117 } 118 ?> 119 </select> 120 </div> 121 122 <div class="instruction-field"> 123 <label>Assistant Style:</label> 124 <select name="responses_assistant_style" id="responses_assistant_style"> 125 <?php 126 $styles = array( 127 'professional' => 'Professional', 128 'conversational' => 'Conversational', 129 'helpful' => 'Helpful', 130 'concise' => 'Concise', 131 'detailed' => 'Detailed' 132 ); 133 $selected_style = get_option('wpiko_chatbot_responses_assistant_style', get_option('wpiko_chatbot_assistant_style', 'professional')); 134 foreach ($styles as $value => $label) { 135 printf('<option value="%s" %s>%s</option>', 136 esc_attr($value), 137 selected($value, $selected_style, false), 138 esc_html($label) 139 ); 140 } 141 ?> 142 </select> 143 </div> 144 </div> 145 <input type="hidden" name="responses_main_system_instructions" id="responses_main_system_instructions" value="<?php 146 $instructions = wpiko_chatbot_get_system_instructions(); 147 echo esc_attr($instructions['main']); 148 ?>"> 149 <p class="description">Customize how your AI assistant introduces itself and understands your website's purpose and content.</p> 150 </td> 151 </tr> 152 </table> 31 32 <!-- Responses API Settings --> 33 <div id="responses-api-settings" style="display: block;"> 34 <div class="responses-api-section"> 35 <h3><span class="dashicons dashicons-admin-generic"></span> AI Configuration</h3> 36 <p class="description">Set up your AI chatbot settings to customize how it interacts with your website 37 visitors.</p> 38 39 <table class="form-table"> 40 <tr valign="top"> 41 <th scope="row">Model</th> 42 <td> 43 <select name="responses_model" id="responses_model"> 44 <?php 45 // Latest models only (per provided documentation) 46 $available_models = array( 47 'gpt-4.1' => 'GPT-4.1', 48 'gpt-4.1-mini' => 'GPT-4.1 Mini', 49 'gpt-4.1-nano' => 'GPT-4.1 Nano', 50 'gpt-5' => 'GPT-5', 51 'gpt-5-mini' => 'GPT-5 Mini', 52 'gpt-5-nano' => 'GPT-5 Nano', 53 'gpt-5.1' => 'GPT-5.1', 54 'gpt-5.1-chat-latest' => 'GPT-5.1 Chat', 55 'gpt-5.2' => 'GPT-5.2', 56 'gpt-5.2-chat-latest' => 'GPT-5.2 Chat' 57 ); 58 foreach ($available_models as $model_value => $model_label) { 59 printf( 60 '<option value="%s" %s>%s</option>', 61 esc_attr($model_value), 62 selected($model_value, $responses_model, false), 63 esc_html($model_label) 64 ); 65 } 66 ?> 67 </select> 68 69 <!-- Dynamic model information will be inserted here by JavaScript --> 70 <div id="wpiko-responses-model-info"></div> 71 <p class="description">Select one of the latest OpenAI models. Detailed information will 72 appear when you select a model.</p> 73 </td> 74 </tr> 75 <tr valign="top"> 76 <th scope="row">System Instructions</th> 77 <td> 78 <div class="instructions-tabs"> 79 <ul class="nav-tab-wrapper"> 80 <li><a href="#" class="nav-tab nav-tab-active" data-tab="responses-basic">Basic 81 Instructions</a></li> 82 <li><a href="#" class="nav-tab" data-tab="responses-advanced">Advanced 83 Instructions</a></li> 84 </ul> 85 86 <div class="tab-content" id="responses-basic-tab" style="display: block;"> 87 <table class="form-table"> 88 <tr valign="top"> 89 <td> 90 <div class="structured-instructions"> 91 92 <div class="instruction-field assistant-type-field"> 93 <label>You are an</label> 94 <input type="text" name="responses_assistant_type" 95 id="responses_assistant_type" class="medium-text" 96 value="<?php echo esc_attr(get_option('wpiko_chatbot_responses_assistant_type', get_option('wpiko_chatbot_assistant_type', 'AI assistant'))); ?>" 97 placeholder="AI assistant"> 98 <span>for the website <strong 99 class="website-name"><?php echo esc_html(get_bloginfo('name')); ?></strong>.</span> 100 </div> 101 102 <div class="instruction-field"> 103 <label>The website specializes in:</label> 104 <input type="text" name="responses_website_specialization" 105 id="responses_website_specialization" class="medium-text" 106 value="<?php echo esc_attr(get_option('wpiko_chatbot_responses_website_specialization', get_option('wpiko_chatbot_website_specialization', ''))); ?>" 107 placeholder="e.g., web development, digital marketing, etc."> 108 </div> 109 110 <div class="instruction-field"> 111 <label>Assistant Tone:</label> 112 <select name="responses_assistant_tone" 113 id="responses_assistant_tone"> 114 <?php 115 $tones = array( 116 'friendly' => 'Friendly', 117 'casual' => 'Casual', 118 'professional' => 'Professional', 119 'formal' => 'Formal', 120 'humorous' => 'Humorous', 121 'educational' => 'Educational', 122 'enthusiastic' => 'Enthusiastic' 123 ); 124 $selected_tone = get_option('wpiko_chatbot_responses_assistant_tone', get_option('wpiko_chatbot_assistant_tone', 'friendly')); 125 foreach ($tones as $value => $label) { 126 printf( 127 '<option value="%s" %s>%s</option>', 128 esc_attr($value), 129 selected($value, $selected_tone, false), 130 esc_html($label) 131 ); 132 } 133 ?> 134 </select> 135 </div> 136 137 <div class="instruction-field"> 138 <label>Assistant Style:</label> 139 <select name="responses_assistant_style" 140 id="responses_assistant_style"> 141 <?php 142 $styles = array( 143 'professional' => 'Professional', 144 'conversational' => 'Conversational', 145 'helpful' => 'Helpful', 146 'concise' => 'Concise', 147 'detailed' => 'Detailed' 148 ); 149 $selected_style = get_option('wpiko_chatbot_responses_assistant_style', get_option('wpiko_chatbot_assistant_style', 'professional')); 150 foreach ($styles as $value => $label) { 151 printf( 152 '<option value="%s" %s>%s</option>', 153 esc_attr($value), 154 selected($value, $selected_style, false), 155 esc_html($label) 156 ); 157 } 158 ?> 159 </select> 160 </div> 161 </div> 162 <input type="hidden" name="responses_main_system_instructions" 163 id="responses_main_system_instructions" value="<?php 164 $instructions = wpiko_chatbot_get_system_instructions(); 165 echo esc_attr($instructions['main']); 166 ?>"> 167 <p class="description">Customize how your AI assistant introduces itself 168 and understands your website's purpose and content.</p> 169 </td> 170 </tr> 171 </table> 172 </div> 173 174 <div class="tab-content" id="responses-advanced-tab" style="display: none;"> 175 <table class="form-table"> 176 <tr valign="top"> 177 <th scope="row">Specific System Instructions</th> 178 <td> 179 <textarea name="responses_specific_system_instructions" 180 id="responses_specific_system_instructions" class="large-text" 181 rows="5" placeholder="Examples: 182 Keep responses under 3 sentences when possible. 183 For support inquiries, direct users to contact@example.com."> <?php 184 $instructions = wpiko_chatbot_get_system_instructions(); 185 echo esc_textarea($instructions['specific']); 186 ?></textarea> 187 <p class="description">Enter specific rules and guidelines for how your 188 assistant should behave and respond.</p> 189 </td> 190 </tr> 191 <tr valign="top"> 192 <th scope="row">Knowledge System Instructions</th> 193 <td> 194 <textarea name="responses_knowledge_system_instructions" 195 id="responses_knowledge_system_instructions" class="large-text" 196 rows="5"><?php 197 echo esc_textarea($instructions['knowledge']); 198 ?></textarea> 199 <p class="description">Edit knowledge-related system instructions for 200 your assistant only if necessary. These instructions help the AI 201 understand how to use uploaded files and knowledge base.</p> 202 </td> 203 </tr> 204 <?php 205 // Action hook for adding advanced system instructions (e.g., WooCommerce products/orders instructions) 206 do_action('wpiko_chatbot_responses_advanced_system_instructions'); 207 ?> 208 </table> 209 </div> 210 </div> 211 </td> 212 </tr> 213 <tr valign="top"> 214 <th scope="row">Save Configuration</th> 215 <td> 216 <button type="button" id="save_responses_config" class="button button-primary">Save 217 Configuration</button> 218 <span id="responses_save_status"></span> 219 </td> 220 </tr> 221 222 </table> 223 </div> 224 225 <!-- Responses Actions Section --> 226 <div id="responses-actions-section" style="display: block;"> 227 <h3><span class="dashicons dashicons-admin-tools"></span> Train AI Assistant</h3> 228 <p class="description">Deliver better user experiences by shaping your AI assistant's knowledge.</p> 229 230 <?php 231 // Display Vector Store Information 232 $vector_store_details = wpiko_chatbot_get_responses_vector_store_details(); 233 if ($vector_store_details['success']) { 234 $created_date = !empty($vector_store_details['created_at']) ? date('F j, Y', $vector_store_details['created_at']) : 'N/A'; 235 $file_counts = $vector_store_details['file_counts'] ?? array(); 236 $total_files = isset($file_counts['total']) ? $file_counts['total'] : 0; 237 $completed_files = isset($file_counts['completed']) ? $file_counts['completed'] : 0; 238 $status = $vector_store_details['status'] ?? 'unknown'; 239 $status_class = $status === 'completed' ? 'status-active' : 'status-processing'; 240 $status_text = ucfirst($status); 241 ?> 242 <div class="vector-store-info"> 243 <div class="vector-store-header"> 244 <span class="dashicons dashicons-database"></span> 245 <h4>Vector Store Information 246 <span class="vector-store-info-icon" 247 title="A Vector Store is a specialized database in OpenAI that stores and indexes your uploaded files (PDFs, documents, etc.) for semantic search. It enables your AI chatbot to search through your knowledge base and provide accurate answers based on your content."> 248 <span class="dashicons dashicons-info"></span> 249 </span> 250 </h4> 251 <span 252 class="vector-store-status <?php echo esc_attr($status_class); ?>"><?php echo esc_html($status_text); ?></span> 253 <button type="button" class="button button-link-refresh vector-store-refresh-btn" 254 title="Refresh Vector Store Information"> 255 <span class="dashicons dashicons-update"></span> 256 </button> 257 <button type="button" class="button button-link-delete vector-store-delete-btn" 258 title="Delete Vector Store and All Files"> 259 <span class="dashicons dashicons-trash"></span> 260 </button> 153 261 </div> 154 155 <div class="tab-content" id="responses-advanced-tab" style="display: none;"> 156 <table class="form-table"> 157 <tr valign="top"> 158 <th scope="row">Specific System Instructions</th> 159 <td> 160 <textarea name="responses_specific_system_instructions" id="responses_specific_system_instructions" class="large-text" rows="5" placeholder="Examples: 161 Keep responses under 3 sentences when possible. 162 For support inquiries, direct users to contact@example.com."><?php 163 $instructions = wpiko_chatbot_get_system_instructions(); 164 echo esc_textarea($instructions['specific']); 165 ?></textarea> 166 <p class="description">Enter specific rules and guidelines for how your assistant should behave and respond.</p> 167 </td> 168 </tr> 169 <tr valign="top"> 170 <th scope="row">Knowledge System Instructions</th> 171 <td> 172 <textarea name="responses_knowledge_system_instructions" id="responses_knowledge_system_instructions" class="large-text" rows="5"><?php 173 echo esc_textarea($instructions['knowledge']); 174 ?></textarea> 175 <p class="description">Edit knowledge-related system instructions for your assistant only if necessary. These instructions help the AI understand how to use uploaded files and knowledge base.</p> 176 </td> 177 </tr> 178 <?php 179 // Action hook for adding advanced system instructions (e.g., WooCommerce products/orders instructions) 180 do_action('wpiko_chatbot_responses_advanced_system_instructions'); 181 ?> 182 </table> 262 <div class="vector-store-details"> 263 <div class="vector-store-item"> 264 <strong>Name:</strong> 265 <span><?php echo esc_html($vector_store_details['name']); ?></span> 266 </div> 267 <div class="vector-store-item"> 268 <strong>ID:</strong> 269 <code class="vector-store-id"><?php echo esc_html($vector_store_details['id']); ?></code> 270 </div> 271 <div class="vector-store-item"> 272 <strong>Created:</strong> 273 <span><?php echo esc_html($created_date); ?></span> 274 </div> 275 <div class="vector-store-item"> 276 <strong>Files:</strong> 277 <span><?php echo esc_html($completed_files . ' completed / ' . $total_files . ' total'); ?></span> 278 </div> 183 279 </div> 184 280 </div> 185 </td> 186 </tr> 187 <tr valign="top"> 188 <th scope="row">Save Configuration</th> 189 <td> 190 <button type="button" id="save_responses_config" class="button button-primary">Save Configuration</button> 191 <span id="responses_save_status"></span> 192 </td> 193 </tr> 194 195 </table> 196 </div> 197 198 <!-- Responses Actions Section --> 199 <div id="responses-actions-section" style="display: block;"> 200 <h3><span class="dashicons dashicons-admin-tools"></span> Train AI Assistant</h3> 201 <p class="description">Deliver better user experiences by shaping your AI assistant's knowledge.</p> 202 203 <?php 204 // Display Vector Store Information 205 $vector_store_details = wpiko_chatbot_get_responses_vector_store_details(); 206 if ($vector_store_details['success']) { 207 $created_date = !empty($vector_store_details['created_at']) ? date('F j, Y', $vector_store_details['created_at']) : 'N/A'; 208 $file_counts = $vector_store_details['file_counts'] ?? array(); 209 $total_files = isset($file_counts['total']) ? $file_counts['total'] : 0; 210 $completed_files = isset($file_counts['completed']) ? $file_counts['completed'] : 0; 211 $status = $vector_store_details['status'] ?? 'unknown'; 212 $status_class = $status === 'completed' ? 'status-active' : 'status-processing'; 213 $status_text = ucfirst($status); 214 ?> 215 <div class="vector-store-info"> 216 <div class="vector-store-header"> 217 <span class="dashicons dashicons-database"></span> 218 <h4>Vector Store Information 219 <span class="vector-store-info-icon" title="A Vector Store is a specialized database in OpenAI that stores and indexes your uploaded files (PDFs, documents, etc.) for semantic search. It enables your AI chatbot to search through your knowledge base and provide accurate answers based on your content."> 220 <span class="dashicons dashicons-info"></span> 221 </span> 222 </h4> 223 <span class="vector-store-status <?php echo esc_attr($status_class); ?>"><?php echo esc_html($status_text); ?></span> 224 <button type="button" class="button button-link-refresh vector-store-refresh-btn" title="Refresh Vector Store Information"> 225 <span class="dashicons dashicons-update"></span> 281 <?php } elseif (isset($vector_store_details['not_found']) && $vector_store_details['not_found']) { 282 // Vector Store was deleted from OpenAI dashboard 283 ?> 284 <div class="vector-store-info vector-store-error"> 285 <div class="vector-store-header"> 286 <span class="dashicons dashicons-warning"></span> 287 <h4>Vector Store Not Found 288 <span class="vector-store-info-icon" 289 title="A Vector Store is a specialized database in OpenAI that stores and indexes your uploaded files (PDFs, documents, etc.) for semantic search. It enables your AI chatbot to search through your knowledge base and provide accurate answers based on your content."> 290 <span class="dashicons dashicons-info"></span> 291 </span> 292 </h4> 293 <span class="vector-store-status status-error">Error</span> 294 <button type="button" class="button button-link-refresh vector-store-refresh-btn" 295 title="Refresh Vector Store Information"> 296 <span class="dashicons dashicons-update"></span> 297 </button> 298 </div> 299 <div class="vector-store-error-message"> 300 <p><strong>The Vector Store was deleted or is no longer accessible.</strong></p> 301 <p>This may have happened if you deleted it from the OpenAI dashboard. To fix this issue:</p> 302 <ol> 303 <li>Upload a new file using the "File Management" button below, or</li> 304 <li>Use any of the training tools (Scan Website, Q&A Builder, etc.)</li> 305 </ol> 306 <p>A new Vector Store will be automatically created when you upload your first file.</p> 307 </div> 308 </div> 309 <?php } ?> 310 311 <div class="assistant-action-buttons"> 312 <button type="button" class="button button-secondary wpiko-file-management-button"> 313 <span class="dashicons dashicons-upload"></span> File Management 226 314 </button> 227 <button type="button" class="button button-link-delete vector-store-delete-btn" title="Delete Vector Store and All Files"> 228 <span class="dashicons dashicons-trash"></span> 229 </button> 315 316 <?php 317 // Check if additional response actions are available 318 if (has_action('wpiko_chatbot_responses_scan_website_button')): ?> 319 <?php do_action('wpiko_chatbot_responses_scan_website_button'); ?> 320 <?php do_action('wpiko_chatbot_responses_qa_builder_button'); ?> 321 322 <?php if (wpiko_chatbot_is_woocommerce_active()): ?> 323 <?php do_action('wpiko_chatbot_responses_woocommerce_integration_button'); ?> 324 <?php endif; ?> 325 <?php endif; ?> 230 326 </div> 231 <div class="vector-store-details"> 232 <div class="vector-store-item"> 233 <strong>Name:</strong> 234 <span><?php echo esc_html($vector_store_details['name']); ?></span> 235 </div> 236 <div class="vector-store-item"> 237 <strong>ID:</strong> 238 <code class="vector-store-id"><?php echo esc_html($vector_store_details['id']); ?></code> 239 </div> 240 <div class="vector-store-item"> 241 <strong>Created:</strong> 242 <span><?php echo esc_html($created_date); ?></span> 243 </div> 244 <div class="vector-store-item"> 245 <strong>Files:</strong> 246 <span><?php echo esc_html($completed_files . ' completed / ' . $total_files . ' total'); ?></span> 247 </div> 248 </div> 327 328 <!-- Modal container for file management is defined globally below --> 329 330 <?php 331 // Check if additional response modal actions are available 332 if (has_action('wpiko_chatbot_responses_scan_website_modal')): ?> 333 <?php do_action('wpiko_chatbot_responses_scan_website_modal'); ?> 334 <?php do_action('wpiko_chatbot_responses_qa_builder_modal'); ?> 335 <?php do_action('wpiko_chatbot_responses_woocommerce_integration_modal'); ?> 336 <?php endif; ?> 249 337 </div> 250 <?php } elseif (isset($vector_store_details['not_found']) && $vector_store_details['not_found']) {251 // Vector Store was deleted from OpenAI dashboard252 ?>253 <div class="vector-store-info vector-store-error">254 <div class="vector-store-header">255 <span class="dashicons dashicons-warning"></span>256 <h4>Vector Store Not Found257 <span class="vector-store-info-icon" title="A Vector Store is a specialized database in OpenAI that stores and indexes your uploaded files (PDFs, documents, etc.) for semantic search. It enables your AI chatbot to search through your knowledge base and provide accurate answers based on your content.">258 <span class="dashicons dashicons-info"></span>259 </span>260 </h4>261 <span class="vector-store-status status-error">Error</span>262 <button type="button" class="button button-link-refresh vector-store-refresh-btn" title="Refresh Vector Store Information">263 <span class="dashicons dashicons-update"></span>264 </button>265 </div>266 <div class="vector-store-error-message">267 <p><strong>The Vector Store was deleted or is no longer accessible.</strong></p>268 <p>This may have happened if you deleted it from the OpenAI dashboard. To fix this issue:</p>269 <ol>270 <li>Upload a new file using the "File Management" button below, or</li>271 <li>Use any of the training tools (Scan Website, Q&A Builder, etc.)</li>272 </ol>273 <p>A new Vector Store will be automatically created when you upload your first file.</p>274 </div>275 </div>276 <?php } ?>277 278 <div class="assistant-action-buttons">279 <button type="button" class="button button-secondary wpiko-file-management-button">280 <span class="dashicons dashicons-upload"></span> File Management281 </button>282 283 <?php284 // Check if additional response actions are available285 if (has_action('wpiko_chatbot_responses_scan_website_button')): ?>286 <?php do_action('wpiko_chatbot_responses_scan_website_button'); ?>287 <?php do_action('wpiko_chatbot_responses_qa_builder_button'); ?>288 289 <?php if (wpiko_chatbot_is_woocommerce_active()): ?>290 <?php do_action('wpiko_chatbot_responses_woocommerce_integration_button'); ?>291 <?php endif; ?>292 <?php endif; ?>293 338 </div> 294 339 295 <!-- Modal container for file management is defined globally below --> 296 297 <?php 298 // Check if additional response modal actions are available 299 if (has_action('wpiko_chatbot_responses_scan_website_modal')): ?> 300 <?php do_action('wpiko_chatbot_responses_scan_website_modal'); ?> 301 <?php do_action('wpiko_chatbot_responses_qa_builder_modal'); ?> 302 <?php do_action('wpiko_chatbot_responses_woocommerce_integration_modal'); ?> 303 <?php endif; ?> 304 </div> 305 </div> 306 307 308 <input type="hidden" name="action" value="save_ai_configuration"> 340 341 <input type="hidden" name="action" value="save_ai_configuration"> 309 342 </form> 310 343 … … 320 353 </div> 321 354 <?php 322 355 323 356 } -
wpiko-chatbot/trunk/includes/responses-api.php
r3406566 r3421683 30 30 'gpt-5-mini', 31 31 'gpt-5-nano', 32 // GPT-5.1 family 33 'gpt-5.1', 34 'gpt-5.1-chat-latest', 35 // GPT-5.2 family 36 'gpt-5.2', 37 'gpt-5.2-chat-latest', 32 38 // o-series models 33 39 'o1-preview', … … 40 46 } 41 47 // Heuristic: most modern 4o/4.1/o-series variants support tools 42 if (preg_match('/^(gpt-4o|gpt-4\.1|gpt-4-turbo|gpt-5| o[1-4]-mini|o[1-4]-preview)/', $model)) {48 if (preg_match('/^(gpt-4o|gpt-4\.1|gpt-4-turbo|gpt-5|gpt-5\.1|gpt-5\.2|o[1-4]-mini|o[1-4]-preview)/', $model)) { 43 49 return true; 44 50 } … … 76 82 function wpiko_chatbot_get_responses_api_models() 77 83 { 78 return array('gpt-4.1' => 'GPT-4.1', 'gpt-4.1-mini' => 'GPT-4.1 Mini', 'gpt-4.1-nano' => 'GPT-4.1 Nano', 'gpt-5' => 'GPT-5', 'gpt-5-mini' => 'GPT-5 Mini', 'gpt-5-nano' => 'GPT-5 Nano' );84 return array('gpt-4.1' => 'GPT-4.1', 'gpt-4.1-mini' => 'GPT-4.1 Mini', 'gpt-4.1-nano' => 'GPT-4.1 Nano', 'gpt-5' => 'GPT-5', 'gpt-5-mini' => 'GPT-5 Mini', 'gpt-5-nano' => 'GPT-5 Nano', 'gpt-5.1' => 'GPT-5.1', 'gpt-5.1-chat-latest' => 'GPT-5.1 Chat', 'gpt-5.2' => 'GPT-5.2', 'gpt-5.2-chat-latest' => 'GPT-5.2 Chat'); 79 85 } 80 86 } … … 485 491 'gpt-5' => 'GPT-5', 486 492 'gpt-5-mini' => 'GPT-5 Mini', 487 'gpt-5-nano' => 'GPT-5 Nano' 493 'gpt-5-nano' => 'GPT-5 Nano', 494 'gpt-5.1' => 'GPT-5.1', 495 'gpt-5.1-chat-latest' => 'GPT-5.1 Chat', 496 'gpt-5.2' => 'GPT-5.2', 497 'gpt-5.2-chat-latest' => 'GPT-5.2 Chat' 488 498 ); 489 499 } … … 550 560 if (!$model || !is_string($model)) 551 561 return false; 552 $fixed = array('gpt-5', 'gpt-5-mini', 'gpt-5-nano' );562 $fixed = array('gpt-5', 'gpt-5-mini', 'gpt-5-nano', 'gpt-5.1', 'gpt-5.1-chat-latest', 'gpt-5.2', 'gpt-5.2-chat-latest'); 553 563 if (in_array($model, $fixed, true)) 554 564 return true; 555 return (bool) preg_match('/^gpt-5( $|[-_])/', $model);565 return (bool) preg_match('/^gpt-5(\.\d+)?($|[-_])/', $model); 556 566 } 557 567 -
wpiko-chatbot/trunk/readme.txt
r3406566 r3421683 3 3 Tags: chatbot, chatgpt, openai, woocommerce, live-chat 4 4 Requires at least: 6.0 5 Tested up to: 6. 86 Stable tag: 1.0. 65 Tested up to: 6.9 6 Stable tag: 1.0.7 7 7 Requires PHP: 7.0 8 8 License: GPL-2.0+ … … 114 114 == Changelog == 115 115 116 = 1.0.7 = 117 * Added support for latest OpenAI models: GPT-5.1, GPT-5.1 Chat, GPT-5.2, and GPT-5.2 Chat 118 * Added model information display with accurate specifications for all new models 119 116 120 = 1.0.6 = 117 121 * Added client-side timeout handling (90s for chatbot, 60s for contact form) - users now receive clear feedback instead of waiting indefinitely -
wpiko-chatbot/trunk/wpiko-chatbot.php
r3406566 r3421683 4 4 * Plugin URI: https://wpiko.com/chatbot 5 5 * Description: A WordPress plugin that integrates OpenAI's AI models to create an intelligent chatbot for WordPress websites. 6 * Version: 1.0. 66 * Version: 1.0.7 7 7 * Author: WPiko 8 8 * Author URI: https://wpiko.com … … 20 20 define('WPIKO_CHATBOT_PLUGIN_DIR', plugin_dir_path(__FILE__)); 21 21 define('WPIKO_CHATBOT_PLUGIN_URL', plugin_dir_url(__FILE__)); 22 define('WPIKO_CHATBOT_VERSION', '1.0. 6');22 define('WPIKO_CHATBOT_VERSION', '1.0.7'); 23 23 24 24 // Ensures that the default options is set 25 function wpiko_chatbot_set_default_options() { 25 function wpiko_chatbot_set_default_options() 26 { 26 27 $default_image = WPIKO_CHATBOT_PLUGIN_URL . 'assets/images/chatbot-icon.png'; 27 28 add_option('wpiko_chatbot_image', $default_image); 28 29 add_option('wpiko_chatbot_floating_position', 'right'); 29 30 30 31 // Set default to Responses API for new installations 31 32 add_option('wpiko_chatbot_api_type', 'responses'); … … 41 42 42 43 // Enqueuing the necessary scripts and files 43 function wpiko_chatbot_enqueue_scripts() { 44 function wpiko_chatbot_enqueue_scripts() 45 { 44 46 // Use defined version constant with dynamic cache-busting 45 47 $version = WPIKO_CHATBOT_VERSION; 46 48 $version = apply_filters('wpiko_chatbot_asset_version', $version); 47 49 48 50 wp_enqueue_script('wpiko-chatbot-js', WPIKO_CHATBOT_PLUGIN_URL . 'js/wpiko-chatbot.js', array('jquery'), $version, true); 49 51 wp_enqueue_style('wpiko-chatbot-css', WPIKO_CHATBOT_PLUGIN_URL . 'css/wpiko-chatbot.css', array(), $version); 50 52 51 53 // Read CSS content for inlining in transcript downloads 52 54 $css_path = WPIKO_CHATBOT_PLUGIN_DIR . 'css/frontend-transcript-styles.css'; … … 55 57 $css_content = file_get_contents($css_path); 56 58 } 57 59 58 60 // Localize script for frontend transcript CSS 59 61 wp_localize_script('wpiko-chatbot-js', 'wpikoAjax', array( … … 65 67 66 68 // Include files 67 require_once WPIKO_CHATBOT_PLUGIN_DIR . 'admin/admin-page.php';68 require_once WPIKO_CHATBOT_PLUGIN_DIR . 'admin/includes/plugin-header.php';69 70 require_once WPIKO_CHATBOT_PLUGIN_DIR . 'admin/sections/dashboard-section.php';71 require_once WPIKO_CHATBOT_PLUGIN_DIR . 'admin/sections/api-key-section.php';72 require_once WPIKO_CHATBOT_PLUGIN_DIR . 'admin/sections/ai-configuration-section.php';73 require_once WPIKO_CHATBOT_PLUGIN_DIR . 'admin/sections/floating-chatbot-section.php';74 require_once WPIKO_CHATBOT_PLUGIN_DIR . 'admin/sections/shortcode-chatbot-section.php';75 require_once WPIKO_CHATBOT_PLUGIN_DIR . 'admin/sections/chatbot-style-section.php';76 require_once WPIKO_CHATBOT_PLUGIN_DIR . 'admin/sections/chatbot-menu-section.php';77 require_once WPIKO_CHATBOT_PLUGIN_DIR . 'admin/sections/questions-section.php';78 require_once WPIKO_CHATBOT_PLUGIN_DIR . 'admin/sections/conversations-section.php';79 require_once WPIKO_CHATBOT_PLUGIN_DIR . 'admin/sections/error-messages-section.php';80 81 require_once WPIKO_CHATBOT_PLUGIN_DIR . 'chatbot-interface.php';82 83 require_once WPIKO_CHATBOT_PLUGIN_DIR . 'includes/logging.php'; 84 require_once WPIKO_CHATBOT_PLUGIN_DIR . 'includes/floating-chatbot.php';85 require_once WPIKO_CHATBOT_PLUGIN_DIR . 'includes/responses-api.php';86 require_once WPIKO_CHATBOT_PLUGIN_DIR . 'includes/conversation-handler.php';87 require_once WPIKO_CHATBOT_PLUGIN_DIR . 'includes/markdown-handler.php';88 require_once WPIKO_CHATBOT_PLUGIN_DIR . 'includes/api-helpers.php';89 require_once WPIKO_CHATBOT_PLUGIN_DIR . 'includes/sound-functions.php';90 require_once WPIKO_CHATBOT_PLUGIN_DIR . 'includes/files-list-handler.php';91 require_once WPIKO_CHATBOT_PLUGIN_DIR . 'includes/instructions-handler.php';92 require_once WPIKO_CHATBOT_PLUGIN_DIR . 'includes/cache-management.php';93 require_once WPIKO_CHATBOT_PLUGIN_DIR . 'includes/conversation-translation.php';69 require_once WPIKO_CHATBOT_PLUGIN_DIR . 'admin/admin-page.php'; 70 require_once WPIKO_CHATBOT_PLUGIN_DIR . 'admin/includes/plugin-header.php'; 71 72 require_once WPIKO_CHATBOT_PLUGIN_DIR . 'admin/sections/dashboard-section.php'; 73 require_once WPIKO_CHATBOT_PLUGIN_DIR . 'admin/sections/api-key-section.php'; 74 require_once WPIKO_CHATBOT_PLUGIN_DIR . 'admin/sections/ai-configuration-section.php'; 75 require_once WPIKO_CHATBOT_PLUGIN_DIR . 'admin/sections/floating-chatbot-section.php'; 76 require_once WPIKO_CHATBOT_PLUGIN_DIR . 'admin/sections/shortcode-chatbot-section.php'; 77 require_once WPIKO_CHATBOT_PLUGIN_DIR . 'admin/sections/chatbot-style-section.php'; 78 require_once WPIKO_CHATBOT_PLUGIN_DIR . 'admin/sections/chatbot-menu-section.php'; 79 require_once WPIKO_CHATBOT_PLUGIN_DIR . 'admin/sections/questions-section.php'; 80 require_once WPIKO_CHATBOT_PLUGIN_DIR . 'admin/sections/conversations-section.php'; 81 require_once WPIKO_CHATBOT_PLUGIN_DIR . 'admin/sections/error-messages-section.php'; 82 83 require_once WPIKO_CHATBOT_PLUGIN_DIR . 'chatbot-interface.php'; 84 85 require_once WPIKO_CHATBOT_PLUGIN_DIR . 'includes/logging.php'; 86 require_once WPIKO_CHATBOT_PLUGIN_DIR . 'includes/floating-chatbot.php'; 87 require_once WPIKO_CHATBOT_PLUGIN_DIR . 'includes/responses-api.php'; 88 require_once WPIKO_CHATBOT_PLUGIN_DIR . 'includes/conversation-handler.php'; 89 require_once WPIKO_CHATBOT_PLUGIN_DIR . 'includes/markdown-handler.php'; 90 require_once WPIKO_CHATBOT_PLUGIN_DIR . 'includes/api-helpers.php'; 91 require_once WPIKO_CHATBOT_PLUGIN_DIR . 'includes/sound-functions.php'; 92 require_once WPIKO_CHATBOT_PLUGIN_DIR . 'includes/files-list-handler.php'; 93 require_once WPIKO_CHATBOT_PLUGIN_DIR . 'includes/instructions-handler.php'; 94 require_once WPIKO_CHATBOT_PLUGIN_DIR . 'includes/cache-management.php'; 95 require_once WPIKO_CHATBOT_PLUGIN_DIR . 'includes/conversation-translation.php'; 94 96 95 97 // Register shortcode … … 97 99 98 100 // Shortcode function to display the chatbot 99 function wpiko_chatbot_shortcode($atts) { 101 function wpiko_chatbot_shortcode($atts) 102 { 100 103 // Process any attributes if needed 101 104 $atts = shortcode_atts(array( 102 105 // You can add custom attributes here if needed 103 106 ), $atts); 104 107 105 108 // Return the chatbot display 106 109 return wpiko_chatbot_display(); … … 108 111 109 112 // Add AJAX handler for sending messages 110 function wpiko_chatbot_ajax_handler() { 113 function wpiko_chatbot_ajax_handler() 114 { 111 115 check_ajax_referer('wpiko_chatbot_nonce', 'security'); 112 116 113 117 $encrypted_api_key = get_option('wpiko_chatbot_api_key', ''); 114 118 $api_key = wpiko_chatbot_decrypt_api_key($encrypted_api_key); … … 130 134 wp_die(); 131 135 } 132 136 133 137 $message = sanitize_textarea_field(wp_unslash($_POST['message'])); 134 138 $conversation_id = isset($_POST['thread_id']) ? sanitize_text_field(wp_unslash($_POST['thread_id'])) : null; 135 139 $user_email = isset($_POST['user_email']) ? sanitize_email(wp_unslash($_POST['user_email'])) : ''; 136 140 137 141 // Process user_name parameter 138 142 if (isset($_POST['user_name'])) { … … 142 146 } 143 147 } 144 148 145 149 if (is_user_logged_in()) { 146 150 $current_user = wp_get_current_user(); … … 149 153 150 154 $result = wpiko_chatbot_responses_api_call($message, $conversation_id, $user_email); 151 155 152 156 if (isset($result['success']) && $result['success'] === false) { 153 157 wp_send_json_error($result['data']); … … 155 159 // Debug logging 156 160 wpiko_chatbot_log('Responses API result: ' . json_encode($result), 'info'); 157 161 158 162 // Ensure response is a string 159 163 $response_text = isset($result['response']) ? $result['response'] : ''; … … 162 166 $response_text = (string) $response_text; 163 167 } 164 168 165 169 // Format response to match expected format 166 170 $response_data = array( … … 170 174 wp_send_json_success($response_data); 171 175 } 172 176 173 177 wp_die(); 174 178 } … … 178 182 179 183 180 function wpiko_chatbot_localize_script() { 184 function wpiko_chatbot_localize_script() 185 { 181 186 $encrypted_api_key = get_option('wpiko_chatbot_api_key', ''); 182 187 $api_key = wpiko_chatbot_decrypt_api_key($encrypted_api_key); 183 188 $sound_enabled = get_option('wpiko_chatbot_sound_enabled', '1'); 184 189 185 190 // Configuration is complete if API key is set (using Responses API) 186 191 $config_complete = !empty($api_key); 187 192 188 193 // Get reCAPTCHA settings 189 194 $enable_recaptcha = get_option('wpiko_chatbot_enable_recaptcha', '0'); … … 220 225 221 226 // Function to encrypt the API key 222 function wpiko_chatbot_encrypt_api_key($api_key) { 223 if (empty($api_key)) return ''; 224 227 function wpiko_chatbot_encrypt_api_key($api_key) 228 { 229 if (empty($api_key)) 230 return ''; 231 225 232 $encryption_key = wp_salt('auth'); 226 233 $iv = openssl_random_pseudo_bytes(openssl_cipher_iv_length('AES-256-CBC')); 227 234 $encrypted = openssl_encrypt($api_key, 'AES-256-CBC', $encryption_key, 0, $iv); 228 235 229 236 return base64_encode($encrypted . '::' . $iv); 230 237 } 231 238 232 239 // Function to decrypt the API key 233 function wpiko_chatbot_decrypt_api_key($encrypted_api_key) { 234 if (empty($encrypted_api_key)) return ''; 235 240 function wpiko_chatbot_decrypt_api_key($encrypted_api_key) 241 { 242 if (empty($encrypted_api_key)) 243 return ''; 244 236 245 $encryption_key = wp_salt('auth'); 237 246 list($encrypted_data, $iv) = explode('::', base64_decode($encrypted_api_key), 2); 238 247 239 248 return openssl_decrypt($encrypted_data, 'AES-256-CBC', $encryption_key, 0, $iv); 240 249 } … … 245 254 * @return bool Whether the pro plugin is active 246 255 */ 247 function wpiko_chatbot_is_pro_plugin_active() { 256 function wpiko_chatbot_is_pro_plugin_active() 257 { 248 258 if (!function_exists('is_plugin_active')) { 249 259 include_once ABSPATH . 'wp-admin/includes/plugin.php'; 250 260 } 251 261 252 262 return is_plugin_active('wpiko-chatbot-pro/wpiko-chatbot-pro.php'); 253 263 } … … 256 266 * Check if WooCommerce is active 257 267 */ 258 function wpiko_chatbot_is_woocommerce_active() { 268 function wpiko_chatbot_is_woocommerce_active() 269 { 259 270 if (!function_exists('is_plugin_active')) { 260 271 include_once ABSPATH . 'wp-admin/includes/plugin.php'; 261 272 } 262 273 263 274 return is_plugin_active('woocommerce/woocommerce.php'); 264 275 }
Note: See TracChangeset
for help on using the changeset viewer.