PluginProbe
WPBot – AI ChatBot for Live Support, Lead Generation, WordPress Automation, AI Services / 8.7.8
WPBot – AI ChatBot for Live Support, Lead Generation, WordPress Automation, AI Services v8.7.8
8.7.8 8.7.7 8.7.6 8.7.5 8.7.4 8.7.3 8.7.2 8.7.1 8.7.0 8.6.9 8.6.8 8.6.7 8.6.6 8.6.5 8.6.4 8.6.2 8.6.1 8.6.0 8.5.9 8.5.8 8.5.7 8.5.6 8.5.5 8.5.4 8.5.3 All 534 releases
chatbot / addons / automator / wpbot-automator.php

wpbot-automator.php in WPBot – AI ChatBot for Live Support, Lead Generation, WordPress Automation, AI Services 8.7.8, at addons/automator/wpbot-automator.php

227 lines 7.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Plugin Name: WPBot- Automator
4 * Plugin URI: https://www.wpbot.pro/
5 * Description: A powerful automation plugin for WordPress with a visual no-code builder.
6 * Version: 1.3.1
7 * Author: QuantumCloud
8 * Author URI: https://www.wpbot.pro/
9 * Text Domain: wpbot-automator
10 * Domain Path: /languages
11 * Requires at least: 5.8
12 * Requires PHP: 7.4
13 * License: GPLv2 or later
14 */
15
16 namespace WPbot_Automator;
17
18 if ( ! defined( 'ABSPATH' ) ) {
19 exit; // Exit if accessed directly.
20 }
21
22 // Check if the standalone WPBot Automator plugin is active to prevent fatal errors from redeclaration.
23 if ( ! function_exists( 'is_plugin_active' ) ) {
24 require_once ABSPATH . 'wp-admin/includes/plugin.php';
25 }
26 if ( is_plugin_active( 'wpbot/wpbot-automator.php' ) ) {
27 return; // Abort loading the addon. The standalone plugin will load instead.
28 }
29
30 // Define Constants.
31 if ( ! defined( 'WPBOT_AUTOMATOR_VERSION' ) ) {
32 define( 'WPBOT_AUTOMATOR_VERSION', '1.3.1' );
33 }
34 if ( ! defined( 'WPBOT_AUTOMATOR_PLUGIN_DIR' ) ) {
35 define( 'WPBOT_AUTOMATOR_PLUGIN_DIR', plugin_dir_path( __FILE__ ) );
36 }
37 if ( ! defined( 'WPBOT_AUTOMATOR_PLUGIN_URL' ) ) {
38 define( 'WPBOT_AUTOMATOR_PLUGIN_URL', plugin_dir_url( __FILE__ ) );
39 }
40
41 // Include Autoloader.
42 require_once WPBOT_AUTOMATOR_PLUGIN_DIR . 'includes/autoloader.php';
43
44 use WPbot_Automator\Autoloader;
45
46 if ( ! class_exists( 'WPbot_Automator\WPbot_Automator' ) ) {
47 /**
48 * Main Plugin Class
49 */
50 class WPbot_Automator {
51
52 /**
53 * Instance of this class
54 *
55 * @var WPbot_Automator|null
56 */
57 private static $instance = null;
58
59 /**
60 * Get the instance of the class
61 */
62 public static function get_instance() {
63 if ( null === self::$instance ) {
64 self::$instance = new self();
65 }
66 return self::$instance;
67 }
68
69 /**
70 * Constructor
71 */
72 public function __construct() {
73 $this->define_constants();
74
75 // Run Autoloader.
76 Autoloader::run();
77
78 $this->init_hooks();
79
80 // Initialize the Core Plugin logic.
81 Core\Plugin::init();
82 }
83
84 /**
85 * Define constants
86 */
87 private function define_constants() {
88 // Constants already defined at file level for simplicity in some contexts,
89 // but typically we can put more here if needed.
90 }
91
92 /**
93 * Initialize Hooks
94 */
95 private function init_hooks() {
96 // As an addon, we use admin_init to check and run installation
97 add_action( 'admin_init', array( $this, 'maybe_install' ) );
98 }
99
100 public function maybe_install() {
101 $installed_version = get_option( 'wpbot_automator_version' );
102 if ( $installed_version !== WPBOT_AUTOMATOR_VERSION ) {
103 Core\Database::install();
104 Core\Default_Workflows::install();
105 update_option( 'wpbot_automator_version', WPBOT_AUTOMATOR_VERSION );
106 }
107 }
108 }
109 }
110
111 /**
112 * Initialize the plugin
113 */
114 if(!function_exists(__NAMESPACE__ . '\wpbot_automator_init')) {
115 function wpbot_automator_init() {
116 return WPbot_Automator::get_instance();
117 }
118 }
119
120 add_action('admin_init', function() {
121 if (isset($_GET['install_cf_workflow'])) {
122 global $wpdb;
123 $table = $wpdb->prefix . 'wpbot_automator_workflows';
124
125 $workflow = array(
126 'name' => 'Conversational Form to Sheet, AI & Email',
127 'description' => 'Saves conversational form data to Google Sheets, generates an AI summary, and emails the response.',
128 'workflow_data' => array(
129 'nodes' => array(
130 array(
131 'id' => 'trigger-1',
132 'type' => 'trigger',
133 'position' => array('x' => 100, 'y' => 100),
134 'data' => array(
135 'appId' => 'wpbot',
136 'actionId' => 'conversationalforms_submit',
137 'label' => 'Conversational Forms Submitted',
138 ),
139 ),
140 array(
141 'id' => 'action-1',
142 'type' => 'action',
143 'position' => array('x' => 400, 'y' => 100),
144 'data' => array(
145 'appId' => 'google_sheets',
146 'actionId' => 'gs_add_row',
147 'label' => 'Add row to Google Sheet',
148 'config' => array(
149 'spreadsheet_id' => 'your_google_sheet_id_here',
150 'sheet_name' => 'Sheet1',
151 'row_data' => array(
152 '{{wpbot.conversationalforms_submit.name}}',
153 '{{wpbot.conversationalforms_submit.email}}',
154 ),
155 ),
156 ),
157 ),
158 array(
159 'id' => 'action-2',
160 'type' => 'action',
161 'position' => array('x' => 700, 'y' => 100),
162 'data' => array(
163 'appId' => 'openai',
164 'actionId' => 'chat_completion',
165 'label' => 'Generate Summary',
166 'config' => array(
167 'model' => 'gpt-4o-mini',
168 'prompt' => "Summarize the following form submission: Name: {{wpbot.conversationalforms_submit.name}}, Email: {{wpbot.conversationalforms_submit.email}}",
169 'max_tokens' => '150',
170 'temperature' => '0.7',
171 ),
172 ),
173 ),
174 array(
175 'id' => 'action-3',
176 'type' => 'action',
177 'position' => array('x' => 1000, 'y' => 100),
178 'data' => array(
179 'appId' => 'mail',
180 'actionId' => 'send_email',
181 'label' => 'Send Email Response',
182 'config' => array(
183 'to_email' => '{{wpbot.conversationalforms_submit.email}}',
184 'subject' => 'Thank you for your submission',
185 'body' => "Hello {{wpbot.conversationalforms_submit.name}},\n\nHere is a summary of your submission:\n{{openai.chat_completion.response}}",
186 'is_html' => false,
187 ),
188 ),
189 ),
190 ),
191 'connections' => array(
192 array('id' => 'conn-1', 'source' => 'trigger-1', 'target' => 'action-1'),
193 array('id' => 'conn-2', 'source' => 'action-1', 'target' => 'action-2'),
194 array('id' => 'conn-3', 'source' => 'action-2', 'target' => 'action-3'),
195 ),
196 ),
197 );
198
199 $exists = $wpdb->get_var($wpdb->prepare("SELECT id FROM {$table} WHERE name = %s", $workflow['name']));
200 if (!$exists) {
201 $wpdb->insert(
202 $table,
203 array(
204 'name' => $workflow['name'],
205 'description' => $workflow['description'],
206 'workflow_data' => wp_json_encode($workflow['workflow_data']),
207 'status' => 'active',
208 ),
209 array('%s', '%s', '%s', '%s')
210 );
211 } else {
212 $wpdb->update(
213 $table,
214 array(
215 'description' => $workflow['description'],
216 'workflow_data' => wp_json_encode($workflow['workflow_data']),
217 ),
218 array('id' => $exists),
219 array('%s', '%s'),
220 array('%d')
221 );
222 }
223 }
224 });
225
226 wpbot_automator_init();
227