• Resolved johocen168

    (@johocen168)


    Hi there,

    I created a chatbot which will answer with a percentage for score, how can I retrive that to be used in another plugin such as myCred ?

    btw, What is the limitation for the number of chatbots can be created?

    Thanks

    The page I need help with: [log in to see the link]

Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Author Jordy Meow

    (@tigroumeow)

    Hi @johocen168,

    What is the limitation for the number of chatbots can be created?

    Sky is the limit.

    I created a chatbot which will answer with a percentage for score, how can I retrive that to be used in another plugin such as myCred ?

    That is very complex, you’ll need to catch the answer from the AI, parse it by yourself and input the data in the other plugin you mentioned. Have a look here: https://meowapps.com/ai-engine/api/. You can get the reply from the AI through the mwai_chatbot_reply filter and use it for something else (it will not impact the behavior of the chatbot). A developer will have no problem doing this ??

    Thread Starter johocen168

    (@johocen168)

    Hi @tigroumeow,

    We are working on this…

    The overall objective is to parse the percentage score of a login user, from the reply of the AI Engine plugin in WordPress, using the mwai_chatbot_reply filter. If the score is 60% or higher, the code should award x points to the user, using the Hook API of the myCred plugin. Additionally, a hook code is required in the myCred plugin to receive the call from the above function and award the points to the user. The sub-task is to add error handling to the code so that it can handle situations where the percentage score cannot be extracted or the myCred Hook API call fails.

    Question: we have 2 chatbots in each post, how can we identify which mwai_chatbot_reply to be fetched, and how to link it with login user id?

    Here is the initial code, but got error…Return type of Meow_MWAI_Reply::jsonSerialize() should either be compatible with JsonSerializable::jsonSerialize(): mixed, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /var/web/site/public_html/wp-content/plugins/ai-engine/classes/reply.php on line 15

    function extract_percentage_score( $reply, $user_id ) {
        // Use regular expressions to find the percentage score in the reply
        if ( preg_match( '/Score: (\d+)%/', $reply, $matches ) ) {
            $percentage_score = intval( $matches[1] );
            
            // Handle case where percentage score cannot be extracted
            if ( $percentage_score == 0 ) {
                error_log( 'Failed to extract percentage score from AI Engine reply' );
                return $reply;
            }
            
            // Store the user ID and percentage score in variables
            $user_id = get_current_user_id();
            $score = $percentage_score;
            
            // Call the myCred Hook API to award points to the user if score is 60% or higher
            if ( $score >= 60 ) {
                $points = 50; // Change this to the number of points you want to award
                $result = mycred_add( 'score', $user_id, $points, 'Scored 60% or higher' );
                
                // Handle case where myCred Hook API call fails
                if ( ! $result ) {
                    error_log( 'Failed to award points using myCred Hook API' );
                } else {
                    // Log the Hook API call and number of points awarded
                    error_log( 'Awarded ' . $points . ' points to user ID ' . $user_id . ' using myCred Hook API' );
                }
            }
        }
        
        return $reply;
    }
    add_filter( 'mwai_chatbot_reply', 'extract_percentage_score', 10, 2 );
    

    We are willing to pay for the hours of consulting if you are willing to guide us for this function.

    Thanks

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘How to retrive the completion/answer from chatbot?’ is closed to new replies.