PluginProbe
Templately – Elementor & Gutenberg Template Library: 6500+ Free & Pro Ready Templates And Cloud! / 3.5.2
Templately – Elementor & Gutenberg Template Library: 6500+ Free & Pro Ready Templates And Cloud! v3.5.2
3.7.5 3.7.4 3.7.3 3.7.2 1-final 3.7.1 3.7.0 3.6.8 3.6.7 3.6.6 3.6.5 3.6.4 3.6.3 3.6.2 3.6.1 3.0.3 3.0.4 3.0.5 3.0.6 3.0.7 3.0.8 3.0.9 3.1.0 3.1.1 3.1.10 All 111 releases
← All changes | includes/API/AIContent.php +21 -73 3.6.63.5.2 View file →
@@ -89,17 +89,8 @@
89 89 $this->post($this->endpoint . '/modify-content', [$this, 'modify_content']);
90 90 $this->post($this->endpoint . '/ai-update', [$this, 'ai_update']);
91 91 $this->post($this->endpoint . '/ai-update-preview', [$this, 'ai_update_preview']);
92 92 $this->post($this->endpoint . '/generate-tagline', [$this, 'generate_tagline']);
93 - $this->get($this->endpoint . '/chatbot-conversation', [$this, 'get_chatbot_conversation'], [
94 - 'chat' => [
95 - 'required' => true,
96 - 'sanitize_callback' => 'sanitize_text_field',
97 - 'validate_callback' => function($param, $request, $key) {
98 - return is_string($param) && strlen($param) > 0 && strlen($param) <= 128 && preg_match('/^[A-Za-z0-9\-_]+$/', $param);
99 - },
100 - ],
101 - ]);
102 93 $this->get($this->endpoint . '/attachments', [$this, 'get_attachments'], [
103 94 'type' => [
104 95 'default' => 'pack',
105 96 'required' => false,
@@ -334,27 +325,26 @@
334 325
335 326 $user = $this->utils('options')->get('user');
336 327
337 328 $ai_process_data[$process_id] = [
338 - 'name' => $name,
339 - 'category' => $category,
340 - 'description' => $description,
341 - 'email' => $email,
342 - 'contactNumber' => $contactNumber,
343 - 'businessAddress' => $businessAddress,
344 - 'openingHour' => $openingHour,
345 - 'process_id' => $process_id,
346 - 'pack_id' => $pack_id,
347 - 'ai_page_ids' => $ai_page_ids,
348 - 'ai_preview_ids' => $preview_pages,
349 - 'content_ids' => $content_ids,
350 - 'platform' => $platform,
351 - 'api_key' => $this->api_key,
352 - 'user_id' => isset($user['id']) ? $user['id'] : null,
353 - 'session_id' => $session_id,
354 - 'imageReplace' => $image_replace,
355 - 'language' => $language,
356 - 'requested_platform' => $requested_platform,
329 + 'name' => $name,
330 + 'category' => $category,
331 + 'description' => $description,
332 + 'email' => $email,
333 + 'contactNumber' => $contactNumber,
334 + 'businessAddress' => $businessAddress,
335 + 'openingHour' => $openingHour,
336 + 'process_id' => $process_id,
337 + 'pack_id' => $pack_id,
338 + 'ai_page_ids' => $ai_page_ids,
339 + 'ai_preview_ids' => $preview_pages,
340 + 'content_ids' => $content_ids,
341 + 'platform' => $platform,
342 + 'api_key' => $this->api_key,
343 + 'user_id' => isset($user['id']) ? $user['id'] : null,
344 + 'session_id' => $session_id, // Store session_id for coordination
345 + 'imageReplace' => $image_replace, // Store session_id for coordination
346 + 'language' => $language,
357 347 ];
358 348
359 349 // Update using API key-based storage with automatic count-based cleanup
360 350 AIUtils::update_ai_process_data($ai_process_data);
@@ -520,11 +510,10 @@
520 510 * @return array|\WP_Error
521 511 */
522 512 public function get_attachments() {
523 513 // Get parameters from request
524 - $type = $this->get_param('type', 'pack');
525 - $id = $this->get_param('pack_id');
526 - $requested_platform = $this->get_param('requested_platform', 'templately');
514 + $type = $this->get_param('type', 'pack');
515 + $id = $this->get_param('pack_id');
527 516
528 517 // Require ID parameter - return error if not provided
529 518 if (empty($id)) {
530 519 return $this->error('missing_id', __('Pack ID or ID parameter is required.', 'templately'), 'get_attachments', 400);
@@ -535,10 +524,9 @@
535 524 $api_endpoint = "get-xml-attachment/{$type}/{$id}";
536 525
537 526 // Make API call
538 527 $extra_headers = [
539 - 'Accept' => 'application/xml, text/xml',
540 - 'x-templately-requested-platform' => $requested_platform,
528 + 'Accept' => 'application/xml, text/xml',
541 529 ];
542 530 $response = Helper::make_api_get_request("v2/$api_endpoint", [], $extra_headers, 30);
543 531
544 532 // Check for HTTP errors
@@ -941,48 +929,8 @@
941 929 );
942 930 }
943 931
944 932 // Return the response as-is
945 - return $data;
946 - }
947 -
948 - /**
949 - * Fetch a chatbot conversation by ID from the external Templately chatbot API.
950 - *
951 - * Used to resume a conversation that began on templately.dev when the user
952 - * is redirected into the plugin with ?process=ai&chat={uuid}.
953 - *
954 - * @return array|\WP_Error Pass-through of the external response { status, data } or WP_Error.
955 - */
956 - public function get_chatbot_conversation() {
957 - $chat = $this->get_param('chat');
958 -
959 - if (empty($chat)) {
960 - return $this->error('invalid_chat_id', __('Invalid conversation ID.', 'templately'), 'ai-content/chatbot-conversation', 400);
961 - }
962 -
963 - $extra_headers = [
964 - 'Accept' => 'application/json',
965 - ];
966 - $response = Helper::make_api_get_request("v2/chatbot/conversation/{$chat}", [], $extra_headers, 30);
967 -
968 - if (is_wp_error($response)) {
969 - return $this->error('request_failed', __('Failed to fetch conversation.', 'templately'), 'ai-content/chatbot-conversation', 500, ['error_detail' => $response->get_error_message()]);
970 - }
971 -
972 - $response_code = wp_remote_retrieve_response_code($response);
973 - $body = wp_remote_retrieve_body($response);
974 - $data = json_decode($body, true);
975 -
976 - if ($response_code !== 200) {
977 - $message = (is_array($data) && !empty($data['message'])) ? $data['message'] : sprintf(__('API returned HTTP %d error.', 'templately'), $response_code);
978 - return $this->error('api_http_error', $message, 'ai-content/chatbot-conversation', $response_code);
979 - }
980 -
981 - if (!is_array($data) || !isset($data['status'])) {
982 - return $this->error('invalid_response', __('Invalid response.', 'templately'), 'ai-content/chatbot-conversation', 500);
983 - }
984 -
985 933 return $data;
986 934 }
987 935
988 936 /**