$cid], $public_key); if (is_wp_error($encrypted_data)) { $slack_integration = false; } else { if (!function_exists('abmsense_get_api_request_args')) { require_once(plugin_dir_path(__FILE__) . 'utility.php'); } $args = abmsense_get_api_request_args(wp_json_encode($encrypted_data)); $response = abmsense_safe_api_request($config['get_abmsense_slack_integration'], $args); if (is_wp_error($response)) { $slack_integration = false; } else { $raw_body = wp_remote_retrieve_body($response); $status_code = wp_remote_retrieve_response_code($response); $body = json_decode($raw_body, true); $slack_integration = ($body && isset($body['success']) && $body['success']) ? (object)$body['data'] : false; if (!$slack_integration) { abmsense_log('No current Slack integration exists for CID: ' . $cid, 'warning'); } } } ?>

BETA

How to Connect Slack and Receive Hot Lead Alerts:
  • Add a channel in your Slack workspace where you want to receive notifications (e.g., #abmsense_alerts).
  • Add your bot-user to the channel (e.g., /invite @your-bot).
  • Click the "Connect Slack" button below.
  • Fill in the required details from your Slack App settings (Bot Token and Signing Secret).
  • Select the channel from the list or enter its name (e.g., #abmsense_alerts).
  • Save the integration. You're done!

Slack Integration

Get Notified on Slack When ABMsense Identifies a Hot Lead.

is_active) && !$slack_integration->is_active) { // Disabled state ?>
Disabled
Connected
default_channel)): ?>
Channel: default_channel_name) ? '#' . esc_html($slack_integration->default_channel_name) : esc_html($slack_integration->default_channel); ?>
Not Connected
admin_url('admin-ajax.php'), 'nonce' => wp_create_nonce('abmsense_slack_nonce') )); } } add_action('admin_enqueue_scripts', 'abmsense_integrations_admin_scripts'); // AJAX handlers for Slack integration function abmsense_save_slack_config() { check_ajax_referer('abmsense_slack_nonce', 'nonce'); if (!current_user_can('manage_options')) { abmsense_log('Permission denied for saving Slack configuration', 'error'); wp_send_json_error(['message' => 'Permission denied']); } $customer_id = get_current_user_id(); $customer_details = abmsense_get_customer_details($customer_id); if (!$customer_details) { abmsense_log('Customer details not found for user ID: ' . $customer_id, 'error'); wp_send_json_error(['message' => 'Customer details not found']); } $cid = $customer_details['cid']; abmsense_log('Attempting to save Slack configuration for CID: ' . $cid, 'info'); // Get API configuration $config = require(plugin_dir_path(__FILE__) . 'db_config.php'); // Prepare and encrypt data for API if (!function_exists('abmsense_encrypt_data')) { require_once(plugin_dir_path(__FILE__) . 'utility.php'); } $public_key = $config['public_key']; $to_encrypt = [ 'cid' => $cid, 'slack_bot_token' => sanitize_text_field($_POST['bot_token']), 'signing_secret' => sanitize_text_field($_POST['signing_secret']), 'default_channel' => sanitize_text_field($_POST['default_channel']) ]; if (!empty($_POST['default_channel_name'])) { $to_encrypt['default_channel_name'] = sanitize_text_field($_POST['default_channel_name']); } $encrypted_data = abmsense_encrypt_data($to_encrypt, $public_key); if (is_wp_error($encrypted_data)) { abmsense_log('Encryption failed: ' . $encrypted_data->get_error_message(), 'error'); wp_send_json_error(['message' => $encrypted_data->get_error_message()]); } // Send request to our API gateway $args = abmsense_get_api_request_args(wp_json_encode($encrypted_data)); $response = abmsense_safe_api_request($config['upsert_abmsense_slack_integration'], $args); if (is_wp_error($response)) { abmsense_log('API Gateway error while saving Slack config: ' . $response->get_error_message(), 'error'); wp_send_json_error(['message' => 'Failed to connect to API gateway']); } $raw_body = wp_remote_retrieve_body($response); $status_code = wp_remote_retrieve_response_code($response); $body = json_decode($raw_body, true); if (!$body || !isset($body['success']) || !$body['success']) { $error_message = isset($body['error']) ? $body['error'] : ($body['message'] ?? 'Failed to save configuration'); abmsense_log('Failed to save Slack configuration. API Response: ' . json_encode($body), 'error'); wp_send_json_error(['message' => $error_message]); } abmsense_log('Successfully saved Slack configuration for CID: ' . $cid, 'success'); wp_send_json_success(); } add_action('wp_ajax_abmsense_save_slack_config', 'abmsense_save_slack_config'); function abmsense_get_slack_config() { check_ajax_referer('abmsense_slack_nonce', 'nonce'); if (!current_user_can('manage_options')) { wp_send_json_error(['message' => 'Permission denied']); } $customer_id = get_current_user_id(); $customer_details = abmsense_get_customer_details($customer_id); if (!$customer_details) { wp_send_json_error(['message' => 'Customer details not found']); } $cid = $customer_details['cid']; // Get API configuration $config = require(plugin_dir_path(__FILE__) . 'db_config.php'); if (!function_exists('abmsense_encrypt_data')) { require_once(plugin_dir_path(__FILE__) . 'utility.php'); } $public_key = $config['public_key']; $encrypted_data = abmsense_encrypt_data(['cid' => $cid], $public_key); if (is_wp_error($encrypted_data)) { wp_send_json_error(['message' => $encrypted_data->get_error_message()]); } if (!function_exists('abmsense_get_api_request_args')) { require_once(plugin_dir_path(__FILE__) . 'utility.php'); } $args = abmsense_get_api_request_args(wp_json_encode($encrypted_data)); $response = abmsense_safe_api_request($config['get_abmsense_slack_integration'], $args); if (is_wp_error($response)) { wp_send_json_error(['message' => 'Failed to connect to API gateway']); } $body = json_decode(wp_remote_retrieve_body($response), true); if (!$body || !isset($body['success']) || !$body['success']) { wp_send_json_error(['message' => $body['message'] ?? 'No configuration found']); } wp_send_json_success([ 'bot_token' => $body['data']['slack_bot_token'], 'signing_secret' => $body['data']['signing_secret'], 'default_channel' => $body['data']['default_channel'], 'default_channel_name' => isset($body['data']['default_channel_name']) ? $body['data']['default_channel_name'] : '' ]); } add_action('wp_ajax_abmsense_get_slack_config', 'abmsense_get_slack_config'); function abmsense_disable_slack() { check_ajax_referer('abmsense_slack_nonce', 'nonce'); if (!current_user_can('manage_options')) { abmsense_log('Permission denied for disabling Slack integration', 'error'); wp_send_json_error(['message' => 'Permission denied']); } $customer_id = get_current_user_id(); $customer_details = abmsense_get_customer_details($customer_id); if (!$customer_details) { abmsense_log('Customer details not found for user ID: ' . $customer_id, 'error'); wp_send_json_error(['message' => 'Customer details not found']); } $cid = $customer_details['cid']; abmsense_log('Attempting to disable Slack integration for CID: ' . $cid, 'info'); // Get API configuration $config = require(plugin_dir_path(__FILE__) . 'db_config.php'); // Prepare and encrypt data for API if (!function_exists('abmsense_encrypt_data')) { require_once(plugin_dir_path(__FILE__) . 'utility.php'); } $public_key = $config['public_key']; $to_encrypt = ['cid' => $cid]; $encrypted_data = abmsense_encrypt_data($to_encrypt, $public_key); if (is_wp_error($encrypted_data)) { abmsense_log('Encryption failed: ' . $encrypted_data->get_error_message(), 'error'); wp_send_json_error(['message' => $encrypted_data->get_error_message()]); } // Send request to our API gateway $args = abmsense_get_api_request_args(wp_json_encode($encrypted_data)); $response = abmsense_safe_api_request($config['disable_abmsense_slack_integration'], $args); if (is_wp_error($response)) { abmsense_log('API Gateway error while disabling Slack: ' . $response->get_error_message(), 'error'); wp_send_json_error(['message' => 'Failed to connect to API gateway']); } $raw_body = wp_remote_retrieve_body($response); $status_code = wp_remote_retrieve_response_code($response); $body = json_decode($raw_body, true); if (!$body || !isset($body['success']) || !$body['success']) { $error_message = isset($body['error']) ? $body['error'] : ($body['message'] ?? 'Failed to disable Slack'); abmsense_log('Failed to disable Slack integration. API Response: ' . json_encode($body), 'error'); wp_send_json_error(['message' => $error_message]); } abmsense_log('Successfully disabled Slack integration for CID: ' . $cid, 'success'); wp_send_json_success(); } add_action('wp_ajax_abmsense_disable_slack', 'abmsense_disable_slack'); function abmsense_delete_slack() { check_ajax_referer('abmsense_slack_nonce', 'nonce'); if (!current_user_can('manage_options')) { abmsense_log('Permission denied for deleting Slack integration', 'error'); wp_send_json_error(['message' => 'Permission denied']); } $customer_id = get_current_user_id(); $customer_details = abmsense_get_customer_details($customer_id); if (!$customer_details) { abmsense_log('Customer details not found for user ID: ' . $customer_id, 'error'); wp_send_json_error(['message' => 'Customer details not found']); } $cid = $customer_details['cid']; abmsense_log('Attempting to delete Slack integration for CID: ' . $cid, 'info'); // Get API configuration $config = require(plugin_dir_path(__FILE__) . 'db_config.php'); // Prepare and encrypt data for API if (!function_exists('abmsense_encrypt_data')) { require_once(plugin_dir_path(__FILE__) . 'utility.php'); } $public_key = $config['public_key']; $to_encrypt = ['cid' => $cid]; $encrypted_data = abmsense_encrypt_data($to_encrypt, $public_key); if (is_wp_error($encrypted_data)) { abmsense_log('Encryption failed: ' . $encrypted_data->get_error_message(), 'error'); wp_send_json_error(['message' => $encrypted_data->get_error_message()]); } // Use the same helper as disable/enable if (!function_exists('abmsense_get_api_request_args')) { require_once(plugin_dir_path(__FILE__) . 'utility.php'); } $args = abmsense_get_api_request_args(wp_json_encode($encrypted_data)); $response = abmsense_safe_api_request($config['delete_abmsense_slack_integration'], $args); if (is_wp_error($response)) { abmsense_log('API Gateway error while deleting Slack: ' . $response->get_error_message(), 'error'); wp_send_json_error(['message' => 'Failed to connect to API gateway']); } $body = json_decode(wp_remote_retrieve_body($response), true); if (!$body['success']) { abmsense_log('Failed to delete Slack integration. API Response: ' . json_encode($body), 'error'); wp_send_json_error(['message' => $body['message'] ?? 'Failed to delete Slack']); } abmsense_log('Successfully deleted Slack integration for CID: ' . $cid, 'success'); wp_send_json_success(); } add_action('wp_ajax_abmsense_delete_slack', 'abmsense_delete_slack'); function abmsense_get_customer_details($user_id) { // Get the customer name (domain) for the current site $customer_name = get_option(ABMSENSE_PREFIX . 'customer_name', sanitize_text_field(wp_unslash($_SERVER['SERVER_NAME'] ?? ''))); if (empty($customer_name)) { abmsense_log('Customer name not found for user ID: ' . $user_id, 'error'); return false; } // Get API configuration $config = require(plugin_dir_path(__FILE__) . 'db_config.php'); $public_key = $config['public_key']; // Prepare and encrypt data for API if (!function_exists('abmsense_encrypt_data')) { require_once(plugin_dir_path(__FILE__) . 'utility.php'); } $encrypted_data = abmsense_encrypt_data(['customer_name' => $customer_name], $public_key); if (is_wp_error($encrypted_data)) { abmsense_log('Encryption failed: ' . $encrypted_data->get_error_message(), 'error'); return false; } // Prepare request args using the same helper as notifications.php if (!function_exists('abmsense_get_api_request_args')) { require_once(plugin_dir_path(__FILE__) . 'utility.php'); } $args = abmsense_get_api_request_args(wp_json_encode($encrypted_data)); // Use the safe API request wrapper $response = abmsense_safe_api_request($config['get_customer_cid'], $args); if (is_wp_error($response)) { abmsense_log('API Gateway error while getting customer details: ' . $response->get_error_message(), 'error'); return false; } $body = json_decode(wp_remote_retrieve_body($response), true); if (!$body || !isset($body['success']) || !$body['success']) { abmsense_log('Failed to get customer details. API Response: ' . json_encode($body), 'error'); return false; } return array( 'cid' => $body['data']['cid'], 'customer_name' => $customer_name, 'real_time_alert' => $body['data']['real_time_alert'], 'alert_status' => $body['data']['alert_status'] ); } function abmsense_integrations_admin_styles($hook) { if ($hook === 'abmsense_page_abmsense-integrations') { wp_enqueue_style('abmsense-integrations', plugin_dir_url(__FILE__) . 'css/integrations.css'); } } add_action('admin_enqueue_scripts', 'abmsense_integrations_admin_styles'); function abmsense_get_slack_channels() { check_ajax_referer('abmsense_slack_nonce', 'nonce'); if (!current_user_can('manage_options')) { abmsense_log('Permission denied for fetching Slack channels', 'error'); wp_send_json_error(['message' => 'Permission denied']); } $customer_id = get_current_user_id(); $customer_details = abmsense_get_customer_details($customer_id); if (!$customer_details) { abmsense_log('Customer details not found for user ID: ' . $customer_id, 'error'); wp_send_json_error(['message' => 'Customer details not found']); } $cid = $customer_details['cid']; $bot_token = sanitize_text_field($_POST['bot_token']); if (empty($bot_token)) { wp_send_json_error(['message' => 'Bot token is required']); } // Get API configuration $config = require(plugin_dir_path(__FILE__) . 'db_config.php'); // Prepare and encrypt data for API if (!function_exists('abmsense_encrypt_data')) { require_once(plugin_dir_path(__FILE__) . 'utility.php'); } $public_key = $config['public_key']; $to_encrypt = [ 'cid' => $cid, 'slack_bot_token' => $bot_token ]; $encrypted_data = abmsense_encrypt_data($to_encrypt, $public_key); if (is_wp_error($encrypted_data)) { abmsense_log('Encryption failed: ' . $encrypted_data->get_error_message(), 'error'); wp_send_json_error(['message' => $encrypted_data->get_error_message()]); } // Send request to our API gateway $args = abmsense_get_api_request_args(wp_json_encode($encrypted_data)); $response = abmsense_safe_api_request($config['get_slack_channels'], $args); if (is_wp_error($response)) { abmsense_log('API Gateway error while fetching channels: ' . $response->get_error_message(), 'error'); wp_send_json_error(['message' => 'Failed to connect to API gateway']); } $raw_body = wp_remote_retrieve_body($response); $status_code = wp_remote_retrieve_response_code($response); $body = json_decode($raw_body, true); if (!$body || !isset($body['success']) || !$body['success']) { $error_message = isset($body['error']) ? $body['error'] : ($body['message'] ?? 'Failed to fetch channels'); abmsense_log('Failed to fetch Slack channels. API Response: ' . json_encode($body), 'error'); wp_send_json_error(['message' => $error_message]); } wp_send_json_success(['channels' => $body['data']['channels']]); } add_action('wp_ajax_abmsense_get_slack_channels', 'abmsense_get_slack_channels'); // Add AJAX handler for enabling Slack integration function abmsense_enable_slack() { check_ajax_referer('abmsense_slack_nonce', 'nonce'); if (!current_user_can('manage_options')) { abmsense_log('Permission denied for enabling Slack integration', 'error'); wp_send_json_error(['message' => 'Permission denied']); } $customer_id = get_current_user_id(); $customer_details = abmsense_get_customer_details($customer_id); if (!$customer_details) { abmsense_log('Customer details not found for user ID: ' . $customer_id, 'error'); wp_send_json_error(['message' => 'Customer details not found']); } $cid = $customer_details['cid']; abmsense_log('Attempting to enable Slack integration for CID: ' . $cid, 'info'); // Get API configuration $config = require(plugin_dir_path(__FILE__) . 'db_config.php'); // Prepare and encrypt data for API if (!function_exists('abmsense_encrypt_data')) { require_once(plugin_dir_path(__FILE__) . 'utility.php'); } $public_key = $config['public_key']; $to_encrypt = ['cid' => $cid]; $encrypted_data = abmsense_encrypt_data($to_encrypt, $public_key); if (is_wp_error($encrypted_data)) { abmsense_log('Encryption failed: ' . $encrypted_data->get_error_message(), 'error'); wp_send_json_error(['message' => $encrypted_data->get_error_message()]); } // Send request to our API gateway $args = abmsense_get_api_request_args(wp_json_encode($encrypted_data)); $response = abmsense_safe_api_request($config['enable_abmsense_slack_integration'], $args); if (is_wp_error($response)) { abmsense_log('API Gateway error while enabling Slack: ' . $response->get_error_message(), 'error'); wp_send_json_error(['message' => 'Failed to connect to API gateway']); } $raw_body = wp_remote_retrieve_body($response); $status_code = wp_remote_retrieve_response_code($response); $body = json_decode($raw_body, true); if (!$body || !isset($body['success']) || !$body['success']) { $error_message = isset($body['error']) ? $body['error'] : ($body['message'] ?? 'Failed to enable Slack'); abmsense_log('Failed to enable Slack integration. API Response: ' . json_encode($body), 'error'); wp_send_json_error(['message' => $error_message]); } abmsense_log('Successfully enabled Slack integration for CID: ' . $cid, 'success'); wp_send_json_success(); } add_action('wp_ajax_abmsense_enable_slack', 'abmsense_enable_slack');