The error messages shown in red in the chat come 90% of the time directly from the AI providers you are using, not from the plugin. If there’s an issue on the plugin side, you might see the error in the PHP error logs instead. These messages sent by the AI service (e.g., when a query couldn’t be processed) might make sense to you as a developer but not to your clients using the chatbot. So, you can override these error messages.
There is a mwai_ai_exception filter that you can hook to, and that takes an argument (the original error message) and you can return whatever message you’d like to return. For example, here is an example if you would like to hide the real error to your visitors:
add_filter( 'mwai_ai_exception', function ( $exception ) {
try {
if ( substr( $exception, 0, 26 ) === "Error while calling OpenAI" ) {
error_log( $exception );
return "There was an AI system error. Please contact us.";
}
return $exception;
}
catch ( Exception $e ) {
error_log( $e->getMessage() );
}
return $exception;
} );