diff --git a/wp-content/plugins/vf-events/README.md b/wp-content/plugins/vf-events/README.md index 850b42eb4..24e4edcf7 100644 --- a/wp-content/plugins/vf-events/README.md +++ b/wp-content/plugins/vf-events/README.md @@ -63,12 +63,9 @@ The global options are: | vf_event_past_title | [TEXT] | | vf_events_per_page | [NUMBER] | | vf_events_enable_chatbot | [BOOLEAN] | -| vf_events_chatbot_routes_payload | [JSON TEXTAREA] | † If the date format is `custom` the custom text string is used. -The chatbot routes payload is stored directly in the Events settings page, refreshed automatically once a day, refreshed whenever an event is saved, and can also be refreshed manually with the button on that screen. - See the ACF JSON file for default values. ## Templates diff --git a/wp-content/plugins/vf-events/assets/qa.json b/wp-content/plugins/vf-events/assets/qa.json new file mode 100644 index 000000000..45c3c7957 --- /dev/null +++ b/wp-content/plugins/vf-events/assets/qa.json @@ -0,0 +1,36 @@ +{ + "predefinedQA": { + "How can I register?": { + "answer": "Answer 1 here" + }, + "Who is the contact person for this event?": { + "answer": "Answer 2 here" + }, + "Where is the event taking place?": { + "answer": "Answer 3 here", + "sources": [ + { + "domain": "ebi.ac.uk", + "title": "EMBL-EBI Training", + "url": "https://www.ebi.ac.uk/training/", + "description": "Delivering world-class training in data-driven life sciences." + } + ] + } + }, + "fallbackResponses": [ + { + "answer": "I'm sorry, I'm having trouble connecting to my knowledge base right now. Could you try again in a moment?", + "prompts": [ + { + "action_text": "Contact support team", + "action_url": "tel:+44 1223 494 444" + }, + { + "action_text": "Submit a support request", + "action_url": "https://www.ebi.ac.uk/about/contact/support/" + } + ] + } + ] +} diff --git a/wp-content/plugins/vf-events/assets/vf-events-chatbot.js b/wp-content/plugins/vf-events/assets/vf-events-chatbot.js index 87bdb8f3a..54b867bce 100644 --- a/wp-content/plugins/vf-events/assets/vf-events-chatbot.js +++ b/wp-content/plugins/vf-events/assets/vf-events-chatbot.js @@ -58,14 +58,6 @@ return selector ? selector.getAttribute("data-routes-path") : ""; } - function getRoutesPayloadElement() { - var selector = getSelectorElement(); - - return selector - ? selector.querySelector("[data-vf-js-events-chatbot-routes-payload]") - : null; - } - function getSelectorEmptyLabel() { var selector = getSelectorElement(); @@ -189,40 +181,11 @@ function loadEventRoutes() { var routesPath = getRoutesPath(); - var routesPayloadElement = getRoutesPayloadElement(); if (eventRoutesPromise) { return eventRoutesPromise; } - if (routesPayloadElement) { - eventRoutesPromise = Promise.resolve() - .then(function () { - var payloadText = routesPayloadElement.textContent || ""; - var parsedPayload = payloadText ? JSON.parse(payloadText) : { routes: [] }; - var routes = sortRoutesAlphabetically( - normalizeRoutesPayload(parsedPayload) - ); - - eventRoutesById = {}; - routes.forEach(function (route) { - if (route && route.id) { - eventRoutesById[route.id] = route; - } - }); - - return routes; - }) - .catch(function (error) { - console.error("Unable to parse inline event routes payload:", error); - eventRoutesById = {}; - eventRoutesPromise = null; - return []; - }); - - return eventRoutesPromise; - } - if (!routesPath) { return Promise.resolve([]); } diff --git a/wp-content/plugins/vf-events/includes/acf.php b/wp-content/plugins/vf-events/includes/acf.php index 517754796..e5d6a4274 100644 --- a/wp-content/plugins/vf-events/includes/acf.php +++ b/wp-content/plugins/vf-events/includes/acf.php @@ -53,14 +53,6 @@ function __construct($file) { 'acf/settings/load_json', array($this, 'acf_settings_load_json') ); - add_filter( - 'acf/prepare_field/name=vf_events_chatbot_routes_payload_actions', - array($this, 'acf_prepare_field_vf_events_chatbot_routes_payload_actions') - ); - add_action( - 'admin_post_vf_events_refresh_chatbot_routes', - array($this, 'handle_manual_chatbot_routes_refresh') - ); add_action( VF_Events::chatbot_routes_refresh_hook(), array($this, 'refresh_chatbot_routes_payload') @@ -209,35 +201,6 @@ public function acf_init() { 'ui_on_text' => __('Enabled', 'vfwp'), 'ui_off_text' => __('Disabled', 'vfwp'), ), - array( - 'key' => 'field_vf_events_chatbot_routes_payload', - 'label' => __('Chatbot routes payload', 'vfwp'), - 'name' => 'vf_events_chatbot_routes_payload', - 'type' => 'textarea', - 'instructions' => __( - 'Stored JSON payload used by the event chatbot selector. It is refreshed automatically once a day and whenever an event is saved.', - 'vfwp' - ), - 'required' => 0, - 'conditional_logic' => 0, - 'wrapper' => array( - 'width' => '', - 'class' => '', - 'id' => '', - ), - 'default_value' => '', - 'rows' => 18, - 'new_lines' => '', - ), - array( - 'key' => 'field_vf_events_chatbot_routes_payload_actions', - 'label' => __('Refresh chatbot routes payload', 'vfwp'), - 'name' => 'vf_events_chatbot_routes_payload_actions', - 'type' => 'message', - 'message' => '', - 'new_lines' => 'wpautop', - 'esc_html' => 0, - ), ), 'location' => array( array( @@ -422,40 +385,6 @@ public function rest_api_init() { )); } - /** - * Prepare the actions field for chatbot routes payload refresh. - */ - public function acf_prepare_field_vf_events_chatbot_routes_payload_actions($field) { - $refresh_url = wp_nonce_url( - admin_url('admin-post.php?action=vf_events_refresh_chatbot_routes'), - 'vf_events_refresh_chatbot_routes' - ); - $updated_at = VF_Events::get_chatbot_routes_updated_at(); - $status_message = $updated_at - ? sprintf( - __('Last refreshed: %s', 'vfwp'), - wp_date(get_option('date_format') . ' ' . get_option('time_format'), $updated_at) - ) - : __('The chatbot routes payload has not been generated yet.', 'vfwp'); - - if (isset($_GET['vf_events_chatbot_routes_refreshed'])) { - if ($_GET['vf_events_chatbot_routes_refreshed'] === '1') { - $status_message = __('The chatbot routes payload was refreshed successfully.', 'vfwp') . ' ' . $status_message; - } elseif ($_GET['vf_events_chatbot_routes_refreshed'] === '0') { - $status_message = __('The chatbot routes payload could not be refreshed.', 'vfwp') . ' ' . $status_message; - } - } - - $field['message'] = sprintf( - '
%1$s
', - esc_html($status_message), - esc_url($refresh_url), - esc_html__('Refresh now', 'vfwp') - ); - - return $field; - } - /** * Return the stored chatbot routes payload via REST. */ @@ -483,27 +412,6 @@ public function refresh_chatbot_routes_payload_on_save($post_id) { $this->refresh_chatbot_routes_payload(); } - /** - * Handle manual chatbot routes refresh from the Events settings page. - */ - public function handle_manual_chatbot_routes_refresh() { - if (!current_user_can('manage_options')) { - wp_die(__('You are not allowed to refresh chatbot routes.', 'vfwp')); - } - - check_admin_referer('vf_events_refresh_chatbot_routes'); - - $refreshed = $this->refresh_chatbot_routes_payload(); - $redirect_url = add_query_arg( - 'vf_events_chatbot_routes_refreshed', - $refreshed ? '1' : '0', - VF_Events::get_settings_url() - ); - - wp_safe_redirect($redirect_url); - exit; - } - /** * Filter: `acf/settings/load_json` */ diff --git a/wp-content/plugins/vf-events/templates/partials/chatbot.php b/wp-content/plugins/vf-events/templates/partials/chatbot.php index c433c6f9f..528e08b42 100644 --- a/wp-content/plugins/vf-events/templates/partials/chatbot.php +++ b/wp-content/plugins/vf-events/templates/partials/chatbot.php @@ -13,10 +13,7 @@ $chatbot_event_id = get_post_field('post_name', $chatbot_event_post_id); $chatbot_plugin_base_url = plugin_dir_url(dirname(dirname(dirname(__FILE__))) . '/vf-events.php'); $chatbot_asset_base = untrailingslashit(get_theme_file_uri('assets/assets/vf-chatbot/assets')); -$chatbot_asset_base_custom = untrailingslashit(get_template_directory_uri() . '/assets/assets/chatbot'); -$chatbot_routes_payload = class_exists('VF_Events') - ? VF_Events::get_chatbot_routes_payload() - : array('routes' => array()); +$chatbot_qa_data_url = $chatbot_plugin_base_url . 'assets/qa.json'; $chatbot_routes_url = class_exists('VF_Events') ? VF_Events::get_chatbot_routes_url() : rest_url('vf-events/v1/chatbot-routes'); @@ -103,7 +100,6 @@