prefix . 'userdetails'; $sql = "DROP TABLE IF EXISTS $table_name;"; $wpdb->query($sql); $rootpath = home_url(); } //removing the ana script when a new script has been updated function anacbt_removeScript($a) { $files = glob($a . '*.js'); foreach ($files as $file) { if (is_file($file)) { unlink($file); } } } // registering the ana-script with the wordpress page function anacbt_registerScript() { $temp_path = wp_upload_dir(); $uploadpath = trailingslashit($temp_path['baseurl']); ini_set('allow_url_fopen', '1'); $botstatus = ""; global $wpdb; $table_name = $wpdb->prefix . 'userdetails'; $results = $wpdb->get_results("SELECT * FROM $table_name"); if (!empty($results)) { foreach ($results as $row) { $botstatus = $row->botApply; } } if ($botstatus == "home page") { if (is_front_page()) { wp_register_script('ana-script', $uploadpath . 'ANA/ANAFiles/script.js', array(), false, true); wp_enqueue_script('ana-script'); } } else { wp_register_script('ana-script', $uploadpath . 'ANA/ANAFiles/script.js', array(), false, true); wp_enqueue_script('ana-script'); } } // removing all the ana project files when new file is uploaded function anacbt_remove_files($a, $filename) { $files = glob($a . '*.anaproj'); foreach ($files as $file) { if (is_file($file) && $file != $filename) { unlink($file); } } $files = glob($a . '*.js'); foreach ($files as $file) { if (is_file($file) && $file != $filename) { unlink($file); } } } // removing the old logo when a new one id uploaded function anacbt_remove_images($a) { $imgfiles = glob($a . '*.jpg'); foreach ($imgfiles as $file) { if (is_file($file)) { unlink($file); } } $imgfiles = glob($a . '*.png'); foreach ($imgfiles as $file) { if (is_file($file)) { unlink($file); } } } // Performing all the prerequisite operation on activation function anacbt_onActivate() { $temp_path = wp_upload_dir(); $uploadpath = trailingslashit($temp_path['basedir']); if (!is_dir($uploadpath . "ANA")) { wp_mkdir_p($uploadpath . "ANA"); } if (!is_dir($uploadpath . "ANA/ANAFiles/")) { wp_mkdir_p($uploadpath . "ANA/ANAFiles/"); } else { $uploaddir = $uploadpath . "ANA/ANAFiles/"; anacbt_remove_files($uploaddir, "sample.anaproj"); } if (!is_dir($uploadpath . "ANA/ANAUploads/")) { wp_mkdir_p($uploadpath . "ANA/ANAUploads/"); } else { $uploaddir = $uploadpath . "ANA/ANAUploads/"; anacbt_remove_files($uploaddir, "sample.anaproj"); anacbt_remove_images($uploaddir); } $samplelogolocation = plugins_url("/ANA/ANAUploads", __FILE__); $sampleflowlocation = plugins_url("/ANA/ANAUploads", __FILE__); if (copy($samplelogolocation . "/ana.png", $uploadpath . "ANA/ANAUploads/ana.png")) { $test = 1; } else { return "error"; } //$remote_file_url = 'https://cdn.ana.chat/wordpress-plugin/sample_flow.anaproj'; if (copy($sampleflowlocation . "/sample.anaproj", $uploadpath . "ANA/ANAUploads/sample.anaproj")) { $test = 1; } else { return "error"; } $temp_path = wp_upload_dir(); $uploadpath = trailingslashit($temp_path['baseurl']); $logoname = "ana.png"; $agentName = "Ana"; $color = "#8cc83c"; $seconds = "3"; $logopath = $uploadpath . 'ANA/ANAUploads/ana.png'; $fileurl = "sample.anaproj"; $projfilepath = $uploadpath . 'ANA/ANAUploads/sample.anaproj'; $imgName = "ana.png"; global $wpdb; $table_name = $wpdb->prefix . 'userdetails'; $charset_collate = $wpdb->get_charset_collate(); $sql = "CREATE TABLE $table_name ( id mediumint(9) NOT NULL AUTO_INCREMENT, time datetime DEFAULT '0000-00-00 00:00:00' NOT NULL, businessId varchar(50) NOT NULL, color varchar(50) NOT NULL, botApply varchar(50) NOT NULL, seconds mediumint(9) NOT NULL, logoUrl varchar(100) DEFAULT '' NOT NULL, fileUrl varchar(100) DEFAULT '' NOT NULL, modifiedLogoUrl varchar(100) DEFAULT '' NOT NULL, modifiedFileUrl varchar(100) DEFAULT '' NOT NULL, PRIMARY KEY (id) ) $charset_collate;"; require_once ABSPATH . 'wp-admin/includes/upgrade.php'; dbDelta($sql); $wpdb->insert( $table_name, array( 'time' => current_time('mysql'), 'businessId' => $agentName, 'color' => $color, 'botApply' => "all pages", 'logoUrl' => $imgName, 'seconds' => $seconds, 'fileUrl' => $fileurl, 'modifiedFileUrl' => $fileurl, 'modifiedLogoUrl' => $imgName, ) ); $response = $wpdb->print_error(); $fullpath = plugins_url("/ANA/ANAFiles/dist/assets/embed/ana-web-chat-plugin.js", __FILE__); $indexpath = plugins_url("/ANA/ANAFiles/dist/index.html", __FILE__); $seconds = 5; $color = "#8cc83c"; $agentName = "Ana-bot"; $logopath = $uploadpath . 'ANA/ANAUploads/ana.png'; $projfilepath = $uploadpath . 'ANA/ANAUploads/sample.anaproj'; anacbt_generateScript($fullpath, $color, $logopath, $agentName, $indexpath, $projfilepath, $seconds); wp_register_script('ana-script', $uploadpath . 'ANA/ANAFiles/script.js', array(), false, true); wp_enqueue_script('ana-script'); } //Ana files uplaoding for the chatbot function anacbt_fileUpload() { $path = plugin_dir_path(__FILE__); $temp_path = wp_upload_dir(); $uploadpath = trailingslashit($temp_path['basedir']); $uploadscript = trailingslashit($temp_path['baseurl']); global $wpdb; $table_name = $wpdb->prefix . 'userdetails'; $results = $wpdb->get_row("SELECT * FROM $table_name WHERE id=1"); $scriptpath = $uploadscript . 'ANA/ANAFiles/script.js'; $rootpath1 = home_url(); $rootpath = dirname(__FILE__, 2); $fullpath = plugins_url("ANA/ANAFiles/dist/assets/embed/ana-web-chat-plugin.js", __FILE__); $indexpath = plugins_url("ANA/ANAFiles/dist/index.html", __FILE__); if (!empty($_POST['businessId'])) { $agentName = sanitize_text_field($_POST['businessId']); } else if (!empty($results->businessId)) { $agentName = $results->businessId; } else { $agentName = "Ana-bot"; } if (!empty($_POST['openSeconds'])) { $seconds = sanitize_text_field($_POST['openSeconds']); } else if (!empty($results->businessId)) { $seconds = $results->seconds; } else { $seconds = 0; } if (empty($_POST['secondsbox'])) { $seconds = 0; } $uploadOk = 1; $uploadImgOk = 1; if (empty($_POST['botapply'])) { $_POST['botapply'] = "all pages"; } if (!empty($_POST['color'])) { $color = sanitize_hex_color($_POST['color']); } else { $color = "#8cc83c"; } //for uploading the ana logo $imgName = "ana.png"; $uploaddir = $uploadpath . "ANA/ANAUploads/"; if (!empty($_FILES['logo']['name'])) { $imgName = sanitize_file_name($_FILES['logo']['name']); $imgTemp = explode('.', $imgName); if ((end($imgTemp) == 'jpg' || end($imgTemp) == 'png' || end($imgTemp) == 'jpeg') && ($_FILES['logo']['size'] < 4194304)) { $uploadfile = $uploaddir . $imgName; $modifiedLogoUrl = uniqid('ANAIMG_') . '.' . end($imgTemp); $uploadOk = 1; anacbt_remove_images($uploaddir); if (is_dir($uploaddir)) { //move_uploaded_file($_FILES['logo']['tmp_name'], $uploadfile); $copy_resp = move_uploaded_file($_FILES['logo']['tmp_name'], $uploadfile); if ($copy_resp) { $imgName = sanitize_file_name($_FILES['logo']['name']); } else { // echo "hi"; $uploadOk = 0; return "
Could not upload logo please try again\n Error:" . $copy_resp; } } } elseif (!empty($results->logoUrl)) { $modifiedLogoUrl = $results->modifiedLogoUrl; $imgName = $results->logoUrl; $uploadOk = 1; } elseif (file_exists($uploadpath . 'ANA/ANAUploads/ana.png')) { $uploadOk = 1; $imgName = "ana.png"; } else { $uploadOk = 0; return "
Please upload a image of format jpg or png \n"; } } elseif (!empty($results->logoUrl)) { $modifiedLogoUrl = $results->modifiedLogoUrl; $imgName = $results->logoUrl; $uploadOk = 1; } elseif (file_exists($uploadpath . 'ANA/ANAUploads/ana.png')) { $uploadOk = 1; $imgName = "ana.png"; } else { $uploadOk = 0; return "
Please upload a image of format jpg or png or check the size of the file and upload again \n"; } // for uploading the ana project file checking for all possible cases and validating the type of file uploaded $uploaddir = $uploadpath . "ANA/ANAUploads/"; if ($uploadOk == 1) { $temp = explode('.', sanitize_file_name($_FILES['userfile']['name'])); if (end($temp) == 'anaproj') { $uploadOk = 1; $filename = uniqid('ANA_') . '.' . end($temp); $uploadfile = $uploaddir . $filename; if (!empty($_FILES['userfile']['name'])) { anacbt_remove_files($uploaddir, $_FILES['userfile']['name']); $resp = move_uploaded_file($_FILES['userfile']['tmp_name'], $uploadfile); $logopath = $uploadscript . 'ANA/ANAUploads/' . $imgName; $projfilepath = $uploadscript . 'ANA/ANAUploads/' . $filename; $delete = $wpdb->query("TRUNCATE TABLE $table_name"); $wpdb->insert( $table_name, array( 'time' => current_time('mysql'), 'businessId' => $agentName, 'color' => $color, 'botApply' => sanitize_text_field($_POST['botapply']), 'logoUrl' => $imgName, 'seconds' => $seconds, 'fileUrl' => sanitize_file_name($_FILES['userfile']['name']), 'modifiedFileUrl' => $filename, 'modifiedLogoUrl' => $modifiedLogoUrl, ) ); anacbt_generateScript($fullpath, $color, $logopath, $agentName, $indexpath, $projfilepath, $seconds); } else { return "
Could not upload the file! \n"; } } elseif (!empty($results->fileUrl)) { $res = $wpdb->get_row("SELECT * FROM $table_name"); $tempFileUrl = $res->fileUrl; $tempModifiedFileUrl = $res->modifiedFileUrl; if (!$imgName) { $imgName = $res->logoUrl; $modifiedLogoUrl = $res->modifiedLogoUrl; } $delete = $wpdb->query("TRUNCATE TABLE $table_name"); $wpdb->insert( $table_name, array( 'time' => current_time('mysql'), 'businessId' => $agentName, 'color' => $color, 'botApply' => sanitize_text_field($_POST['botapply']), 'logoUrl' => $imgName, 'seconds' => $seconds, 'fileUrl' => $tempFileUrl, 'modifiedFileUrl' => $tempModifiedFileUrl, 'modifiedLogoUrl' => $modifiedLogoUrl, ) ); $res = $wpdb->get_row("SELECT * FROM $table_name"); $logopath = $uploadscript . 'ANA/ANAUploads/' . $res->logoUrl; $projfilepath = $uploadscript . 'ANA/ANAUploads/' . $results->modifiedFileUrl; anacbt_generateScript($fullpath, $color, $logopath, $agentName, $indexpath, $projfilepath, $seconds); } elseif (file_exists($uploadpath . 'ANA/ANAUploads/sample.anaproj')) { $delete = $wpdb->query("TRUNCATE TABLE $table_name"); $tempFileUrl = "sample.anaproj"; $modifiedFileUrl = "sample.anaproj"; $logopath = $uploadscript . 'ANA/ANAUploads/ana.png'; $modifiedLogoUrl = $imgName; $projfilepath = $uploadscript . 'ANA/ANAUploads/sample.anaproj'; global $wpdb; if (!empty($_POST['botapply'])) { $tempvar = sanitize_text_field($_POST['botapply']); } else { $tempvar = "all pages"; } $table_name = $wpdb->prefix . 'userdetails'; $wpdb->insert( $table_name, array( 'time' => current_time('mysql'), 'businessId' => $agentName, 'color' => $color, 'botApply' => sanitize_text_field($_POST['botapply']), 'logoUrl' => $imgName, 'seconds' => $seconds, 'fileUrl' => $tempFileUrl, 'modifiedFileUrl' => $tempModifiedFileUrl, 'modifiedLogoUrl' => $modifiedLogoUrl, ) ); $wpdb->last_query; anacbt_generateScript($fullpath, $color, $logopath, $agentName, $indexpath, $projfilepath, $seconds); } else { anacbt_removeScript($scriptpath); return "
The file is not a ANA project file please try again \n"; } } else { anacbt_removeScript($scriptpath); return "
Some of your details are not correct please verify and upload again \n"; } } // Generating the ana-script function anacbt_generateScript($fullpath, $color, $logopath, $agentName, $indexpath, $projfilepath, $seconds) { $temp_path = wp_upload_dir(); $rootpath = $temp_path['basedir']; $file = "script.js"; $my_file = $rootpath . "/ANA/ANAFiles/" . $file; $handle = fopen($my_file, 'w') or die('Cannot open file:' . $my_file); $data = ' (function (){ var ele = document.createElement("script"); ele.id = "ana-web-chat-script"; ele.src = "' . $fullpath . '"; ele.setAttribute("ana-primary-bg","' . $color . '"); ele.setAttribute("ana-primary-fg", "white"); ele.setAttribute("ana-logo-url", "' . $logopath . '"); ele.setAttribute("ana-agent-name", "' . $agentName . '"); ele.setAttribute("ana-iframe-src", "' . $indexpath . '"); ele.setAttribute("ana-frame-height", "70vh"); ele.setAttribute("ana-frame-width", "360px"); ele.setAttribute("ana-simulator", "true"); ele.setAttribute("ana-html-messages", "true"); ele.setAttribute("ana-allow-chat-reset", "true"); ele.setAttribute("ana-chat-json", "' . $projfilepath . '"); ele.setAttribute("ana-frame-content-width", "360px"); ele.setAttribute("ana-gmaps-key", ""); ele.setAttribute("ana-auto-open","' . $seconds . '") document.body.appendChild(ele); })(); '; fwrite($handle, $data); } //This part of the code is dispalyed in the admin page of the wordpress dashboard function anacbt_plugin_main() { $temp_path = wp_upload_dir(); $path = trailingslashit($temp_path['baseurl']); $output_log = ""; if (isset($_POST['submit']) && $_POST['hidden'] == "true") { $output_log = anacbt_fileUpload(); } global $wpdb; $table_name = $wpdb->prefix . 'userdetails'; $results = $wpdb->get_row("SELECT * FROM $table_name"); $rootpath = home_url(); if (!empty($results)) { $botname = $results->businessId; $color = $results->color; $seconds = $results->seconds; $logoname = $results->logoUrl; $logopath = $path . 'ANA/ANAUploads/' . $results->logoUrl; $fileurl = $results->fileUrl; $projfilepath = $path . 'ANA/ANAUploads/' . $results->modifiedFileUrl; } else { $logoname = "ana.png"; $botname = "Ana"; $color = "#8cc83c"; $seconds = "3"; $logopath = $path . 'ANA/ANAUploads/ana.png'; $fileurl = "sample.anaproj"; $projfilepath = $path . 'ANA/ANAUploads/sample.anaproj'; } echo '

