- Created a base mail template - Adapt and improve document API to usage of catalogs and processors - Adapt eveai_sync to new authentication mechanism and usage of catalogs and processors
129 lines
4.1 KiB
PHP
129 lines
4.1 KiB
PHP
<?php
|
|
class EveAI_Chat_Loader {
|
|
private $version;
|
|
|
|
public function __construct() {
|
|
$this->version = EVEAI_CHAT_VERSION;
|
|
$this->load_dependencies();
|
|
}
|
|
|
|
private function load_dependencies() {
|
|
// Load required files
|
|
require_once EVEAI_CHAT_PLUGIN_DIR . 'includes/class-eveai-api.php';
|
|
require_once EVEAI_CHAT_PLUGIN_DIR . 'includes/class-eveai-security.php';
|
|
|
|
// Load admin if in admin area
|
|
if (is_admin()) {
|
|
require_once EVEAI_CHAT_PLUGIN_DIR . 'admin/class-eveai-admin.php';
|
|
}
|
|
}
|
|
|
|
public function run() {
|
|
// Initialize components
|
|
$this->define_admin_hooks();
|
|
$this->define_public_hooks();
|
|
$this->define_shortcodes();
|
|
}
|
|
|
|
private function define_admin_hooks() {
|
|
if (is_admin()) {
|
|
$admin = new EveAI_Chat_Admin($this->version);
|
|
add_action('admin_menu', array($admin, 'add_plugin_admin_menu'));
|
|
add_action('admin_init', array($admin, 'register_settings'));
|
|
}
|
|
}
|
|
|
|
private function define_public_hooks() {
|
|
// Enqueue scripts and styles
|
|
add_action('wp_enqueue_scripts', array($this, 'enqueue_assets'));
|
|
|
|
// Register REST API endpoints
|
|
add_action('rest_api_init', array($this, 'register_rest_routes'));
|
|
}
|
|
|
|
private function define_shortcodes() {
|
|
add_shortcode('eveai_chat', array($this, 'render_chat_widget'));
|
|
}
|
|
|
|
public function enqueue_assets() {
|
|
// Enqueue required scripts
|
|
wp_enqueue_script('socket-io', 'https://cdn.socket.io/4.0.1/socket.io.min.js', array(), '4.0.1', true);
|
|
wp_enqueue_script('marked', 'https://cdn.jsdelivr.net/npm/marked/marked.min.js', array(), '1.0.0', true);
|
|
|
|
// Enqueue our scripts
|
|
wp_enqueue_script(
|
|
'eveai-sdk',
|
|
EVEAI_CHAT_PLUGIN_URL . 'public/js/eveai-sdk.js',
|
|
array('socket-io', 'marked'),
|
|
$this->version,
|
|
true
|
|
);
|
|
|
|
wp_enqueue_script(
|
|
'eveai-chat-widget',
|
|
EVEAI_CHAT_PLUGIN_URL . 'public/js/eveai-chat-widget.js',
|
|
array('eveai-sdk'),
|
|
$this->version,
|
|
true
|
|
);
|
|
|
|
// Enqueue styles
|
|
wp_enqueue_style('material-icons', 'https://fonts.googleapis.com/icon?family=Material+Icons');
|
|
wp_enqueue_style(
|
|
'eveai-chat-style',
|
|
EVEAI_CHAT_PLUGIN_URL . 'public/css/eveai-chat-style.css',
|
|
array(),
|
|
$this->version
|
|
);
|
|
|
|
// Add WordPress-specific configuration
|
|
wp_localize_script('eveai-sdk', 'eveaiWP', array(
|
|
'nonce' => wp_create_nonce('wp_rest'),
|
|
'ajaxUrl' => admin_url('admin-ajax.php'),
|
|
'restUrl' => rest_url('eveai/v1/')
|
|
));
|
|
}
|
|
|
|
public function register_rest_routes() {
|
|
$api = new EveAI_Chat_API();
|
|
$api->register_routes();
|
|
}
|
|
|
|
public function render_chat_widget($atts) {
|
|
$defaults = array(
|
|
'tenant_id' => '',
|
|
'language' => 'en',
|
|
'supported_languages' => 'en,fr,de,es',
|
|
'server_url' => 'https://evie.askeveai.com',
|
|
'specialist_id' => '1'
|
|
);
|
|
|
|
$atts = shortcode_atts($defaults, $atts, 'eveai_chat');
|
|
$chat_id = 'chat-container-' . uniqid();
|
|
|
|
return sprintf(
|
|
'<div id="%s"></div>
|
|
<script>
|
|
document.addEventListener("DOMContentLoaded", function() {
|
|
const eveAI = new EveAI({
|
|
tenantId: "%s",
|
|
language: "%s",
|
|
languages: "%s",
|
|
serverUrl: "%s",
|
|
specialistId: "%s",
|
|
proxyUrl: "%s"
|
|
});
|
|
eveAI.initializeChat("%s");
|
|
});
|
|
</script>',
|
|
$chat_id,
|
|
esc_js($atts['tenant_id']),
|
|
esc_js($atts['language']),
|
|
esc_js($atts['supported_languages']),
|
|
esc_js($atts['server_url']),
|
|
esc_js($atts['specialist_id']),
|
|
esc_js(rest_url('eveai/v1/session-token')),
|
|
esc_js($chat_id)
|
|
);
|
|
}
|
|
} |