68 lines
2.5 KiB
PHP
68 lines
2.5 KiB
PHP
<?php
|
|
/*
|
|
Plugin Name: EveAI Chat Widget
|
|
Plugin URI: https://askeveai.com/
|
|
Description: Integrates the EveAI chat interface into your WordPress site.
|
|
Version: 1.5.0
|
|
Author: Josako, Pieter Laroy
|
|
Author URI: https://askeveai.com/about/
|
|
*/
|
|
|
|
// Enqueue necessary scripts and styles
|
|
function eveai_chat_enqueue_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);
|
|
wp_enqueue_script('eveai-sdk', plugin_dir_url(__FILE__) . 'js/eveai-sdk.js', array(), '1.0.0', true);
|
|
wp_enqueue_script('eveai-chat-widget', plugin_dir_url(__FILE__) . 'js/eveai-chat-widget.js', array('eveai-sdk'), '1.0.0', true);
|
|
wp_enqueue_style('material-icons', 'https://fonts.googleapis.com/icon?family=Material+Icons');
|
|
wp_enqueue_style('eveai-chat-style', plugin_dir_url(__FILE__) . 'css/eveai-chat-style.css');
|
|
}
|
|
add_action('wp_enqueue_scripts', 'eveai_chat_enqueue_scripts');
|
|
add_action('admin_enqueue_scripts', 'eveai_chat_enqueue_scripts');
|
|
|
|
// Shortcode function
|
|
function eveai_chat_shortcode($atts) {
|
|
// Default values
|
|
$defaults = array(
|
|
'tenant_id' => '',
|
|
'api_key' => '',
|
|
'domain' => '',
|
|
'language' => 'en',
|
|
'supported_languages' => 'en,fr,de,es',
|
|
'server_url' => 'https://evie.askeveai.com'
|
|
);
|
|
|
|
// Merge provided attributes with defaults
|
|
$atts = shortcode_atts($defaults, $atts, 'eveai_chat');
|
|
|
|
// Sanitize inputs
|
|
$tenant_id = sanitize_text_field($atts['tenant_id']);
|
|
$api_key = sanitize_text_field($atts['api_key']);
|
|
$domain = esc_url_raw($atts['domain']);
|
|
$language = sanitize_text_field($atts['language']);
|
|
$supported_languages = sanitize_text_field($atts['supported_languages']);
|
|
$server_url = esc_url_raw($atts['server_url']);
|
|
|
|
// Generate a unique ID for this instance of the chat widget
|
|
$chat_id = 'chat-container-' . uniqid();
|
|
|
|
$output = "<div id='$chat_id'></div>";
|
|
$output .= "<script>
|
|
document.addEventListener('DOMContentLoaded', function() {
|
|
const eveAI = new EveAI(
|
|
'$tenant_id',
|
|
'$api_key',
|
|
'$domain',
|
|
'$language',
|
|
'$supported_languages',
|
|
'$server_url'
|
|
);
|
|
eveAI.initializeChat('$chat_id');
|
|
});
|
|
</script>";
|
|
|
|
return $output;
|
|
}
|
|
add_shortcode('eveai_chat', 'eveai_chat_shortcode');
|
|
|