WP-Chatbot for Facebook Messenger Customer Chat - Version 1.0.0

Version Description

= using FTP or similar = * Delete wp-shapes folder - your setting will not lost. * unzip wp-shapes file and * Upload "wp-shapes" folder to the "/wp-content/plugins/" directory. * Activate the plugin through the "Plugins" menu in WordPress.

= From Dashboard ( WordPress admin ) = * If plugin new version released - you can see 'update now' link at wp-admin -> plugins * click on 'update now'

Download this release

Release Info

Developer bhvreddy
Plugin Icon 128x128 WP-Chatbot for Facebook Messenger Customer Chat
Version 1.0.0
Comparing to
See all releases

Version 1.0.0

admin/admin.php ADDED
@@ -0,0 +1,21 @@
1
+ <?php
2
+ /**
3
+ * Central file for admin
4
+ *
5
+ * @package htcc
6
+ * @subpackage Admin
7
+ * @since 1.0.0
8
+ *
9
+ * subpackage Admin loads only on wp-admin
10
+ */
11
+
12
+
13
+ if ( ! defined( 'ABSPATH' ) ) exit;
14
+
15
+
16
+ require_once('class-htcc-admin.php');
17
+
18
+
19
+ $admin = new HTCC_Admin();
20
+ add_action('admin_menu', array( $admin, 'htcc_options_page') );
21
+ add_action( 'admin_init', array( $admin, 'htcc_custom_settings' ) );
admin/class-htcc-admin.php ADDED
@@ -0,0 +1,146 @@
1
+ <?php
2
+ /**
3
+ * Creates top level menu
4
+ * and options page
5
+ *
6
+ * @package htcc
7
+ * @subpackage admin
8
+ * @since 1.0.0
9
+ *
10
+ */
11
+
12
+ if ( ! defined( 'ABSPATH' ) ) exit;
13
+
14
+ if ( ! class_exists( 'htcc_Admin' ) ) :
15
+
16
+ class HTCC_Admin {
17
+
18
+
19
+ /**
20
+ * Adds top level menu -> WP CSS Shapes
21
+ *
22
+ * @uses action hook - admin_menu
23
+ *
24
+ * @since 1.0.0
25
+ * @return void
26
+ */
27
+ public function htcc_options_page() {
28
+ add_menu_page(
29
+ 'customer chat',
30
+ 'customer-chat',
31
+ 'manage_options',
32
+ 'customer-chat',
33
+ array( $this, 'settings_page' ),
34
+ 'dashicons-heart'
35
+ );
36
+ }
37
+
38
+
39
+ /**
40
+ * Options page Content -
41
+ * get settings form from a template settings_page.php
42
+ *
43
+ * Call back from - $this->htcc_options_page, add_menu_page
44
+ *
45
+ * @since 1.0.0
46
+ * @return void
47
+ */
48
+ public function settings_page() {
49
+
50
+ if ( ! current_user_can('manage_options') ) {
51
+ return;
52
+ }
53
+
54
+ // get options page form
55
+ require_once('settings_page.php');
56
+ }
57
+
58
+
59
+
60
+ /**
61
+ * Options page - Regsiter, add section and add setting fields
62
+ *
63
+ * @uses action hook - admin_init
64
+ *
65
+ * @since 1.0.0
66
+ * @return void
67
+ */
68
+ public function htcc_custom_settings() {
69
+
70
+ register_setting( 'htcc_settings_group', 'htcc_options' , array( $this, 'htcc_options_sanitize' ) );
71
+
72
+ add_settings_section( 'htcc_settings', '', array( $this, 'htcc_settings_section_cb' ), 'htcc_options_settings' );
73
+
74
+ add_settings_field( 'htcc_fb_app_id', 'Facebook App ID', array( $this, 'htcc_fb_app_id_cb' ), 'htcc_options_settings', 'htcc_settings' );
75
+ add_settings_field( 'htcc_fb_page_id', 'Facebook Page ID', array( $this, 'htcc_fb_page_id_cb' ), 'htcc_options_settings', 'htcc_settings' );
76
+
77
+ }
78
+
79
+ // section heading
80
+ function htcc_settings_section_cb() {
81
+ echo '<h1>Customer Chat - Settings</h1>';
82
+ }
83
+
84
+
85
+
86
+ public function htcc_fb_app_id_cb() {
87
+
88
+ $htcc_fb_app_id = get_option('htcc_options');
89
+ ?>
90
+ <input type="text" name="htcc_options[fb_app_id]" id="" value="<?php echo esc_attr( $htcc_fb_app_id['fb_app_id'] ) ?>">
91
+
92
+ <p class="description">Facebook App ID - <a target="_blank" href="">moreinfo</a> </p>
93
+ <?php
94
+ }
95
+
96
+
97
+ public function htcc_fb_page_id_cb() {
98
+
99
+ $htcc_fb_page_id = get_option('htcc_options');
100
+ ?>
101
+ <input type="text" name="htcc_options[fb_page_id]" id="" value="<?php echo esc_attr( $htcc_fb_page_id['fb_page_id'] ) ?>">
102
+
103
+
104
+ <p class="description">Facebook Page ID - <a target="_blank" href="">moreinfo</a> </p>
105
+ <?php
106
+ }
107
+
108
+
109
+
110
+
111
+
112
+
113
+
114
+
115
+
116
+ /**
117
+ * Sanitize each setting field as needed
118
+ *
119
+ * @since 1.0.0
120
+ * @param array $input Contains all settings fields as array keys
121
+ */
122
+ public function htcc_options_sanitize( $input ) {
123
+
124
+ if ( ! current_user_can( 'manage_options' ) ) {
125
+ wp_die( 'not allowed to modify - please contact admin ' );
126
+ }
127
+
128
+ $new_input = array();
129
+
130
+ if( isset( $input['fb_app_id'] ) )
131
+ $new_input['fb_app_id'] = sanitize_text_field( $input['fb_app_id'] );
132
+
133
+ if( isset( $input['fb_page_id'] ) )
134
+ $new_input['fb_page_id'] = sanitize_text_field( $input['fb_page_id'] );
135
+
136
+ return $new_input;
137
+ }
138
+
139
+
140
+
141
+
142
+
143
+
144
+ }
145
+
146
+ endif; // END class_exists check
admin/settings_page.php ADDED
@@ -0,0 +1,22 @@
1
+ <?php
2
+ /**
3
+ * template for options page
4
+ * @uses HTCC_Admin::settings_page
5
+ * @since 1.0.0
6
+ */
7
+
8
+ if ( ! defined( 'ABSPATH' ) ) exit;
9
+
10
+ ?>
11
+
12
+ <div class="wrap">
13
+
14
+ <?php settings_errors(); ?>
15
+
16
+ <form action="options.php" method="post" class="">
17
+ <?php settings_fields( 'htcc_settings_group' ); ?>
18
+ <?php do_settings_sections( 'htcc_options_settings' ) ?>
19
+ <?php submit_button() ?>
20
+ </form>
21
+
22
+ </div>
customer-chat.php ADDED
@@ -0,0 +1,46 @@
1
+ <?php
2
+ /*
3
+ Plugin Name: WP Chatbot
4
+ Description: Customer chat plugin for Facebook
5
+ Version: 1.0.0
6
+ Author: bhvreddy
7
+ License: GPL2
8
+ License URI: https://www.gnu.org/licenses/gpl-2.0.html
9
+ Text Domain: htcc_text
10
+ */
11
+
12
+
13
+ if ( ! defined( 'ABSPATH' ) ) exit;
14
+
15
+ define( 'HTCC_VERSION', '1.0.0' );
16
+ define( 'HTCC_WP_MIN_VERSION', '3.1.0' );
17
+ define( 'HTCC_PLUGIN_DIR', plugin_dir_path( __FILE__ ) );
18
+ define( 'HTCC_PLUGIN_FILE', __FILE__ );
19
+
20
+
21
+ // include in admin and public pages ( non-admin )
22
+ require_once('inc/class-htcc-register.php');
23
+
24
+
25
+
26
+ /**
27
+ * is_admin - include file to admin area - only if it is_admin
28
+ * else - include files to non-admin area
29
+ */
30
+ if ( is_admin() ) {
31
+ require_once('admin/admin.php');
32
+ } else {
33
+ require_once('inc/chatbot.php');
34
+
35
+ }
36
+
37
+ /**
38
+ * Register hooks - when plugin activate, deactivate, uninstall
39
+ * commented deactivation, uninstall hook - its not needed as now
40
+ */
41
+ register_activation_hook( __FILE__, array( 'HTCC_Register', 'activate' ) );
42
+ // register_deactivation_hook( __FILE__, array( 'HTCC_Register', 'deactivate' ) );
43
+ // register_uninstall_hook(__FILE__, array( 'HTCC_Register', 'uninstall' ) );
44
+
45
+ // when plugin updated - check version diff
46
+ add_action('plugins_loaded', array( 'HTCC_Register', 'plugin_update' ) );
inc/chatbot.php ADDED
@@ -0,0 +1,44 @@
1
+ <?php
2
+ /**
3
+ * get app id
4
+ * get page id
5
+ * and add it to script, div
6
+ */
7
+
8
+ if ( ! defined( 'ABSPATH' ) ) exit;
9
+
10
+ $htcc_options = get_option('htcc_options');
11
+
12
+ $htcc_fb_app_id = esc_attr( $htcc_options['fb_app_id'] );
13
+ $htcc_fb_page_id = esc_attr( $htcc_options['fb_page_id'] );
14
+
15
+ ?>
16
+
17
+
18
+
19
+ <script>
20
+ window.fbAsyncInit = function() {
21
+ FB.init({
22
+ appId : '<?php echo $htcc_fb_app_id ?>',
23
+ autoLogAppEvents : true,
24
+ xfbml : true,
25
+ version : 'v2.11'
26
+ });
27
+ };
28
+
29
+ (function(d, s, id){
30
+ var js, fjs = d.getElementsByTagName(s)[0];
31
+ if (d.getElementById(id)) {return;}
32
+ js = d.createElement(s); js.id = id;
33
+ js.src = "https://connect.facebook.net/en_US/sdk.js";
34
+ fjs.parentNode.insertBefore(js, fjs);
35
+ }(document, 'script', 'facebook-jssdk'));
36
+ </script>
37
+
38
+
39
+
40
+ <div class="fb-customerchat"
41
+ page_id="<?php echo $htcc_fb_page_id ?>"
42
+ ref=""
43
+ minimized="true">
44
+ </div>
inc/class-htcc-register.php ADDED
@@ -0,0 +1,123 @@
1
+ <?php
2
+ /**
3
+ * class htcc_register
4
+ *
5
+ * this class have methods to run when plugin
6
+ * activate, deactivate, uninstall, update
7
+ *
8
+ * add values to Database - wp_options table
9
+ * plugin details
10
+ */
11
+
12
+ if ( ! defined( 'ABSPATH' ) ) exit;
13
+
14
+ if ( ! class_exists( 'HTCC_Register' ) ) :
15
+
16
+ class HTCC_Register {
17
+
18
+ /**
19
+ * When plugin activate this function will call
20
+ *
21
+ * Check min wp version
22
+ * calls self::db_plugin_details - add plugin details to db
23
+ *
24
+ * @since 1.0.0
25
+ * @uses register_activation_hook
26
+ *
27
+ * @return void
28
+ */
29
+ public static function activate() {
30
+
31
+ // check minimum version required to run this plugin
32
+ if( version_compare( get_bloginfo('version'), HTCC_WP_MIN_VERSION, '<') ) {
33
+ wp_die( 'please update WordPress' );
34
+ }
35
+
36
+ // update plugin details to wp_options table
37
+ self::db_plugin_details();
38
+
39
+ self::db_default_values();
40
+
41
+ }
42
+
43
+ /**
44
+ * When plugin deactivate
45
+ * @since 1.0.0
46
+ * @uses register_deactivation_hook
47
+ * @return void
48
+ */
49
+ public static function deactivate() {
50
+
51
+ }
52
+
53
+ /**
54
+ * When plugin uninstall ( delete )
55
+ * @since 1.0.0
56
+ * @uses register_uninstall_hook
57
+ * @return void
58
+ */
59
+ public static function uninstall() {
60
+
61
+ }
62
+
63
+
64
+ /**
65
+ * @uses action hook - plugins_loaded
66
+ *
67
+ * compare this content version with saved version in db
68
+ * If version is different then run activate function
69
+ *
70
+ * @since 1.0.0
71
+ *
72
+ * @return void
73
+ */
74
+ public static function plugin_update() {
75
+
76
+ $htcc_plugin_details = get_option('htcc_plugin_details');
77
+
78
+ if ( HTCC_VERSION !== $htcc_plugin_details['version'] ) {
79
+ // to update the plugin - just like activate plugin
80
+ self::activate();
81
+
82
+ }
83
+ }
84
+
85
+ /**
86
+ * Add plugin Details to db - wp_options table
87
+ * Add plugin version to db - useful while updating plugin
88
+ *
89
+ * @uses self::activate()
90
+ * @return void
91
+ */
92
+ public static function db_plugin_details() {
93
+
94
+ // plugin details
95
+ $plugin_details = array(
96
+ 'version' => HTCC_VERSION,
97
+ );
98
+
99
+ // Always use update_option - override new values .. don't preseve already existing values
100
+ update_option( 'htcc_plugin_details', $plugin_details );
101
+ }
102
+
103
+
104
+ public static function db_default_values() {
105
+
106
+ // plugin details
107
+ $values = array(
108
+ 'fb_app_id' => '510187842699385',
109
+ 'fb_page_id' => '135269407170658',
110
+ );
111
+
112
+
113
+ // update_option( 'htcc_options', $values );
114
+ // add_option( 'htcc_options', $values );
115
+
116
+ $db_values = get_option( 'htcc_options', array() );
117
+ $update_values = array_merge($values, $db_values);
118
+ update_option('htcc_options', $update_values);
119
+ }
120
+
121
+ }
122
+
123
+ endif; // END class_exists check
index.php ADDED
@@ -0,0 +1,2 @@
1
+ <?php
2
+ // Silence is golden.
readme.txt ADDED
@@ -0,0 +1,73 @@
1
+ === WP CHATBOT ===
2
+ Requires at least: 4.0.0
3
+ Tested up to: 4.9.1
4
+ Requires PHP: 5.6
5
+ Contributors: bhvreddy
6
+ Donate link: https://www.paypal.me/ugadi
7
+ Stable tag: trunk
8
+ Tags: messanger chatbot, customer chat, facebook customer chat, facebook chat plugin, chatbot
9
+ License: GPLv2 or later
10
+ License URI: https://www.gnu.org/licenses/gpl-2.0.html
11
+
12
+
13
+
14
+ == Description ==
15
+ Chat with Customer from your website using Messanger bot.
16
+
17
+ == Documentation ==
18
+ Build for Facebook Customer chat plugin - Integrate your Messenger bot directly into your website
19
+
20
+ = Requires =
21
+ Facebook Developer account
22
+ Facebook APP ID
23
+ Facebook Page ID
24
+
25
+ ( if you already done this no need to do again )
26
+ 1. signup for Facebook Developer Account
27
+ 1. Create an APP
28
+ 1. Create a Page
29
+ 1. Whitelisted Domains - Facebook page -> settings -> Messenger Platform
30
+ and at 'Whitelisted Domains' add domain name.
31
+
32
+ in plugin setting page
33
+ add Facebook App ID, Facebook Page ID
34
+
35
+ and for creating automatic messages - chatbot - use chatfuel or some other tools
36
+
37
+ more info - https://developers.facebook.com/docs/messenger-platform/discovery/customer-chat-plugin
38
+
39
+ == screenshots ==
40
+
41
+ 1. Demo
42
+ 1. Facebook App ID
43
+ 1. Facebook Page ID
44
+
45
+
46
+ == Installation ==
47
+
48
+ = using FTP or similar =
49
+ * unzip wp-shapes file and
50
+ * Upload "wp-shapes" folder to the "/wp-content/plugins/" directory.
51
+ * Activate the plugin through the "Plugins" menu in WordPress.
52
+
53
+ = From Dashboard ( WordPress admin ) =
54
+ * plugins -> Add New
55
+ * search for 'wp shapes'
56
+ * click on Install Now and then Active.
57
+
58
+ == Upgrade Notice ==
59
+
60
+ = using FTP or similar =
61
+ * Delete wp-shapes folder - your setting will not lost.
62
+ * unzip wp-shapes file and
63
+ * Upload "wp-shapes" folder to the "/wp-content/plugins/" directory.
64
+ * Activate the plugin through the "Plugins" menu in WordPress.
65
+
66
+ = From Dashboard ( WordPress admin ) =
67
+ * If plugin new version released - you can see 'update now' link at wp-admin -> plugins
68
+ * click on 'update now'
69
+
70
+ == Changelog ==
71
+
72
+ = 1.0.0 =
73
+ * Initial release.