-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathwp-autorag-chatbot.php
More file actions
104 lines (89 loc) · 2.75 KB
/
Copy pathwp-autorag-chatbot.php
File metadata and controls
104 lines (89 loc) · 2.75 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
<?php
/*
Plugin Name: WP Cloudflare AutoRAG Chatbot
Description: Adds a shortcode that renders a chatbot UI backed by Cloudflare AutoRAG. Includes a server-side proxy to avoid exposing your API token.
Version: 1.4.25
Author: neuno.ai
Author URI: https://neuno.ai
License: GPL-2.0-or-later
License URI: https://www.gnu.org/licenses/gpl-2.0.html
Text Domain: autorag-chatbot
Domain Path: /languages
*/
defined( 'ABSPATH' ) || exit;
define( 'AUTORAG_CB_DIR', plugin_dir_path( __FILE__ ) );
define( 'AUTORAG_CB_URL', plugin_dir_url( __FILE__ ) );
require_once AUTORAG_CB_DIR . 'settings.php';
require_once AUTORAG_CB_DIR . 'proxy.php';
/**
* Enqueue front‑end assets.
*/
function autorag_chatbot_enqueue_assets() {
wp_enqueue_style(
'autorag-chatbot-css',
AUTORAG_CB_URL . 'chatbot.css',
[],
'1.4.25'
);
wp_enqueue_script(
'autorag-md',
plugins_url( 'assets/markdown.bundle.min.js', __FILE__ ),
[],
'1.0',
true
);
wp_enqueue_script(
'autorag-renderer',
plugins_url( 'assets/autorag-renderer.js', __FILE__ ),
[ 'autorag-md' ],
'1.0',
true
);
wp_enqueue_script(
'autorag-chatbot-js',
AUTORAG_CB_URL . 'chatbot.js',
[],
'1.4.25',
true
);
wp_localize_script(
'autorag-chatbot-js',
'AutoRAGConfig',
[
'endpoint' => esc_url_raw( rest_url( 'autorag/v1/search' ) ),
'placeholder' => esc_html__( 'Ask a question…', 'autorag-chatbot' ),
]
);
}
add_action( 'wp_enqueue_scripts', 'autorag_chatbot_enqueue_assets' );
/**
* Shortcode that renders the chat UI.
*/
function autorag_chatbot_shortcode() {
$options = get_option( 'autorag_chatbot_settings', [] );
$accent = $options['accent_color'] ?? '#d96704';
ob_start(); ?>
<!-- ▼ style attribute injects the custom property -->
<div id="autorag-chatbot" style="--n-accent: <?php echo esc_attr( $accent ); ?>;">
<div class="chat-card">
<div id="chat-window"></div>
<div class="input-row">
<input type="text"
id="chat-input"
placeholder="<?php echo esc_attr__( 'Ask a question…', 'autorag-chatbot' ); ?>">
<button type="button" class="send-btn">Send</button>
</div>
</div>
</div>
<?php
return ob_get_clean();
}
add_shortcode( 'autorag_chatbot', 'autorag_chatbot_shortcode' );
/**
* Load translations.
*/
function autorag_chatbot_load_textdomain() {
load_plugin_textdomain( 'autorag-chatbot', false, dirname( plugin_basename( __FILE__ ) ) . '/languages/' );
}
add_action( 'plugins_loaded', 'autorag_chatbot_load_textdomain' );
?>