PluginProbe
WPBot – AI ChatBot for Live Support, Lead Generation, WordPress Automation, AI Services / 8.8.2
WPBot – AI ChatBot for Live Support, Lead Generation, WordPress Automation, AI Services v8.8.2
8.8.3 8.8.2 8.8.1 8.8.0 8.7.9 8.7.8 8.7.7 8.7.6 8.7.5 8.7.4 8.7.3 8.7.2 8.7.1 8.7.0 8.6.9 8.6.8 8.6.7 8.6.6 8.6.5 8.6.4 8.6.2 8.6.1 8.6.0 8.5.9 8.5.8 All 539 releases
← All changes | includes/integration/claude/qcld-bot-claude.php +30 -13 8.7.4 → 8.8.2 View file →
@@ -65,9 +65,9 @@
65 65 }
66 66
67 67 public function qcld_claude_settings_option_callback() {
68 68 $nonce = sanitize_text_field( $_POST['nonce'] );
69 - if ( ! wp_verify_nonce( $nonce, 'wp_chatbot' ) ) {
69 + if ( ! wp_verify_nonce( $nonce, 'wp_chatbot' ) || ! current_user_can( 'manage_options' ) ) {
70 70 wp_send_json( array( 'success' => false, 'msg' => esc_html__( 'Failed in Security check', 'chatbot' ) ) );
71 71 wp_die();
72 72 } else {
73 73 $claude_api_key = sanitize_text_field( $_POST['claude_api_key'] ?? '' );
@@ -128,9 +128,17 @@
128 128
129 129 if( isset($result_body['error']) ) {
130 130 wp_send_json( array( 'status' => 'error', 'msg' => esc_html( $result_body['error']['message'] ) ) );
131 131 } elseif ( isset($result_body['content']) && is_array($result_body['content']) ) {
132 - wp_send_json( array( 'status' => 'success', 'msg' => esc_html( $result_body['content'][0]['text'] ) ) );
132 + $text_content = '';
133 + foreach ($result_body['content'] as $block) {
134 + if (isset($block['type']) && $block['type'] === 'text' && !empty($block['text'])) {
135 + $text_content .= $block['text'];
136 + }
137 + }
138 + if (!empty($text_content)) {
139 + wp_send_json( array( 'status' => 'success', 'msg' => esc_html( $text_content ) ) );
140 + }
133 141 }
134 142 wp_die();
135 143 }
136 144
@@ -252,9 +260,9 @@
252 260 $relevant_pagelinks = '<br><br><p><em>' . $relevant_post_link[ get_wpbot_locale() ] . '</em><p>' . implode( '</br>', $relevant_pagelink );
253 261 }
254 262 }
255 263
256 - $Parsedown = new Parsedown();
264 + $Parsedown = new Qcld_Parsedown();
257 265
258 266 $claude_model = get_option( 'qcld_claude_model' );
259 267 if ( empty( $claude_model ) || strpos( $claude_model, 'latest' ) !== false ) { $claude_model = 'claude-sonnet-4-6'; }
260 268 $api_url = 'https://api.anthropic.com/v1/messages';
@@ -308,9 +316,10 @@
308 316 $system_content .= "2. Wait for the user's response before asking the next question.\n";
309 317 $system_content .= "3. Once all necessary information is collected for the form, you MUST output a final JSON block summarizing the collected data. The keys inside the \"data\" object MUST be dynamically named based on the specific questions you asked during the form collection (e.g., \"Full Name\", \"Company Size\", \"Email\", etc.). The final JSON block must be wrapped EXACTLY in these delimiters:\n";
310 318 $system_content .= "__AI_FORM_DATA__{ \"form_title\": \"<Form Title>\", \"data\": { \"Question 1\": \"Answer 1\", \"Question 2\": \"Answer 2\" } }__AI_FORM_DATA_END__\n";
311 319 $system_content .= "Do not include any other text after this JSON block once the form is complete.\n";
312 - $system_content .= "4. If the user provides an invalid, irrelevant, or nonsensical answer to your question, DO NOT apologize or state that you lack information. Instead, respond with 'Invalid answer found' and ask the exact same question again.";
320 + $system_content .= "4. If the user provides an invalid, irrelevant, or nonsensical answer to your question, DO NOT apologize or state that you lack information. Instead, politely inform the user in the language of the conversation (the language the user is speaking in, e.g. German if communicating in German) that their answer is invalid or cannot be assigned, and ask the exact same question again in the user's language. NEVER output the English phrase 'Invalid answer found' unless the user is communicating in English.\n";
321 + $system_content .= "5. MULTI-LANGUAGE SUPPORT: Always communicate, ask questions, validate answers, and reply strictly in the user's language (matching the language used by the user, e.g. German, French, Spanish, etc.). Understand and accept valid answers in the user's language.";
313 322 }
314 323
315 324 $contents = $history;
316 325 $last_msg = end($contents);
@@ -353,18 +362,26 @@
353 362 $http_code = wp_remote_retrieve_response_code($result);
354 363 $body = wp_remote_retrieve_body($result);
355 364 $msg = json_decode($body, true);
356 365
357 - if (isset($msg['content']) && is_array($msg['content']) && !empty($msg['content'][0]['text'])) {
358 - $response['status'] = 'success';
359 - $reply_text = $Parsedown->text( $msg['content'][0]['text'] );
360 - if (strpos($reply_text, 'AI_FORM_DATA') !== false) {
361 - $reply_text = Qcld_WPBot_Common_Functions::format_and_save_ai_form_response($reply_text);
362 - $response['message'] = $reply_text;
363 - } else {
364 - $response['message'] = $reply_text . $relevant_pagelinks;
366 + if (isset($msg['content']) && is_array($msg['content'])) {
367 + $text_content = '';
368 + foreach ($msg['content'] as $block) {
369 + if (isset($block['type']) && $block['type'] === 'text' && !empty($block['text'])) {
370 + $text_content .= $block['text'];
371 + }
365 372 }
366 - break;
373 + if (!empty($text_content)) {
374 + $response['status'] = 'success';
375 + $reply_text = $Parsedown->text( $text_content );
376 + if (strpos($reply_text, 'AI_FORM_DATA') !== false) {
377 + $reply_text = Qcld_WPBot_Common_Functions::format_and_save_ai_form_response($reply_text);
378 + $response['message'] = $reply_text;
379 + } else {
380 + $response['message'] = $reply_text . $relevant_pagelinks;
381 + }
382 + break;
383 + }
367 384 }
368 385
369 386 if (($http_code == 503 || $http_code == 429) && $attempt < $max_attempts) {
370 387 $wait_seconds = $attempt * 2;