From dbc434c40971ee17636f8db2184480d4e92d369c Mon Sep 17 00:00:00 2001 From: Marco Milesi Date: Mon, 1 Jul 2024 15:21:40 +0200 Subject: [PATCH] v3.8 --- defaults.php | 31 ---- panel/settings.php | 398 +++++++++++++++++++-------------------------- readme.txt | 14 +- telegram-bot.php | 44 ++++- zapier.php | 9 - 5 files changed, 216 insertions(+), 280 deletions(-) delete mode 100644 defaults.php delete mode 100644 zapier.php diff --git a/defaults.php b/defaults.php deleted file mode 100644 index 22d4031..0000000 --- a/defaults.php +++ /dev/null @@ -1,31 +0,0 @@ - diff --git a/panel/settings.php b/panel/settings.php index b2b283d..4e5d776 100644 --- a/panel/settings.php +++ b/panel/settings.php @@ -1,12 +1,8 @@ + +

Settings

-

- This plugin is capable of broadcasting to channel and create interactive bots. -
In both cases, you need to create a bot with BotFather and obtain the token. -
If you want to broadcast to a channel, please add the bot as admin in your channel. -

-

'.__('Warning: the plugin does not work in localhost environments!', 'telegram-bot').'

'; } ?> @@ -21,275 +17,219 @@ if ( isset($_GET['settings-updated']) ) { - $url=telegram_geturl() . 'setWebhook?url='; + $url=telegram_geturl() . 'setWebhook?url=' . telegram_getapiurl(); - switch( telegram_option('mode') ) { - case 0: // SSL - $url .=telegram_getapiurl(); - break; - } json_decode(file_get_contents($url), true); telegram_log( 'sys', 'Webhook update', $url); } ?> - -
-
- - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- - - -
- The unique key for your website: Keep it secret! -
- - - -
- Telegram Bot authentication key. Keep it secret! - -
- - - -
- Telegram Bot username. Example: mywebsite_bot -
- - - -
- Insert your channel username (if you want to broadcast). Example: @mywebsite -
The bot must be admin in your channel -
-
- - - -
- - Telegram webhooks to get the best user experience!', 'telegram-bot'); - } else { - _e('SSL NOT ACTIVE: choose BotPress.org to bypass webhook restriction', 'telegram-bot'); - echo '
'; - _e('Warning: by choosing BotPress.org some data, including your website url and email, will be sent to our servers.', 'telegram-bot'); - echo '
'; - _e('BotPress.org usage is subject to our ', 'telegram-bot'); - echo ''; - _e('Privacy Policy'); - echo ' and '; - _e('Terms & Conditions'); - echo '. By choosing the service you automatically accept these conditions.
Warning: BotPress.org connection mode will be dismissed in 2023'; - } - ?> -
-
- - - Show private endpoint -

- This is your private Telegram webhook. Please keep it private and make sure it bypasses cache and firewall. -

-
- - - /> -
- enable zapier integration • Beta • - Click here to get an invite - - -
-
- - - -
- - - - - - - - - - - + - + + + + + + + + + + + + + + + + + + + + + + - - - + + + -
-

-

-
- - -
- - +
- -
-
- - - -
%TITLE% %LINK% %EXCERPT% %CHAT_ID%', 'telegram-bot'); ?>
-

-

Only use this section if you want to build an interactive bot

+ The unique key for your website: Keep it secret!
- + - +
- - . - + BotFather', 'telegram-bot'); ?>
- + - +
- - . - + Telegram Bot username. Example: mywebsite_bot
- - +
- + Insert your channel username (if you want to broadcast). Example: @mywebsite +
The bot must be admin in your channel +
+ + + Show private endpoint +

+ This is your private Telegram webhook. Please keep it private and make sure it bypasses cache and firewall. +

+
+ + + /> +
+ Zapier allows you to send messages from your own platforms + Click here to get an invite + +
+

+

+

+
+ + + +
+ + +
+ +
+
- + - + +
%TITLE% %LINK% %EXCERPT% %CHAT_ID%', 'telegram-bot'); ?>
+

+

Only use this section if you want to build an interactive bot

+
+
- - - + + + + +
+ + . + +
+
-
-
+ + + + + + + +
+ + . + + + + + + + + + +
+ + + + + + + + + +
+ + . + + + + + + + + + +
+ 1,2,3;4,5,6;Text', 'telegram-bot'); ?> + + + -
-