Ana Settings


Upload Ana Chatbot

' . $fileurl . '

Refer to the steps in How to Create a Chatbot


Upload Logo


Name of Chatbot

Primary Color Hex Code

Add Chatbot to Home Page only

Added to all pages by default

Enable Auto Pop-up


Auto Pop-up Chatbot in seconds


How to Create a Chatbot

You require Ana Studio to create chatbots. It is very easy and fun to use. Just follow these steps and you can add a chatbot to your website

Setting Up

  1. Click here to download Ana Studio for Windows, Linux or Mac.
  2. Run the downloaded file. The Ana setup will start and after installation, a window will open.
  3. Select Studio and then Add New Chatbot. You can give your chatbot any name you wish.

Creating Chatbot

Click here to download a sample chatbot flow. You can edit this for your use.

  1. Ana Chat flow designer will open, where you will create your chatbot flow.
  2. Each element of conversation is called a Node.You can add text and multimedia content to each node.
  3. You can add buttons to each node. Each button has a specific function. You can set the Button Type
    for each button. Commonly used Button Types are:
    NextNode- On clicking this button, it will direct it to another node
    GetText - To make the user enter text, which can be stored for later use
  4. You can drag a line from a button to another node. When a user clicks on this button, he/she will be directed to the other node.

Uploading Chatbot

  1. Double click on the node you want the conversation to start with, navigate to Node Info and check Mark as start node.
  2. See how the chatbot will look like by clicking on Run Chat. This will show you the chatbot you have created. You can make as many changes to your bot as you wish. Once the chatbot is ready, click on Save.
  3. Click on Export and save the chatbot file. You will need to upload this file in the next step.
  4. In the WordPress Ana Plugin Configuration, in Upload Ana Chatbot section, select Choose File and upload the chatbot file you had saved.
  5. Click on Save. Click on Preview to view the bot on your website\'s homepage. All done and ready on your website!

You can always make new chatbots or make changes to existing one and upload them. A fun way to keep users on your website engaged.

In case of any queries, email us at hello@ana.chat.

'; echo esc_attr($output_log); }