Plugin Directory

Changeset 3335155


Ignore:
Timestamp:
07/28/2025 06:57:00 AM (7 months ago)
Author:
techbeeps
Message:

version 1.7

Location:
replypilot-ai
Files:
33 added
4 edited

Legend:

Unmodified
Added
Removed
  • replypilot-ai/trunk/ai-chatbot.php

    r3322100 r3335155  
    8484    $conversation_id = $wpdb->insert_id;
    8585
     86    setcookie("replypilot_conversation_id", $conversation_id, time() + 1296000, "/"); // 15 days
    8687    // Add welcome message to conversation
    8788    if ($conversation_id) {
     
    219220
    220221    $body = json_decode($response['body'], true);
    221     error_log(print_r($body, true));
    222222    if (isset($body['candidates'][0]['content']['parts'][0]['text'])) {
    223223
     
    469469    }
    470470}
     471
     472add_action('wp_ajax_replypilot_get_chatbot_messages', 'replypilot_get_chatbot_messages_callback');
     473add_action('wp_ajax_nopriv_replypilot_get_chatbot_messages', 'replypilot_get_chatbot_messages_callback');
     474
     475function replypilot_get_chatbot_messages_callback() {
     476    check_ajax_referer('replypilot_ai_chatbot_nonce', 'nonce');
     477
     478    global $wpdb;
     479    $conversation_id = isset($_POST['conversation_id']) ? sanitize_text_field(wp_unslash($_POST['conversation_id'])) : '';
     480    if (empty($conversation_id)) {
     481        wp_send_json_error(['message' => 'Missing conversation ID']);
     482    }
     483    $messages = $wpdb->get_results(
     484        $wpdb->prepare("SELECT * FROM {$wpdb->prefix}replypilot_chatbot_messages WHERE conversation_id = %s ORDER BY sent_at ASC", $conversation_id),
     485        ARRAY_A
     486    );
     487    // Escape output
     488    $escaped_messages = array_map(function($message) {
     489        return [
     490            'message_type' => esc_html($message['message_type']),
     491            'content' => esc_html($message['content']),
     492            'sent_at' => esc_html($message['sent_at']),
     493        ];
     494    }, $messages);
     495
     496    wp_send_json_success(['messages' => $escaped_messages]);
     497}
     498
  • replypilot-ai/trunk/assets/js/script.js

    r3322100 r3335155  
    11jQuery(document).ready(function ($) {
     2
     3    function get_chatbot_Cookie(name) {
     4        const value = `; ${document.cookie}`;
     5        const parts = value.split(`; ${name}=`);
     6        if (parts.length === 2) return parts.pop().split(';').shift();
     7    }
     8
     9    function chatbotfetchMessages(conversation_id) {
     10        fetch(replypilotChatbot.ajaxurl, {
     11            method: 'POST',
     12            headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
     13            body: new URLSearchParams({
     14                action: 'replypilot_get_chatbot_messages',
     15                nonce: replypilotChatbot.nonce,
     16                conversation_id: conversation_id
     17            })
     18        })
     19            .then(res => res.json())
     20            .then(data => {
     21                if (data.success) {
     22                    dataset = data.data.messages;
     23                    sessionStorage.setItem("replypilot_chatHistory", JSON.stringify(dataset));
     24                    for (msgdata of dataset) {
     25                        addMessage(msgdata.message_type, msgdata.content, undefined, msgdata.sent_at);
     26                    }
     27                } else {
     28                    console.error(data.message);
     29                }
     30            });
     31    }
     32
    233    // Chatbot state
     34    const userid = get_chatbot_Cookie("replypilot_conversation_id");
    335    let chatHistory = [];
    4     let isOpen = false;
    5     let conversationId = null;
     36    let isOpen = userid ? true : false;
     37    let conversationId = userid ?? null;
    638    let userData = null;
    739
    840    // Initialize chatbot
    941    function initChatbot() {
     42        const history = JSON.parse(sessionStorage.getItem("replypilot_chatHistory"));
     43        if (isOpen) {
     44            if (history) {
     45                for (msgdata of history) {
     46                    addMessage(msgdata.message_type, msgdata.content, undefined, msgdata.sent_at);
     47                }
     48            } else {
     49                chatbotfetchMessages(userid)
     50            }
     51        }
    1052
    1153        // Close button
     
    1355
    1456        // Handle sending messages
    15         $('#replypilot-chatbot-send').on('click', function () {   
    16                 sendMessage();         
     57        $('#replypilot-chatbot-send').on('click', function () {
     58            sendMessage();
    1759        });
    1860
     
    3072        $(document).on('click', '#replypilot-chatbot-toggle', function () {
    3173            if (!isOpen && (!userData || !conversationId)) {
    32 
    3374                showUserDataForm();
    3475            } else {
    3576                toggleChatbot();
    3677            }
    37 
    3878        });
    3979
     
    4686
    4787    // Toggle chatbot open/close
    48     function toggleChatbot() {
    49         if (isOpen) {
     88    function toggleChatbot(end = false) {
     89        if (!isOpen && end) {
    5090            $('#replypilot-chatbot-container').addClass('closed');
    5191            if (conversationId) {
     
    104144                    conversation_id: conversationId
    105145                };
     146
    106147                // Hide form and show chat
    107148                hideUserDataForm();
     
    129170
    130171    // Add message to chat
    131     function addMessage(sender, message, services = []) {
     172    function addMessage(sender, message, services = [], data = null) {
     173
     174        if (!data) {
     175            const history = JSON.parse(sessionStorage.getItem("replypilot_chatHistory")) || [];
     176            history.push({ message_type: sender, content: message, sent_at: new Date() });
     177            sessionStorage.setItem("replypilot_chatHistory", JSON.stringify(history));
     178        }
    132179
    133180        message = message.replace(/\*\*/g, '');
    134181        message = message.replace(/\n/g, '<br>');
    135         const timestamp = new Date().toLocaleTimeString([], { hour: '2-digit', minute: '2-digit' });
     182        date = data ? new Date(data) : new Date();
     183        const timestamp = date.toLocaleTimeString([], { hour: '2-digit', minute: '2-digit' });
    136184        const messageClass = sender === 'user' ? 'replypilot-user-message' : 'replypilot-bot-message';
    137185        let buttonsHtml = '<div class="replypilot-service-buttons">';
     
    215263        $('#replypilot-chatbot-messages').find(".replypilot-service-btn").prop("disabled", true);
    216264    });
    217 
    218 
    219265    // Initialize
    220266    initChatbot();
     267
    221268});
    222269
  • replypilot-ai/trunk/readme.txt

    r3322100 r3335155  
    11=== ReplyPilot AI ===
    22Contributors: techbeeps, gurjeet6090
    3 Tags: free comment reply, free chatbot, chatbot, comment bot,ai chatbot
     3Tags:ai assistant, chatbot, comment bot,ai chatbot,auto reply
    44Requires at least: 5.0
    55Tested up to: 6.8
    66Requires PHP: 7.4
    7 Stable tag: 1.6
     7Stable tag: 1.7
    88License: GPL-2.0+
    99License URI: https://www.gnu.org/licenses/gpl-2.0.html
     
    140140
    141141== Changelog ==
     142= 1.7 =
     143* Now user can refresh the page and close the browser but still the chat history will be back".
     144
    142145= 1.6 =
    143146* Send Chatbot button conflict fixed".
     
    164167== Upgrade Notice ==
    165168
    166 = 1.4 =
    167 * New Feature: Added user interface to show question suggestions.
     169= 1.7 =
     170* New Feature: Now user can refresh the page and close the browser but still the chat history will be back.
    168171
    169172
  • replypilot-ai/trunk/replypilot-ai.php

    r3322100 r3335155  
    44Plugin URI:  https://replypilot.techbeeps.com/
    55Description: AI-powered plugin that auto-generates human-like replies to user comments and provides a real-time chatbot on your website.
    6 Version:     1.6
     6Version:     1.7
    77Author:      Techbeeps
    88Author URI:  https://techbeeps.co.in/
     
    1616}
    1717
    18 define('REPLYPILOT_AI_TBS', '1.6');
     18define('REPLYPILOT_AI_TBS', '1.7');
    1919define('REPLYPILOT_AI_TBS_PATH', plugin_dir_path(__FILE__));
    2020define('REPLYPILOT_AI_TBS_URL',  __FILE__);
Note: See TracChangeset for help on using the changeset viewer.