• Resolved zsolt

    (@zsolt82)


    Hello

    Is it possible to introduce restrictions?

    1. only logged-in and logged-out users or users with certain roles can see it (can be set in Administration)
    2. Limiting the chat to, say, 10 questions. (can be set in admin)

    There are users who play with the chatbot pointlessly. We are out of tokens

    Thaks

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

    (@tigroumeow)

    Hi,

    You will need to add some custom code. AI Engine runs a filter before every request is made: mwai_ai_allowed. You can hook in it, and if you return anything else than true, it will generate an error to the user.

    You could actually do something like this:

    add_filter('mwai_ai_allowed', function ($allowed) {
    
      if (is_user_logged_in()) {
        if (session_status() == PHP_SESSION_NONE) {
          session_start();
        }
        if (!isset($_SESSION['counter'])) {
          $_SESSION['counter'] = 0;
        }
        $_SESSION['counter']++;
        if ($_SESSION['counter'] > 10) {
          return "Sorry, you can't ask more than 10 questions.";
        }
        else {
          return $allowed;
        }
      }
      else {
        return "Sorry, you need to be connected.";
      }
      return $allowed;
    });
    
    Thread Starter zsolt

    (@zsolt82)

    Thanks

    how can I record the questions and answers on the server, say in txt.

    If, for example, contact information is given for a call back, etc

    Plugin Author Jordy Meow

    (@tigroumeow)

    You can hook into the mwai_ai_reply filter. Through it, you’ll be able to get the Answer and Answer objects, and do whatever you like with them. Just be careful to return the answer at the end (the original one).

    Here is an example in my tutorial: https://meowapps.com/ai-engine/tutorial/#modify-the-reply-or-perform-an-action-on-it

    Thread Starter zsolt

    (@zsolt82)

    Hello

    There is no registration option on the site. I wrote the code like this, but it only records the chatbot’s responses:

    add_filter( 'mwai_ai_reply', function ( $answer, $query ) {
        $root_path = $_SERVER['DOCUMENT_ROOT'];
        $file = fopen("${root_path}/data.txt", "a");
        fwrite($file, $answer->result . "\n");
        fclose($file);
        return $answer;
    }, 10, 2 );

    If I expand the code like this:

    add_filter( 'mwai_ai_reply', function ( $answer, $query ) {
    $root_path = $_SERVER['DOCUMENT_ROOT'];
    $file = fopen("${root_path}/data.txt", "a");
    fwrite($file, $query . " : " . $answer->result . "\n");
    fclose($file);
    return $answer;
    }, 10, 2 );

    The chatbot then sends an error message

    System:
    A serious error has occurred on our website.

    I’m not a programmer, so I don’t understand the cause of the problem. The error log does not write errors. and neither is debugging.

    What could be the problem?

    Thanks

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Restrictions’ is closed to new replies.