+ \ No newline at end of file diff --git a/readme.txt b/readme.txt index cc3c9fd..cc2aaa6 100644 --- a/readme.txt +++ b/readme.txt @@ -1,27 +1,27 @@ === Telegram Bot & Channel === Contributors: Milmor -Version: 3.7 -Stable tag: 3.7 +Version: 3.8 +Stable tag: 3.8 Author: Marco Milesi Author URI: https://profiles.wordpress.org/milmor/ Donate link: https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=F2JK36SCXKTE2 Tags: telegram, bot, newsletter, channel, group, automatic, stream, classicpress Requires at least: 3.8 Requires PHP: 5.6 -Tested up to: 6.4 +Tested up to: 6.5 License: GPLv2 or later License URI: http://www.gnu.org/licenses/gpl-2.0.html -Transform your content distribution and customer experience with our Telegram broadcast and interactive bot solutions. Zapier integrated! +Send your posts to Telegram and build an interactive bot. Zapier integrated! == Description == -This versatile plugin allows you to accomplish a variety of tasks, including teaching, playing, searching, broadcasting, reminding, connecting, and integrating with your services. +This plugin allows you to accomplish a variety of tasks, including teaching, playing, searching, broadcasting, reminding, connecting, and integrating with your services. With this powerful bot builder, you can: -🤖 **Bot builder**: create interactive autoresponders for users and groups -📣 **Broadcast**: utilize the broadcast feature to send messages to your channels and bot subscribers +🤖 **Build a bot**: create interactive autoresponders for users and groups +📣 **Broadcast to a channel**: utilize the broadcast feature to send messages to your channels and bot subscribers https://youtu.be/8fckoWSmAks diff --git a/telegram-bot.php b/telegram-bot.php index 7717bf0..533e70f 100644 --- a/telegram-bot.php +++ b/telegram-bot.php @@ -3,7 +3,7 @@ Plugin Name: Telegram Bot & Channel Plugin URI: https://wordpress.org/plugins/telegram-bot/ Description: Broadcast your content to Telegram, build interactive bots and boost your omnichannel customer experience -Version: 3.7 +Version: 3.8 Author: Marco Milesi Author URI: https://www.marcomilesi.com Contributors: Milmor @@ -14,6 +14,7 @@ require 'columns.php'; require 'admin-messages.php'; require 'panel/send.php'; +require 'panel/settings.php'; add_action( 'plugins_loaded', function(){ load_plugin_textdomain( 'telegram-bot' ); @@ -25,7 +26,7 @@ add_submenu_page('telegram_main', __('Groups', 'telegram-bot'), __('Groups', 'telegram-bot'), 'manage_options', 'edit.php?post_type=telegram_groups'); add_submenu_page('telegram_main', __('Send a message', 'telegram-bot'), __('Send a message', 'telegram-bot'), 'manage_options', 'telegram_send', 'telegram_send_panel' ); add_submenu_page('telegram_main', __('Responders', 'telegram-bot'), __('Responders', 'telegram-bot'), 'manage_options', 'edit.php?post_type=telegram_commands'); - add_submenu_page('telegram_main', __('Settings', 'telegram-bot'), __('Settings', 'telegram-bot'), 'manage_options', 'telegram_settings', function(){require 'panel/settings.php';}); + add_submenu_page('telegram_main', __('Settings', 'telegram-bot'), __('Settings', 'telegram-bot'), 'manage_options', 'telegram_settings', function(){ telegram_settings_page(); }); add_submenu_page('telegram_main', 'Log', 'Log', 'manage_options', 'telegram_log', 'telegram_log_panel'); }); @@ -87,7 +88,34 @@ function telegram_log_panel() { require 'custom-post-types.php'; function telegram_defaults() { - require 'defaults.php'; + if (!get_option('wp_telegram_apikey')) { + update_option('wp_telegram_apikey', md5(microtime() . rand() . get_site_url())); + } + + if (!get_option('wp_telegram_dispatches')) { + update_option('wp_telegram_dispatches', 0); + } + + $defaults = array( + array('token', ''), + array('zapier', ''), + array('wmgroup', 'Welcome!'), + array('wmuser', 'Welcome, %FIRST_NAME%!'), + array('posttemplate', '%TITLE%'.PHP_EOL.PHP_EOL.'%LINK%'), + array('bmuser', 'Bye, %FIRST_NAME%. Type /start to enable the bot again.'), + array('keyboard', '') + ); + + $my_options = get_option('wp_telegram'); + + $conta = count($defaults); + + for ($i = 0; $i < $conta; $i++) { + if (!isset( $my_options[$defaults[$i][0]] ) || !$my_options[$defaults[$i][0]]) { + $my_options[$defaults[$i][0]] = $defaults[$i][1]; + update_option('wp_telegram', $my_options); + } + } } add_action('template_redirect', function(){ @@ -98,7 +126,15 @@ function telegram_defaults() { } else if ( isset( $_GET['zap'] ) && $wp_query->query['zap']) { if ($_GET['zap'] == get_option('wp_telegram_apikey') && telegram_option('zapier')) { status_header( 200 ); - require 'zapier.php'; + + $json = file_get_contents('php://input'); + if (!$json) { + return; + } + $data = (array) json_decode($json, TRUE); + telegram_log('------>', 'ZAPIER', json_encode((array) file_get_contents("php://input"))); + telegram_sendmessagetoall($data['hook']); + } } }); diff --git a/zapier.php b/zapier.php deleted file mode 100644 index 9ee8d47..0000000 --- a/zapier.php +++ /dev/null @@ -1,9 +0,0 @@ -', 'ZAPIER', json_encode((array) file_get_contents("php://input"))); - telegram_sendmessagetoall($data['hook']); -?> \ No newline at end of file