Changeset 3300993
- Timestamp:
- 05/26/2025 08:37:48 PM (10 months ago)
- Location:
- telegram-bot
- Files:
-
- 18 edited
- 1 copied
-
tags/4.0 (copied) (copied from telegram-bot/trunk)
-
tags/4.0/admin-messages.php (modified) (1 diff)
-
tags/4.0/columns.php (modified) (4 diffs)
-
tags/4.0/custom-post-types.php (modified) (1 diff)
-
tags/4.0/panel/main.php (modified) (1 diff)
-
tags/4.0/panel/send.php (modified) (2 diffs)
-
tags/4.0/panel/settings.php (modified) (1 diff)
-
tags/4.0/parse.php (modified) (5 diffs)
-
tags/4.0/readme.txt (modified) (1 diff)
-
tags/4.0/telegram-bot.php (modified) (7 diffs)
-
trunk/admin-messages.php (modified) (1 diff)
-
trunk/columns.php (modified) (4 diffs)
-
trunk/custom-post-types.php (modified) (1 diff)
-
trunk/panel/main.php (modified) (1 diff)
-
trunk/panel/send.php (modified) (2 diffs)
-
trunk/panel/settings.php (modified) (1 diff)
-
trunk/parse.php (modified) (5 diffs)
-
trunk/readme.txt (modified) (1 diff)
-
trunk/telegram-bot.php (modified) (7 diffs)
Legend:
- Unmodified
- Added
- Removed
-
telegram-bot/tags/4.0/admin-messages.php
r2981438 r3300993 1 1 <?php 2 add_action( 'admin_notices', function() { 3 4 global $current_screen; 5 if ( 'telegram_subscribers' == $current_screen->post_type ) { 6 echo ' 7 <div class="notice notice-info"> 8 <p>List of bot subscribers. New users will automatically appear once they /start on the bot</p> 9 </div>'; 10 } else if ( 'telegram_groups' == $current_screen->post_type ) { 11 echo ' 12 <div class="notice notice-info"> 13 <p>List of groups where your bot has been added.<br> 14 <small>Some <strong>BotFather</strong> actions could be required to get this working.</small></p> 15 </div>'; 16 } else if ( 'telegram_commands' == $current_screen->post_type ) { 17 echo ' 18 <div class="notice notice-info"> 19 <p>List of active commands of your bot<br> 20 <small>You can use the <strong>/command</strong> format as well as <strong>command</strong> (they are different). 21 <br>You can define multiple commands by typing, without spaces, a succession of comma-separated values (example: <strong>/command,command,/command2</strong>)</small></p> 22 </div>'; 23 } else if ( 'telegram_lists' == $current_screen->taxonomy ) { 24 echo ' 25 <div class="notice notice-info"> 26 <p>You can create different distribution lists in this page. This can be used for people and groups as well.</p> 27 </div>'; 2 add_action('admin_notices', function() { 3 if (!function_exists('get_current_screen')) { 4 return; 5 } 6 $screen = get_current_screen(); 7 if (!$screen) { 8 return; 9 } 10 $notices = [ 11 'telegram_subscribers' => [ 12 'type' => 'info', 13 'message' => __('List of users who have subscribed to your bot.', 'telegram-bot'), 14 ], 15 'telegram_groups' => [ 16 'type' => 'info', 17 'message' => __('List of groups where your bot has been added.<br><small>Some <strong>BotFather</strong> actions could be required to get this working.</small>', 'telegram-bot'), 18 ], 19 'telegram_commands' => [ 20 'type' => 'info', 21 'message' => __('List of active commands of your bot<br><small>You can use the <strong>/command</strong> format as well as <strong>command</strong> (they are different).<br>You can define multiple commands by typing, without spaces, a succession of comma-separated values (example: <strong>/command,command,/command2</strong>)</small>', 'telegram-bot'), 22 ], 23 ]; 24 if (isset($screen->post_type) && isset($notices[$screen->post_type])) { 25 $notice = $notices[$screen->post_type]; 26 printf( 27 '<div class="notice notice-%s"><p>%s</p></div>', 28 esc_attr($notice['type']), 29 $notice['message'] 30 ); 31 } elseif (isset($screen->taxonomy) && $screen->taxonomy === 'telegram_lists') { 32 printf( 33 '<div class="notice notice-info"><p>%s</p></div>', 34 __('You can create different distribution lists on this page. This can be used for people and groups as well.', 'telegram-bot') 35 ); 28 36 } 29 37 }); -
telegram-bot/tags/4.0/columns.php
r2981438 r3300993 16 16 $columns['name'] ='Group Name'; 17 17 $columns['sdate'] ='Subscribed on'; 18 unset($columns['cb']); 18 19 unset($columns['date']); 19 20 if ( defined('WP_DEBUG') && false === WP_DEBUG) { … … 23 24 } ); 24 25 25 function bulk_actions_telegram_send($bulk_actions) {26 add_filter('bulk_actions-edit-telegram_subscribers', function($bulk_actions) { 26 27 $bulk_actions['telegram-send'] = __('Send message', 'telegram-bot'); 27 28 return $bulk_actions; 28 } 29 add_filter('bulk_actions-edit-telegram_subscribers', 'bulk_actions_telegram_send' ); 30 add_filter('bulk_actions-edit-telegram_groups', 'bulk_actions_telegram_send' ); 29 }); 31 30 32 function handle_bulk_actions_telegram_send($redirect_url, $action, $post_ids) {31 add_filter('handle_bulk_actions-edit-telegram_subscribers', function($redirect_url, $action, $post_ids) { 33 32 if ($action == 'telegram-send') { 34 33 … … 37 36 } 38 37 return $redirect_url; 39 } 40 add_filter('handle_bulk_actions-edit-telegram_subscribers', 'handle_bulk_actions_telegram_send', 10, 3); 41 add_filter('handle_bulk_actions-edit-telegram_groups', 'handle_bulk_actions_telegram_send', 10, 3); 38 }, 10, 3); 39 40 #add_filter('bulk_actions-edit-telegram_subscribers', function($actions){ unset( $actions['edit'] ); return apply_filters( 'bulk_actions-edit-telegram_subscribers_filter', $actions ); }); 41 #add_filter('bulk_actions-edit-telegram_groups', function($actions){ unset( $actions['edit'] ); return apply_filters( 'bulk_actions-edit-telegram_groups_filter', $actions ); }); 42 42 43 43 add_action('manage_telegram_subscribers_posts_custom_column', 't_manage_columns', 10, 2); … … 47 47 switch ($column) { 48 48 case 'name': 49 echo '<a class="row-title" href="'.get_edit_post_link( $post_id ).'">'.get_post_meta($post_id, 'telegram_name', true).'</a>';49 printf(get_post_meta($post_id, 'telegram_name', true)); 50 50 break; 51 51 case 'user_name': -
telegram-bot/tags/4.0/custom-post-types.php
r2981438 r3300993 90 90 ); 91 91 if ( defined('WP_DEBUG') && false === WP_DEBUG) { 92 $args['capabilities'] = array( 'create_posts' => ' false' );93 $args['map_meta_cap'] = true;92 $args['capabilities'] = array( 'create_posts' => 'do_not_allow' ); 93 $args['map_meta_cap'] = false; 94 94 } 95 95 $args = apply_filters('telegram_groups_register_capabilities', $args ); -
telegram-bot/tags/4.0/panel/main.php
r2418686 r3300993 1 <?php 2 // Security: Only allow admins to view this page 3 if (!current_user_can('manage_options')) { 4 wp_die(__('You do not have sufficient permissions to access this page.')); 5 } 1 6 2 <div class="wrap"> 3 <div class="wrap about__container"> 7 // Fetch stats 8 $version = esc_html(get_option('wp_telegram_version')); 9 $dispatches = number_format_i18n(intval(get_option('wp_telegram_dispatches'))); 10 $subscribers = number_format_i18n(wp_count_posts('telegram_subscribers')->publish); 11 $groups = number_format_i18n(wp_count_posts('telegram_groups')->publish); 4 12 5 <div class="about__section is-feature has-accent-background-color"> 6 <h1>Telegram Bot & Channel</h1> 7 <p>Version <?php echo get_option('wp_telegram_version'); ?></p> 13 // Fetch recent log entries (last 5) 14 $log = get_option('wp_telegram_log'); 15 $recent_log = is_array($log) ? array_slice($log, 0, 5) : array(); 16 17 // Fetch plugin settings link 18 $settings_url = admin_url('admin.php?page=telegram_settings'); 19 20 // Fetch log page link 21 $log_url = admin_url('admin.php?page=telegram_log'); 22 23 ?> 24 <div class="wrap telegram-dashboard" style="max-width:900px;margin:auto;"> 25 <div class="telegram-header" style="display:flex;align-items:center;justify-content:space-between;padding:32px 0 16px 0;"> 26 <div> 27 <h1 style="margin:0;font-size:2.5em;">🤖 Telegram Bot & Channel</h1> 28 <span style="color:#888;font-size:1.1em;">v<?php echo $version; ?></span> 8 29 </div> 9 <div class=" wp-clearfix"></div> 10 11 <div class="about__section has-3-columns" style="text-align:center;"> 12 <div class="column has-subtle-background-color"> 13 <span style="font-size:3em;"><?php echo get_option('wp_telegram_dispatches'); ?></span> 14 <br> 15 messages sent 16 </div> 17 <div class="column has-subtle-background-color"> 18 <span style="font-size:3em;"><?php echo wp_count_posts('telegram_subscribers')->publish; ?></span> 19 <br> 20 subscribers 21 </div> 22 <div class="column has-subtle-background-color"> 23 <span style="font-size:3em;"><?php echo wp_count_posts('telegram_groups')->publish; ?></span> 24 <br> 25 groups 26 </div> 30 <div> 31 <a href="<?php echo esc_url($settings_url); ?>" class="button button-primary" style="font-size:1.1em;">⚙️ <?php _e('Settings', 'telegram-bot'); ?></a> 27 32 </div> 28 33 </div> 34 <div class="telegram-stats" style="display:flex;gap:32px;justify-content:space-between;margin:32px 0;"> 35 <div class="telegram-stat-card" style="flex:1;background:#f6f8fa;padding:32px 0;border-radius:12px;text-align:center;box-shadow:0 2px 8px #0001;"> 36 <div style="font-size:2.5em;color:#2271b1;font-weight:bold;"><?php echo $dispatches; ?></div> 37 <div style="color:#666;margin-top:8px;">Messages Sent</div> 38 </div> 39 <div class="telegram-stat-card" style="flex:1;background:#f6f8fa;padding:32px 0;border-radius:12px;text-align:center;box-shadow:0 2px 8px #0001;"> 40 <div style="font-size:2.5em;color:#46b450;font-weight:bold;"><?php echo $subscribers; ?></div> 41 <div style="color:#666;margin-top:8px;">Subscribers</div> 42 </div> 43 <div class="telegram-stat-card" style="flex:1;background:#f6f8fa;padding:32px 0;border-radius:12px;text-align:center;box-shadow:0 2px 8px #0001;"> 44 <div style="font-size:2.5em;color:#d63638;font-weight:bold;"><?php echo $groups; ?></div> 45 <div style="color:#666;margin-top:8px;">Groups</div> 46 </div> 47 </div> 48 <div class="telegram-actions" style="display:flex;gap:16px;justify-content:flex-end;margin-bottom:24px;"> 49 <a href="<?php echo esc_url($log_url); ?>" class="button button-secondary">📝 <?php _e('View Log', 'telegram-bot'); ?></a> 50 <a href="<?php echo esc_url(admin_url('admin.php?page=telegram_send')); ?>" class="button button-primary">✉️ <?php _e('Send Message', 'telegram-bot'); ?></a> 51 </div> 52 <div class="telegram-recent-log" style="background:#fff;border-radius:10px;box-shadow:0 1px 4px #0001;padding:24px;"> 53 <h2 style="margin-top:0;font-size:1.3em;"><?php _e('Recent Activity', 'telegram-bot'); ?></h2> 54 <?php if (!empty($recent_log)) : ?> 55 <table class="widefat striped" style="margin-top:12px;"> 56 <thead> 57 <tr> 58 <th><?php _e('Type', 'telegram-bot'); ?></th> 59 <th><?php _e('Date', 'telegram-bot'); ?></th> 60 <th><?php _e('Author', 'telegram-bot'); ?></th> 61 <th><?php _e('Description', 'telegram-bot'); ?></th> 62 </tr> 63 </thead> 64 <tbody> 65 <?php foreach ($recent_log as $line) : ?> 66 <tr> 67 <td><span style="font-weight:bold;color:#2271b1;"><?php echo isset($line[0]) ? esc_html($line[0]) : ''; ?></span></td> 68 <td><?php echo isset($line[1]) ? esc_html($line[1]) : ''; ?></td> 69 <td><?php echo isset($line[2]) ? esc_html($line[2]) : ''; ?></td> 70 <td><?php echo isset($line[3]) ? esc_html($line[3]) : ''; ?></td> 71 </tr> 72 <?php endforeach; ?> 73 </tbody> 74 </table> 75 <?php else : ?> 76 <div style="color:#888;text-align:center;padding:24px 0;">No recent activity found.</div> 77 <?php endif; ?> 78 </div> 79 <div class="telegram-quick-actions" style="margin-top:32px;display:flex;gap:24px;"> 80 <div style="flex:1;background:#f6f8fa;padding:20px 24px;border-radius:10px;"> 81 <h3 style="margin-top:0;">Subscriber Search</h3> 82 <form method="get" action="<?php echo esc_url(admin_url('edit.php')); ?>"> 83 <input type="hidden" name="post_type" value="telegram_subscribers" /> 84 <input type="search" name="s" style="width:100%;margin-bottom:8px;" placeholder="Search subscribers by name or ID..." /> 85 <button type="submit" class="button">Search</button> 86 </form> 87 </div> 88 </div> 89 <style> 90 .telegram-dashboard h1, .telegram-dashboard h2, .telegram-dashboard h3 { font-family: 'Segoe UI', 'Arial', sans-serif; } 91 .telegram-dashboard .button-primary { background:#2271b1;border-color:#2271b1; } 92 .telegram-dashboard .button-primary:hover { background:#1a5a8a;border-color:#1a5a8a; } 93 .telegram-dashboard .button-danger { background:#d63638;border-color:#d63638;color:#fff; } 94 .telegram-dashboard .button-danger:hover { background:#a00;border-color:#a00; } 95 </style> 29 96 </div> -
telegram-bot/tags/4.0/panel/send.php
r2790989 r3300993 4 4 $count = 0; 5 5 $send_to_custom_ids = false; 6 echo '<div class="wrap"><h2>'.__('Send a message', 'telegram-bot').'</h2>'; 6 echo '<div class="wrap telegram-send-panel" style="max-width:700px;margin:auto;">'; 7 echo '<h1 style="margin-bottom:24px;">' . __('Send a Message', 'telegram-bot') . '</h1>'; 7 8 if (isset($_POST["telegram_new_message"])) { 9 if (!isset($_POST['_wpnonce']) || !wp_verify_nonce($_POST['_wpnonce'], 'telegram_send_message')) { 10 wp_die(__('Security check failed.','telegram-bot')); 11 } 8 12 $message = $_POST["telegram_new_message"]; 9 13 … … 34 38 } 35 39 36 echo '<div class="notice notice-success"> 37 <p>Your message have been sent!</p> 38 </div>'; 40 echo '<div class="notice notice-success" style="margin-bottom:24px;"><p>' . __('Your message has been sent!', 'telegram-bot') . '</p></div>'; 39 41 } 40 echo '<form method="post" id="telegram_new_message">'; 42 echo '<form method="post" id="telegram_new_message" style="background:#fff;padding:32px 32px 24px 32px;border-radius:10px;box-shadow:0 2px 8px #0001;">'; 43 wp_nonce_field('telegram_send_message'); 41 44 if ( isset( $_GET['telegram_post_ids'] ) ) { 42 45 $telegram_post_ids = explode( ',', $_GET['telegram_post_ids']); 43 echo '<div class="notice notice-warning" ><p>Note: You are sending this message to <b>'.count( $telegram_post_ids ).' subscribers</b></p></div>';46 echo '<div class="notice notice-warning" style="margin-bottom:16px;"><p>' . __('Note: You are sending this message to', 'telegram-bot') . ' <b>' . count( $telegram_post_ids ) . ' ' . __('subscribers', 'telegram-bot') . '</b></p></div>'; 44 47 $send_to_custom_ids = true; 45 48 } 46 echo '<textarea name="telegram_new_message" cols="100" rows="10"></textarea><br>'; 49 echo '<label for="telegram_new_message" style="font-weight:bold;font-size:1.1em;">' . __('Message', 'telegram-bot') . '</label><br>'; 50 echo '<textarea name="telegram_new_message" id="telegram_new_message" cols="80" rows="7" style="width:100%;margin-bottom:18px;font-size:1.1em;"></textarea><br>'; 47 51 $target = $send_to_custom_ids ? 'custom_ids' : telegram_option('target'); 48 52 49 53 if ( !$send_to_custom_ids ) { 50 echo __('Send to', 'telegram-bot').':'; 51 ?> 52 <select name="telegram_target"> 53 <option value="0"><?php _e('Users, Groups, Channel', 'telegram-bot'); ?></option> 54 <option value="1"<?php if ($target==1 ) { echo ' selected="selected"'; } ?>><?php _e('Users', 'telegram-bot'); ?></option> 55 <option value="2"<?php if ($target==2 ) { echo ' selected="selected"'; } ?>><?php _e('Groups', 'telegram-bot'); ?></option> 56 <option value="3"<?php if ($target==3 ) { echo ' selected="selected"'; } ?>><?php _e('Users, Groups', 'telegram-bot'); ?></option> 57 <option value="4"<?php if ($target==4 ) { echo ' selected="selected"'; } ?>><?php _e('Channel', 'telegram-bot'); ?></option> 58 </select> 59 <?php } 60 61 submit_button( __('Send Now', 'telegram-bot'), 'primary'); 54 echo '<label for="telegram_target" style="font-weight:bold;">' . __('Send to', 'telegram-bot') . ':</label> '; 55 echo '<select name="telegram_target" id="telegram_target" style="margin-bottom:18px;">'; 56 echo '<option value="0"' . ($target == 0 ? ' selected' : '') . '>' . __('Users, Groups, Channel', 'telegram-bot') . '</option>'; 57 echo '<option value="1"' . ($target == 1 ? ' selected' : '') . '>' . __('Users', 'telegram-bot') . '</option>'; 58 echo '<option value="2"' . ($target == 2 ? ' selected' : '') . '>' . __('Groups', 'telegram-bot') . '</option>'; 59 echo '<option value="3"' . ($target == 3 ? ' selected' : '') . '>' . __('Users, Groups', 'telegram-bot') . '</option>'; 60 echo '<option value="4"' . ($target == 4 ? ' selected' : '') . '>' . __('Channel', 'telegram-bot') . '</option>'; 61 echo '</select><br>'; 62 } 63 echo '<button type="submit" class="button button-primary" style="font-size:1.1em;padding:8px 32px;">' . __('Send Now', 'telegram-bot') . '</button>'; 62 64 echo '</form>'; 63 65 echo '<style>.telegram-send-panel textarea { font-family: inherit; } .telegram-send-panel .notice-success { border-left: 4px solid #46b450; } .telegram-send-panel .notice-warning { border-left: 4px solid #ffb900; }</style>'; 64 66 echo '</div>'; 65 67 } -
telegram-bot/tags/4.0/panel/settings.php
r3110498 r3300993 1 <?php function telegram_settings_page() { ?> 1 <?php 2 // Security: Only allow admins to view this page 3 if (!current_user_can('manage_options')) { 4 wp_die(__('You do not have sufficient permissions to access this page.')); 5 } 2 6 3 <div class="wrap"> 4 <h2>Settings</h2> 7 $options = get_option('wp_telegram'); 8 foreach ($options as $k => $v) { 9 $options[$k] = esc_attr($v); 10 } 5 11 6 <?php if ( $_SERVER["SERVER_ADDR"] == '127.0.0.1' ) { 7 echo '<div class="notice notice-warning"><p>'.__('Warning: the plugin <b>does not</b> work in localhost environments!', 'telegram-bot').'</p></div>'; 8 } ?> 9 10 <form method="post" action="options.php"> 11 <?php 12 settings_fields( 'wp_telegram_options'); 13 $options=get_option( 'wp_telegram'); 14 foreach( $options as $k => $v ) { 15 $options[$k] = esc_attr( $v ); 16 } 17 18 if ( isset($_GET['settings-updated']) ) { 19 20 $url=telegram_geturl() . 'setWebhook?url=' . telegram_getapiurl(); 21 22 json_decode(file_get_contents($url), true); 23 telegram_log( 'sys', 'Webhook update', $url); 24 } 25 ?> 26 27 <table class="form-table"> 28 <tr valign="top"> 29 <th scope="row"> 30 <label for="apikey">Plugin Api Key 31 </label> 32 </th> 33 <td> 34 <input readonly="readonly" id="apikey" type="text" name="wp_telegram_apikey" value="<?php echo get_option('wp_telegram_apikey'); ?>" size="55" /> 35 <br> 36 <small>The unique key for your website: <b>Keep it secret!</b></small> 37 </td> 38 </tr> 39 <tr valign="top"> 40 <th scope="row"> 41 <label for="token">Bot Token<br><span style="background:darkred;font-size:0.8em;padding:2px;color:white;"><?php _e('Required', 'telegram-bot'); ?></span></label> 42 </th> 43 <td> 44 <input id="token" type="text" name="wp_telegram[token]" value="<?php echo $options['token']; ?>" size="55" /> 45 <br> 46 <small><?php _e( 'Paste here your bot token. You can obtain it from Telegram <b>BotFather</b>', 'telegram-bot'); ?></small> 47 </td> 48 </tr 49 <tr valign="top"> 50 <th scope="row"> 51 <label for="username">Bot Username<br><span style="background:darkred;font-size:0.8em;padding:2px;color:white;"><?php _e('Required', 'telegram-bot'); ?></span></label> 52 </th> 53 <td> 54 <input id="username" type="text" name="wp_telegram[username]" value="<?php echo isset( $options['username'] ) ? $options['username'] : ''; ?>" size="55" /> 55 <br> 56 <small>Telegram Bot username. Example: <b>mywebsite_bot</b></small> 57 </td> 58 </tr> 59 <tr valign="top"> 60 <th scope="row"> 61 <label for="channelusername"> 62 <?php _e('Channel Username', 'telegram-bot'); ?> 63 </label> 64 </th> 65 <td> 66 <input id="channelusername" type="text" name="wp_telegram[channelusername]" value="<?php echo isset( $options['channelusername'] ) ? $options['channelusername'] : ''; ?>" size="55" /> 67 <br> 68 <small>Insert your channel username (if you want to broadcast). Example: <b>@mywebsite</b> 69 <br>The bot must be admin in your channel 70 </small> 71 </td> 72 </tr> 73 <tr valign="top"> 74 <th scope="row"> 75 <label> 76 Webhook 77 </label> 78 </th> 79 <td> 80 <a class="page-title-action" onclick="alert('<?php echo telegram_getapiurl(); ?>');">Show private endpoint</a> 81 <p style="font-size:0.9em;"> 82 This is your private Telegram webhook. Please keep it private and make sure it bypasses cache and firewall. 12 // Handle webhook update after settings are saved 13 if (isset($_GET['settings-updated'])) { 14 $url = telegram_geturl() . 'setWebhook?url=' . telegram_getapiurl(); 15 json_decode(@file_get_contents($url), true); 16 telegram_log('sys', 'Webhook update', $url); 17 } 18 ?> 19 <div class="wrap telegram-settings" style="max-width:900px;margin:auto;"> 20 <h1 style="margin-bottom:24px;"><?php _e('Telegram Bot Settings', 'telegram-bot'); ?></h1> 21 <p style="font-size:1.1em;"> 22 <?php _e('This plugin is capable of broadcasting to channel and creating interactive bots.', 'telegram-bot'); ?><br> 23 <?php _e('You need to create a bot with BotFather and obtain the token.', 'telegram-bot'); ?><br> 24 <?php _e('To broadcast to a channel, add the bot as admin in your channel.', 'telegram-bot'); ?> 25 </p> 26 <?php if ($_SERVER["SERVER_ADDR"] == '127.0.0.1') { 27 echo '<div class="notice notice-warning"><p>' . __('Warning: the plugin <b>does not</b> work in localhost environments!', 'telegram-bot') . '</p></div>'; 28 } ?> 29 <form method="post" action="options.php"> 30 <?php settings_fields('wp_telegram_options'); ?> 31 <div id="telegram-tabs" style="margin-top:32px;"> 32 <nav class="nav-tab-wrapper"> 33 <a href="#tab-general" class="nav-tab nav-tab-active">General</a> 34 <a href="#tab-broadcast" class="nav-tab">Broadcast</a> 35 <a href="#tab-bot" class="nav-tab">Bot</a> 36 </nav> 37 <div id="tab-general" class="telegram-tab-content" style="display:block;"> 38 <table class="form-table"> 39 <tr valign="top"> 40 <th scope="row"><label for="apikey">Plugin Api Key</label></th> 41 <td> 42 <input readonly="readonly" id="apikey" type="text" name="wp_telegram_apikey" value="<?php echo get_option('wp_telegram_apikey'); ?>" size="55" /> 43 <br><small><?php _e('The unique key for your website: <b>Keep it secret!</b>', 'telegram-bot'); ?></small> 44 </td> 45 </tr> 46 <tr valign="top"> 47 <th scope="row"><label for="token">Bot Token</label></th> 48 <td> 49 <input id="token" type="text" name="wp_telegram[token]" value="<?php echo $options['token']; ?>" size="55" autocomplete="off" /> 50 <br><small><?php _e('Telegram Bot authentication key. <b>Keep it secret!</b>', 'telegram-bot'); ?></small> 51 </td> 52 </tr> 53 <tr valign="top"> 54 <th scope="row"><label for="username">Bot Username</label></th> 55 <td> 56 <input id="username" type="text" name="wp_telegram[username]" value="<?php echo isset($options['username']) ? $options['username'] : ''; ?>" size="55" /> 57 <br><small><?php _e('Telegram Bot username. Example: <b>mywebsite_bot</b>', 'telegram-bot'); ?></small> 58 </td> 59 </tr> 60 <tr valign="top"> 61 <th scope="row"><label for="channelusername"><?php _e('Channel Username', 'telegram-bot'); ?></label></th> 62 <td> 63 <input id="channelusername" type="text" name="wp_telegram[channelusername]" value="<?php echo isset($options['channelusername']) ? $options['channelusername'] : ''; ?>" size="55" /> 64 <br><small><?php _e('Insert your channel username (if you want to broadcast). Example: <b>@mywebsite</b><br>The bot must be admin in your channel', 'telegram-bot'); ?></small> 65 </td> 66 </tr> 67 <tr valign="top"> 68 <th scope="row"><label for="mode"><?php _e('Connection Mode', 'telegram-bot'); ?></label></th> 69 <td> 70 <select name="wp_telegram[mode]" disabled> 71 <option value="0" selected><?php _e('Telegram WebHooks (required)', 'telegram-bot'); ?></option> 72 </select> 73 <br><small><?php _e('Telegram WebHooks are now required. SSL is mandatory for webhook delivery.', 'telegram-bot'); ?></small> 74 </td> 75 </tr> 76 <tr valign="top"> 77 <th scope="row"><label>Webhook</label></th> 78 <td> 79 <a class="page-title-action" onclick="alert('<?php echo telegram_getapiurl(); ?>');">Show private endpoint</a> 80 <p style="font-size:0.9em;"> 81 <?php _e('This is your private Telegram webhook. Please keep it private and make sure it bypasses cache and firewall.', 'telegram-bot'); ?> 82 </p> 83 </td> 84 </tr> 85 <tr valign="top"> 86 <th scope="row"><label for="zapier"><?php _e('Enable Zapier', 'telegram-bot'); ?></label></th> 87 <td> 88 <input id="zapier" name="wp_telegram[zapier]" type="checkbox" value="1" <?php checked('1', (isset($options['zapier']) && $options['zapier']) ? 1 : 0); ?> /> 89 <br><small><?php _e('Enable Zapier integration • Beta •', 'telegram-bot'); ?> 90 <a href="https://zapier.com/developer/invite/26805/1ec54299d4307c0b86b7417d0866ff25/" target="_blank">Click here to get an invite</a> 91 </small> 92 </td> 93 </tr> 94 </table> 95 </div> 96 <div id="tab-broadcast" class="telegram-tab-content" style="display:none;"> 97 <table class="form-table"> 98 <tr valign="top"> 99 <td colspan="2"> 100 <h3><?php _e('Posts broadcast', 'telegram-bot'); ?></h3> 101 <p><?php _e('You can send post or custom post to Telegram when you publish or edit it.', 'telegram-bot'); ?></p> 102 </td> 103 </tr> 104 <tr valign="top"> 105 <th scope="row"><label for="target"><?php _e('Default content broadcast', 'telegram-bot'); ?></label></th> 106 <td> 107 <select name="wp_telegram[target]"> 108 <option><?php _e('Users, Groups, Channel', 'telegram-bot'); ?></option> 109 <option value="1"<?php if (isset($options['target']) && $options['target'] == 1) { echo ' selected="selected"'; } ?>><?php _e('Users', 'telegram-bot'); ?></option> 110 <option value="2"<?php if (isset($options['target']) && $options['target'] == 2) { echo ' selected="selected"'; } ?>><?php _e('Groups', 'telegram-bot'); ?></option> 111 <option value="3"<?php if (isset($options['target']) && $options['target'] == 3) { echo ' selected="selected"'; } ?>><?php _e('Users, Groups', 'telegram-bot'); ?></option> 112 <option value="4"<?php if (isset($options['target']) && $options['target'] == 4) { echo ' selected="selected"'; } ?>><?php _e('Channel', 'telegram-bot'); ?></option> 113 <option value="5"<?php if (isset($options['target']) && $options['target'] == 5) { echo ' selected="selected"'; } ?>><?php _e('All', 'telegram-bot'); ?></option> 114 </select> 115 <br><small><?php _e('Define the post broadcast targeting when you send content (for example posts or manual text).<br>You can also change this behaviour manually.', 'telegram-bot'); ?></small> 116 </td> 117 </tr> 118 <tr valign="top"> 119 <th scope="row"><label for="posttemplate"><?php _e('Post Template', 'telegram-bot'); ?></label></th> 120 <td> 121 <textarea id="posttemplate" rows="4" class="widefat" name="wp_telegram[posttemplate]"><?php echo $options['posttemplate']; ?></textarea> 122 <br><small><?php _e('Allowed placeholders: <b>%TITLE% %LINK% %EXCERPT% %CHAT_ID%</b>', 'telegram-bot'); ?></small> 123 </td> 124 </tr> 125 </table> 126 </div> 127 <div id="tab-bot" class="telegram-tab-content" style="display:none;"> 128 <table class="form-table"> 129 <tr valign="top"> 130 <td colspan="2"> 131 <h3><?php _e('Interactive bot', 'telegram-bot'); ?></h3> 132 <p><?php _e('Only use this section if you want to build an interactive bot', 'telegram-bot'); ?></p> 133 </td> 134 </tr> 135 <tr valign="top"> 136 <th scope="row"><label for="wmuser"><?php _e('Start Message', 'telegram-bot'); ?><br><small><?php _e('for users', 'telegram-bot'); ?></small></label></th> 137 <td> 138 <input id="wmuser" type="text" name="wp_telegram[wmuser]" value="<?php echo $options['wmuser']; ?>" size="55" /> 139 <br><small><?php _e('Cannot be blank', 'telegram-bot'); ?>.</small> 140 </td> 141 </tr> 142 <tr valign="top"> 143 <th scope="row"><label for="bmuser"><?php _e('Bye Message', 'telegram-bot'); ?><br><small><?php _e('for Private Conversations', 'telegram-bot'); ?></small></label></th> 144 <td> 145 <input id="bmuser" type="text" name="wp_telegram[bmuser]" value="<?php echo $options['bmuser']; ?>" size="55" /> 146 <br><small><?php _e('Cannot be blank', 'telegram-bot'); ?>.</small> 147 </td> 148 </tr> 149 <tr valign="top"> 150 <th scope="row"><label for="emuser"><?php _e('Error Message', 'telegram-bot'); ?><br><small><?php _e('for users', 'telegram-bot'); ?></small></label></th> 151 <td> 152 <input id="emuser" type="text" name="wp_telegram[emuser]" value="<?php echo isset($options['emuser']) ? $options['emuser'] : ''; ?>" size="55" /> 153 <br><small><?php _e('This will be shown when the command doesn\'t exist.', 'telegram-bot'); ?></small> 154 </td> 155 </tr> 156 <tr valign="top"> 157 <th scope="row"><label for="wmgroup"><?php _e('Start Message', 'telegram-bot'); ?><br><small><?php _e('for Groups', 'telegram-bot'); ?></small></label></th> 158 <td> 159 <input id="wmgroup" type="text" name="wp_telegram[wmgroup]" value="<?php echo $options['wmgroup']; ?>" size="55" /> 160 <br><small><?php _e('Cannot be blank', 'telegram-bot'); ?>.</small> 161 </td> 162 </tr> 163 <tr valign="top"> 164 <th scope="row"><label for="keyboard"><?php _e('Keyboard Template', 'telegram-bot'); ?><br><small><?php _e('for users', 'telegram-bot'); ?></small></label></th> 165 <td> 166 <input id="keyboard" type="text" name="wp_telegram[keyboard]" value="<?php echo $options['keyboard']; ?>" size="55" /> 167 <br><small><?php _e('Example: <b>1,2,3;4,5,6;Text</b>', 'telegram-bot'); ?></small> 168 </td> 169 </tr> 170 </table> 171 </div> 172 </div> 173 <div class="clear"></div> 174 <hr> 175 <p class="submit"> 176 <input type="submit" class="button-primary" value="<?php _e('Save Changes'); ?>" /> 83 177 </p> 84 </td> 85 </tr> 86 <tr valign="top"> 87 <th scope="row"> 88 <label for="zapier"> 89 <?php _e('Enable Zapier', 'telegram-bot'); ?> 90 </label> 91 </th> 92 <td> 93 <input id="zapier" name="wp_telegram[zapier]" type="checkbox" value="1" 94 <?php checked( '1', ( isset( $options[ 'zapier'] ) && $options[ 'zapier'] ) ? 1 : 0 ); ?> /> 95 <br> 96 <small>Zapier allows you to send messages from your own platforms 97 <a href="https://zapier.com/developer/public-invite/88225/1d9f5d9ec76cde2aac6e356298aee8e8/">Click here to get an invite</a> 98 </small> 99 </td> 100 </tr> 101 <tr valign="top"> 102 <td colspan="2"> 103 <h3><?php _e('Posts broadcast', 'telegram-bot'); ?></h3> 104 <p><?php _e('You can send post or custom post to Telegram when you publish or edit it.', 'telegram-bot'); ?></p> 105 <p><?php _e('If you want to broadcast to a channel, please add the bot as admin in your channel.', 'telegram-bot'); ?></p> 106 </td> 107 </tr> 108 <tr valign="top"> 109 <th scope="row"> 110 <label for="mode"> 111 <?php _e('Default content broadcast', 'telegram-bot'); ?> 112 </label> 113 </th> 114 <td> 115 <select name="wp_telegram[target]"> 116 <option><?php _e('Users, Groups, Channel', 'telegram-bot'); ?></option> 117 <option value="1"<?php if (isset($options['target'])&&$options['target']==1 ) { echo ' selected="selected"'; } ?>><?php _e('Users', 'telegram-bot'); ?></option> 118 <option value="2"<?php if (isset($options['target'])&&$options['target']==2 ) { echo ' selected="selected"'; } ?>><?php _e('Groups', 'telegram-bot'); ?></option> 119 <option value="3"<?php if (isset($options['target'])&&$options['target']==3 ) { echo ' selected="selected"'; } ?>><?php _e('Users, Groups', 'telegram-bot'); ?></option> 120 <option value="4"<?php if (isset($options['target'])&&$options['target']==4 ) { echo ' selected="selected"'; } ?>><?php _e('Channel', 'telegram-bot'); ?></option> 121 <option value="5"<?php if (isset($options['target'])&&$options['target']==5 ) { echo ' selected="selected"'; } ?>><?php _e('All', 'telegram-bot'); ?></option> 122 </select> 123 <br> 124 <small> 125 <?php _e('Define the post broadcast targeting when you send content (for example posts or manual text).', 'telegram-bot'); ?> 126 <br> 127 <?php _e('You can also change this behaviour manually.', 'telegram-bot'); ?> 128 </small> 129 </td> 130 </tr> 131 <tr valign="top"> 132 <th scope="row"> 133 <label for="posttemplate"><?php _e('Post Template', 'telegram-bot'); ?></label> 134 </th> 135 <td> 136 <textarea id="posttemplate" rows="4" class="widefat" name="wp_telegram[posttemplate]"><?php echo $options['posttemplate']; ?></textarea> 137 <br><small><?php _e('Allowed placeholders: <b>%TITLE% %LINK% %EXCERPT% %CHAT_ID%</b>', 'telegram-bot'); ?></small> </td></td> 138 </tr> 139 <tr valign="top"> 140 <td colspan="2"> 141 <h3><?php _e('Interactive bot', 'telegram-bot'); ?></h3> 142 <p>Only use this section if you want to build an interactive bot</p> 143 </td> 144 </tr> 145 <tr valign="top"> 146 <th scope="row"> 147 <label for="wmuser"> 148 <?php _e('Start Message', 'telegram-bot'); ?> 149 <br> 150 <small> 151 <?php _e('for users', 'telegram-bot'); ?> 152 </small> 153 </label> 154 </th> 155 <td> 156 <input id="wmuser" type="text" name="wp_telegram[wmuser]" value="<?php echo $options['wmuser']; ?>" size="55" /> 157 <br> 158 <small> 159 <?php _e('Cannot be blank', 'telegram-bot'); ?>. 160 </small> 161 </td> 162 </tr> 163 <tr valign="top"> 164 <th scope="row"> 165 <label for="bmuser"> 166 <?php _e('Bye Message', 'telegram-bot'); ?> 167 <br> 168 <small> 169 <?php _e('for Private Conversations', 'telegram-bot'); ?> 170 </small> 171 </label> 172 </th> 173 <td> 174 <input id="bmuser" type="text" name="wp_telegram[bmuser]" value="<?php echo $options['bmuser']; ?>" size="55" /> 175 <br> 176 <small> 177 <?php _e('Cannot be blank', 'telegram-bot'); ?>. 178 </small> 179 </td> 180 </tr> 181 <tr valign="top"> 182 <th scope="row"> 183 <label for="emuser"> 184 <?php _e('Error Message', 'telegram-bot'); ?> 185 <br> 186 <small> 187 <?php _e('for users', 'telegram-bot'); ?> 188 </small> 189 </label> 190 </th> 191 <td> 192 <input id="emuser" type="text" name="wp_telegram[emuser]" value="<?php echo isset( $options['emuser'] ) ? $options['emuser'] : ''; ?>" size="55" /> 193 <br> 194 <small><?php _e('This will be shown when the command doesn\'t exist.', 'telegram-bot'); ?></small> 195 </td> 196 </tr> 197 <tr valign="top"> 198 <th scope="row"> 199 <label for="wmgroup"> 200 <?php _e('Start Message', 'telegram-bot'); ?> 201 <br> 202 <small>for Groups 203 </small> 204 </label> 205 </th> 206 <td> 207 <input id="wmgroup" type="text" name="wp_telegram[wmgroup]" value="<?php echo $options['wmgroup']; ?>" size="55" /> 208 <br> 209 <small> 210 <?php _e('Cannot be blank', 'telegram-bot'); ?>. 211 </small> 212 </td> 213 </tr> 214 <tr valign="top"> 215 <th scope="row"> 216 <label for="keyboard"> 217 <?php _e('Keyboard Template', 'telegram-bot'); ?> 218 <br> 219 <small><?php _e('for users', 'telegram-bot'); ?></small> 220 </label> 221 </th> 222 <td> 223 <input id="keyboard" type="text" name="wp_telegram[keyboard]" value="<?php echo $options['keyboard']; ?>" size="55" /> 224 <br> 225 <small><?php _e('Example: <b>1,2,3;4,5,6;Text</b>', 'telegram-bot'); ?></small> 226 </td> 227 </tr> 228 </table> 229 230 <p class="submit"> 231 <input type="submit" class="button-primary" value="<?php _e('Save Changes'); ?>" /> 232 </p> 233 </form> 178 </form> 179 <style> 180 .telegram-settings .nav-tab-wrapper { margin-bottom: 0; } 181 .telegram-settings .nav-tab { font-size: 1.1em; } 182 .telegram-settings .telegram-tab-content { background: #fff; border: 1px solid #ccd0d4; border-top: none; padding: 24px 32px; border-radius: 0 0 8px 8px; } 183 .telegram-settings table.form-table { width: 100%; } 184 .telegram-settings th { width: 220px; } 185 </style> 186 <script> 187 (function(){ 188 const tabs = document.querySelectorAll('.nav-tab'); 189 const contents = document.querySelectorAll('.telegram-tab-content'); 190 tabs.forEach(tab => { 191 tab.addEventListener('click', function(e) { 192 e.preventDefault(); 193 tabs.forEach(t => t.classList.remove('nav-tab-active')); 194 this.classList.add('nav-tab-active'); 195 contents.forEach(c => c.style.display = 'none'); 196 const sel = this.getAttribute('href'); 197 document.querySelector(sel).style.display = 'block'; 198 }); 199 }); 200 })(); 201 </script> 234 202 </div> 235 <?php } ?> -
telegram-bot/tags/4.0/parse.php
r2981438 r3300993 3 3 4 4 if (!$json) { 5 telegram_log(' Warning','Webhook URL','Endpoint was called without input.');5 telegram_log('returned','',''); 6 6 return; 7 7 } … … 13 13 die(); 14 14 } 15 update_option('wp_telegram_last_id', $data['message']['message_id'] );15 update_option('wp_telegram_last_id', $data['message']['message_id']); 16 16 17 17 if ( $data['message']['chat']['type'] == 'private' ) { … … 25 25 $GROUP = true; $PRIVATE = false; 26 26 $COMMAND = $data['message']['text']; 27 } else if ( $data['my_chat_member']['chat']['type'] == 'supergroup' ) {28 $USERID = $data['my_chat_member']['chat']['id'];29 $CPT = 'telegram_groups';30 $GROUP = true; $PRIVATE = false;31 $COMMAND = '';32 27 } else if ( $data['callback_query']['message']['text'] ) { 33 28 $USERID = $data['callback_query']['message']['chat']['id']; … … 60 55 telegram_sendmessage( $USERID, telegram_option('wmuser') ); 61 56 } else if ( $GROUP ) { 62 $name = ''; 63 if ( isset( $data['message']['chat']['title'] ) ) { 64 $name = $data['message']['chat']['title']; 65 } else if ( isset( $data['my_chat_member']['chat']['title'] ) ) { 66 $name = $data['my_chat_member']['chat']['title']; 67 } 68 update_post_meta($p, 'telegram_name', $name ); 57 update_post_meta($p, 'telegram_name', $data['message']['chat']['title']); 69 58 telegram_log('', '', 'Bot added to <strong>'.$data['message']['chat']['title'].'</strong>'); 70 59 telegram_sendmessage( $USERID, telegram_option('wmgroup') ); … … 83 72 update_post_meta( $POST_ID, 'telegram_counter', $counter ); 84 73 } else if ($GROUP) { 85 update_post_meta($o->ID, 'telegram_name', 'xx');74 update_post_meta($o->ID, 'telegram_name', $data['message']['chat']['title']); 86 75 } 87 76 -
telegram-bot/tags/4.0/readme.txt
r3110525 r3300993 1 1 === Telegram Bot & Channel === 2 Contributors: Milmor 3 Version: 3.8.24 Stable tag: 3.8.25 Author: Marco Milesi6 Author URI: https://profiles.wordpress.org/milmor/2 Contributors: Milmor, marcomilesi 3 Version: 4.0 4 Stable tag: 4.0 5 Author: Marco Milesi 6 Author URI: https://profiles.wordpress.org/milmor/ 7 7 Donate link: https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=F2JK36SCXKTE2 8 Tags: telegram, bot, newsletter, channel, group, automatic, stream, classicpress9 Requires at least: 3.810 Requires PHP: 5.611 Tested up to: 6. 58 Tags: telegram, bot, newsletter, channel, group, broadcast, automation, notifications, autoresponder, webhook, ssl, zapier, integration, marketing, customer-engagement, chatbot, wordpress, classicpress 9 Requires at least: 4.6 10 Requires PHP: 7.0 11 Tested up to: 6.9 12 12 License: GPLv2 or later 13 13 License URI: http://www.gnu.org/licenses/gpl-2.0.html 14 14 15 S end your posts to Telegram and build an interactive bot. Zapier integrated!15 Supercharge your WordPress site with Telegram! Broadcast posts, automate notifications, and build interactive bots for your users, groups, and channels. Secure, modern, and easy to use. Zapier integration included! 16 16 17 17 == Description == 18 18 19 This plugin allows you to accomplish a variety of tasks, including teaching, playing, searching, broadcasting, reminding, connecting, and integrating with your services. 20 21 With this powerful bot builder, you can: 22 23 🤖 **Build a bot**: create interactive autoresponders for users and groups 24 📣 **Broadcast to a channel**: utilize the broadcast feature to send messages to your channels and bot subscribers 25 26 https://youtu.be/8fckoWSmAks 27 28 = Bot features = 29 30 Enhance your content distribution strategy with these **free** advanced features: 31 32 📰 Send your content (post, page or custom messages) with templates 33 📅 Support for scheduled post broadcast 34 ⌨️ Utilize **keyboards** and **inline buttons** for enhanced user engagement 35 💬 Broadcast to various channels including chats, groups, supergroups, and channels 36 ↩️ Create unlimited autoresponders 37 📊 View insights about users and groups subscribed to your bot 38 📡 Haversine algorithm to get users' location and provide geo-focused content 39 🎨 Create custom applicatons with **/$command $var1 $var2** format for custom application creation 40 💡 **[Zapier](https://zapier.com)** integration to ensure seamless connectivity with your other tools 41 42 = Channel features = 43 📰 Send your content (post, page or custom messages) with configurable templates 44 📅 Support for scheduled post broadcast 45 💡 **[Zapier](https://zapier.com)** integration 46 47 **Note:** your bot must be administrator of your channel for sending messages 48 49 🔐 Every connection relies on secure webhooks for maximum security. Telegram requires **SSL** to manage a Telegram Bot. If you don't have it, just choose the free opt-in service [botpress.org](https://botpress.org) in options (the feature will send some data to our server). 50 51 = Zapier and IoT features = 52 Zapier makes it easy to automate tasks between web apps. For example: 53 54 * send a news published on a website (based on RSS) 55 * send the weather to your subscribers, every day 56 * inform users when you upload an image on Instagram 57 * and much more… With 400+ Zapier Apps supported! 58 59 https://www.youtube.com/watch?v=14aEV0_FHFk 60 61 = DEMO = 62 * **[CosenzApp_bot](http://telegram.me/CosenzApp_bot)** (italian) - Guide for Cosenza city 63 Want to showcase your work? contact us! 19 **Telegram Bot & Channel** is the all-in-one solution to connect your WordPress site with Telegram. Instantly broadcast posts, automate notifications, and create interactive bots for your audience. No coding required! 20 21 **Key Features:** 22 - 🤖 **Bot builder:** Create interactive autoresponders for users and groups 23 - 📣 **Broadcast:** Send posts, pages, or custom messages to your channels, groups, and subscribers 24 - 🔔 **Automated notifications:** Instantly notify your audience about new content 25 - 🔗 **Zapier integration:** Connect Telegram with 400+ apps and automate your workflows 26 - 🔐 **Secure:** All connections use Telegram WebHooks and require SSL for maximum security 27 - 🛡️ **Modern UI:** Clean, user-friendly admin panels with stats, logs, and quick actions 28 29 **Why choose this plugin?** 30 - 100% free and open source 31 - No third-party servers: your data stays on your site 32 - Easy setup: just add your bot token and go 33 - Developer-friendly: extend with custom PHP actions and filters 34 35 == Features == 36 37 **Bot & Broadcast:** 38 - Send posts, pages, or custom messages with flexible templates 39 - Schedule broadcasts for future posts 40 - Use custom keyboards and inline buttons for rich user interaction 41 - Broadcast to users, groups, supergroups, and channels 42 - Unlimited autoresponders and command triggers 43 - View insights about your Telegram audience 44 - Haversine algorithm for geo-targeted content 45 - Create custom applications with command variables 46 47 **Zapier & Automation:** 48 - Connect Telegram to 400+ apps (RSS, Instagram, Google Sheets, and more) 49 - Automate news, weather, social, and IoT notifications 50 - Easy Zapier invite and setup 51 52 **Security & Privacy:** 53 - All actions protected by WordPress nonces (CSRF protection) 54 - Only supports secure Telegram WebHooks (SSL required) 55 - No data sent to third-party servers (except optional Zapier integration) 56 57 **Screenshots:** 58 1. Modern dashboard with stats and recent activity 59 2. Subscribers list 60 3. Commands and autoresponders 61 4. Zapier integration 62 5. Plugin settings with tabs 63 6. Dynamic replies and inline buttons 64 7. Keyboard example 65 8. Post broadcasting 66 9. Native Gutenberg support 64 67 65 68 == Installation == 66 This section describes how to install the plugin and get it working. 67 68 1. Upload `telegram-bot` directory to the `/wp-content/plugins/` directory 69 2. Activate the plugin through the 'Plugins' menu in WordPress 69 1. Upload the `telegram-bot` directory to `/wp-content/plugins/` 70 2. Activate the plugin in the WordPress admin 70 71 3. Go to the Telegram settings page 71 4. Go through the steps and hit update! 72 4. Enter your bot token and configure your preferences 73 5. Enjoy automated Telegram notifications and bot features! 72 74 73 75 == Frequently Asked Questions == 74 More documentation is available on [www.botpress.org/docs](https://www.botpress.org/docs) 75 76 = How do I create a bot? = 77 [www.botpress.org/docs/telegram/how-to-create-a-bot](https://www.botpress.org/docs/telegram/how-to-create-a-bot/) 78 79 = How can i let users subscribe? = 80 [www.botpress.org/docs/telegram/how-do-users-subscribe](https://www.botpress.org/docs/telegram/how-do-users-subscribe/) 81 82 = What is Zapier and how do i integrate it? = 83 [www.botpress.org/docs/telegram/zapier-integration](https://www.botpress.org/docs/telegram/zapier-integration/) 84 85 = How to enable debug mode? = 86 If you are a developer, or just want a more complete "Telegram > Log" enable WP_DEBUG mode. 87 The plugin debug mode also allows to explore Telegram users and groups as standard posts. This let you to check custom fields for each users and modify them in real time. You'll notice a new column (= Telegram id for the user) in Subscribers and Groups page. 88 We don't suggest to keep WP_DEBUG if not for testing purposes. 89 90 = How to make dynamic replies? (PHP required) = 91 The best way to integrate PHP code is to build a custom integration plugin, but you can also add PHP to /$commands directly in your WordPress admin dashboard using the [Insert Php](https://wordpress.org/plugins/insert-php) plugin. 92 93 In case you want to scale and choose the first option, you can create a new file called **telegram-bot-custom.php** and upload it to wp-content/plugins. 94 95 The following example, once activated in the plugins list, will reply to `/command`: 96 97 `<?php 98 /* 99 Plugin Name: Telegram Bot & Channel (Custom) 100 Description: My Custom Telegram Plugin 101 Author: My name 102 Version: 1 103 */ 104 105 add_action('telegram_parse','telegramcustom_parse', 10, 2); 106 107 function telegramcustom_parse( $telegram_user_id, $text ) { 108 $plugin_post_id = telegram_getid( $telegram_user_id ); 109 110 if ( !$plugin_post_id ) { 111 return; 112 } 113 114 /* 115 Here is the dynamic processing and how to reply. 116 You can: 117 - use if, switch and everything that works in php 118 - check if $text is made of multiple words (create an array from $text) 119 - customize and code other actions (ex. create WordPress post is $telegram_user_id is your id) 120 */ 121 122 if ( $text == '/command') { 123 telegram_sendmessage( $telegram_user_id, 'Oh, yes you typed /command'); 124 } 125 126 return; 127 } 128 129 ?>` 130 131 = How to set up dynamic keyboards? = 132 You can send custom keyboards directly in php. Every keyboard can be set only when you send a message, and is kept in the client side until another keyboard is sent (in another message). You can also change this behaviour by setting the $one_time_keyboard true or false. 133 134 `telegram_sendmessage( $telegram_user_id, 'Hello from the other side!'); //Message with no keyboard (or with default one if set in plugin options) 135 telegram_sendmessage( $telegram_user_id, 'Hello from the other side!', telegram_build_reply_markup( '11,12,13;21,22', true )); //Message with custom keyboard` 136 137 Here is the details of telegram_build_reply_markup (an array is returned): 138 `telegram_build_reply_markup( 139 '11,12,13;21,22', //The keyboard template (eg. 2 row, 3 columns for the first one and two columns for the second one 140 true, // $one_time_keyboard (optional) (default false = kept until a new keyboard is sent) (true = kept until the user send something to the bot) 141 true // $resize_keyboard (optional) (default true) 142 );` 143 144 You can also alter keyboards for commands defined in the **admin area**. Start from the previous custom plugin created, and add the following filter: 145 146 `add_filter( 'telegram_get_reply_markup_filter', 'telegram_get_reply_markup_filter_custom', 1 ); 147 148 function telegram_get_reply_markup_filter_custom( $id ) { 149 if ( $id ) { 150 switch ( $id ) { 151 case 7: //Your command ID (found in the url while editing the command) 152 telegram_log('####', $id, 'custom keyboard'); //Useful for debug 153 return array( 154 'keyboard' => array(array('Top Left', 'Top Right'),array('Bottom')), 155 'resize_keyboard' => true, //true or false (suggested: true) 156 'one_time_keyboard' => true //true or false 157 ); 158 default: 159 return; 160 } 161 } 162 }` 163 164 = How to get user location? = 165 It's easy, with harvesine algorithm (one-point radius) or standard geolocation (4-points). 166 These snippets only cover the harvesine algorithm, that is simple and supported by the plugin. To use the standard 4-points geolocation it's enough to do some php-calc with basic if-then structures. 167 168 You can start from the previous custom plugin created, and add the following action: 169 170 `add_action('telegram_parse_location','telegramcustom_c_parse_location', 10, 3); 171 172 function telegramcustom_c_parse_location ( $telegram_user_id, $lat, $long ) { 173 174 if ( telegram_location_haversine_check ( 45.85, 9.70, $lat, $long, 20 ) ) { 175 telegram_sendmessage( $telegram_user_id, 'Inside the radius'); 176 } 177 178 }` 179 180 The examples sends a "Inside the radius" message when the user is inside the **20-meters** radius centered in 45.85 Lat, 9.70 Long. 181 182 You have two developer functions to use: 183 184 `//Check if point is within a distance (max_distance required) 185 $boolean = telegram_location_haversine_check ( $latitudeFrom, $longitudeFrom, $latitudeTo, $longitudeTo, $max_distance, $min_distance = 0, $earthRadius = 6371000); 186 187 //Calculate the distance 188 $int = telegram_location_haversine_distance ( $latitudeFrom, $longitudeFrom, $latitudeTo, $longitudeTo, $earthRadius = 6371000);` 189 190 The first function returns a boolean (true/false) depending on given parameters. Please note that $min_distance and $earthRadius are optional. 191 The second one returns a int (in meters) of the distance. $earthRadius optional. 192 193 Both the functions calculates distances on meters. If you want another type of result, just change the $earthRadius. 194 195 = How to get user photos? = 196 We've written simple functions to let developers build everything. 197 Photos are saved in **/wp-content/uploads/telegram-bot/'.$plugin_post_id.'/'.$file_name** where $plugin_post_id is the custom post type id associated with the Telegram subscription (ex. '24') and $file_name is time().$extension 198 199 `<?php 200 /* 201 Plugin Name: Telegram Bot & Channel (Custom) 202 Description: My Custom Telegram Plugin 203 Author: My name 204 Version: 1 205 */ 206 207 add_action('telegram_parse_photo','telegramcustom_parse_photo', 10, 2); 208 209 function telegramcustom_parse_photo ( $telegram_user_id, $photo ) { 210 211 $plugin_post_id = telegram_getid( $telegram_user_id ); 212 213 if ( !$plugin_post_id ) { 214 return; 215 } 216 217 /* 218 Here is the dynamic processing and how to reply. 219 You can: 220 - use if, switch and everything that works in php 221 - check if $text is made of multiple words (create an array from $text) 222 - customize and code other actions (ex. create WordPress post is $telegram_user_id is your id) 223 */ 224 225 /* 226 $photo[2]['file_id'] is only one of available sizes. You should make sure that this size exist, or check for another size. 227 $photo[1]['file_id'] has lower resolution 228 */ 229 $url = telegram_download_file( $telegram_user_id, $photo[2]['file_id'] ); //Fetch and save photo to your server 230 231 if ( $url ) { //$url is the local url because photo is already saved 232 233 //You can save the entry in your db 234 global $wpdb; 235 $arr = array( 'telegram_id' => $telegram_user_id, 'plugin_post_id' => $plugin_post_id, 'url' => $url ); 236 237 $wpdb->insert( 238 $wpdb->prefix . 'your_table_name_that_must_already_exist', $arr, array( '%s' ) 239 ); 240 241 //Or save it as custom field and use it for a Finite State Machine 242 update_post_meta( $plugin_post_id, 'telegram_custom_last_photo_received', $url ); 243 244 telegram_sendmessage( $telegram_user_id, 'Photo received. Thank you!'); 245 } 246 247 ?>` 248 249 Another example, that is a "emergency bot" created for the mid-italy earthquake (24 august 2016) is available on [GitHub](https://github.com/milesimarco/terremotocentroitalia-bot-telegram/) 76 77 = How do I create a Telegram bot? = 78 Visit [Telegram’s BotFather](https://core.telegram.org/bots#botfather) and follow the instructions to create a new bot and get your token. 79 80 = How do users subscribe? = 81 Users can start your bot or join your channel/group where the bot is an admin. 82 83 = How do I enable Zapier integration? = 84 Enable Zapier in the plugin settings and follow the invite link for setup instructions. 85 86 = Is SSL required? = 87 Yes, Telegram WebHooks require SSL. Your site must use HTTPS for the plugin to work. 88 89 = Can I extend the plugin? = 90 Yes! Use WordPress hooks and filters to add custom commands, keyboards, and integrations. See the FAQ and code comments for examples. 250 91 251 92 == Screenshots == 252 1. Plugin dashboard93 1. Modern dashboard with stats and recent activity 253 94 2. Subscribers list 254 3. Commands list 255 4. Autoresponders 256 5. Zapier integration 257 6. plugin options 258 7. Dynamic repliles and inline buttons example from [IcBrendola_bot](http://telegram.me/IcBrendola_bot) 259 8. Keyboard example from [CosenzApp_bot](http://telegram.me/CosenzApp_bot) 260 9. Post broadcasting (all post types) 261 10. Native Gutenberg support 95 3. Commands and autoresponders 96 4. Zapier integration 97 5. Plugin settings with tabs 98 6. Dynamic replies and inline buttons 99 7. Keyboard example 100 8. Post broadcasting 101 9. Native Gutenberg support 262 102 263 103 == Changelog == 264 104 265 = 3.8 2024-07-01 = 266 267 * [IMPROVE] Redesigned settings page with old settings cleanup 268 * [IMPROVE] Better Zapier handling 269 * [IMPROVE] Minor changes, code cleanup, security hardening and optimizations 270 271 = 3.7 20231020 = 272 * [NEW] Added ability to selectively send message to subscribed groups 273 * [BUGFIX] Fixed critical bug when sending to groups 274 * [BUGFIX] Minor changes and optimizations 275 * [NEW] Github deploy flow setup - https://github.com/WPGov/telegram-bot 105 = 4.0 20250526 = 106 * [SECURITY] Added CSRF protection (WordPress nonces) to all sensitive actions (log clear, send message, etc.) 107 * [SECURITY] Hardened webhook and Zapier endpoints, removed BotPress.org fallback (now only Telegram WebHooks are supported) 108 * [SECURITY] Improved admin access checks and output escaping throughout the plugin 109 * [IMPROVE] Redesigned all admin pages for a modern, user-friendly experience (dashboard, log, send message, settings) 110 * [IMPROVE] Settings page now uses tabs for easier navigation and clarity 111 * [IMPROVE] Removed all BotPress.org logic and references (service discontinued, SSL is now required) 112 * [IMPROVE] Inlined and refactored plugin defaults (removed defaults.php) 113 * [IMPROVE] Refactored admin notices for maintainability 114 * [IMPROVE] Enhanced log panel with better design and empty state 115 * [IMPROVE] Enhanced dashboard with stats, recent activity, and quick actions 116 * [IMPROVE] Improved send message panel with modern UI 117 * [IMPROVE] Cleaned up and secured Zapier integration 118 * [IMPROVE] General code cleanup, improved maintainability and best practices 119 * [IMPROVE] Updated documentation and removed outdated references 120 * [DEPRECATED] Removed all support for BotPress.org and non-SSL fallback 121 * [NOTE] This is a major update. Please review your settings and test your integration after updating. 276 122 277 123 = 3.6.3 20230527 = -
telegram-bot/tags/4.0/telegram-bot.php
r3110525 r3300993 4 4 Plugin URI: https://wordpress.org/plugins/telegram-bot/ 5 5 Description: Broadcast your content to Telegram, build interactive bots and boost your omnichannel customer experience 6 Version: 3. 8.26 Version: 3.6.3 7 7 Author: Marco Milesi 8 8 Author URI: https://www.marcomilesi.com … … 15 15 require 'admin-messages.php'; 16 16 require 'panel/send.php'; 17 require 'panel/settings.php';18 17 19 18 add_action( 'plugins_loaded', function(){ … … 27 26 add_submenu_page('telegram_main', __('Send a message', 'telegram-bot'), __('Send a message', 'telegram-bot'), 'manage_options', 'telegram_send', 'telegram_send_panel' ); 28 27 add_submenu_page('telegram_main', __('Responders', 'telegram-bot'), __('Responders', 'telegram-bot'), 'manage_options', 'edit.php?post_type=telegram_commands'); 29 add_submenu_page('telegram_main', __('Settings', 'telegram-bot'), __('Settings', 'telegram-bot'), 'manage_options', 'telegram_settings', function(){ telegram_settings_page();});28 add_submenu_page('telegram_main', __('Settings', 'telegram-bot'), __('Settings', 'telegram-bot'), 'manage_options', 'telegram_settings', function(){require 'panel/settings.php';}); 30 29 add_submenu_page('telegram_main', 'Log', 'Log', 'manage_options', 'telegram_log', 'telegram_log_panel'); 31 30 }); 32 31 33 32 function telegram_log_panel() { 34 if (isset($_GET['tbclear'])) { 35 delete_option('wp_telegram_log'); 36 } 33 if (isset($_GET['tbclear'])) { 34 if (!isset($_GET['_wpnonce']) || !wp_verify_nonce($_GET['_wpnonce'], 'telegram_log_clear')) { 35 wp_die(__('Security check failed.','telegram-bot')); 36 } 37 delete_option('wp_telegram_log'); 38 } 37 39 $log = get_option('wp_telegram_log'); 38 39 echo '<div class="wrap"><h2>Activity log <a href="admin.php?page=telegram_log" class="add-new-h2">'.__('Reload', 'telegram-bot').'</a><a href="admin.php?page=telegram_log&tbclear=1" class="add-new-h2">'.__('Clear', 'telegram-bot').'</a></h2> 40 <table class="widefat fixed" cellspacing="0"> 41 <thead> 42 <tr> 43 <th style="width: 5%;" class="manage-column" scope="col">'.__('Type', 'telegram-bot').'</th> 44 <th style="width: 10%;" class="manage-column" scope="col">'.__('Date', 'telegram-bot').'</th> 45 <th style="width: 10%;" class="manage-column" scope="col">'.__('Author', 'telegram-bot').'</th> 46 <th id="columnname" class="manage-column" scope="col">'.__('Description', 'telegram-bot').'</th> 47 </tr> 48 </thead> 49 <tbody>'; 50 if ( is_array( $log ) ) { 40 echo '<div class="wrap telegram-log-panel">'; 41 echo '<h1 style="margin-bottom:24px;">'.__('Activity Log', 'telegram-bot').'</h1>'; 42 echo '<div style="margin-bottom:20px;">'; 43 echo '<a href="admin.php?page=telegram_log" class="button button-secondary" style="margin-right:10px;">'.__('Reload', 'telegram-bot').'</a>'; 44 echo '<a href="'.wp_nonce_url('admin.php?page=telegram_log&tbclear=1', 'telegram_log_clear').'" class="button button-danger" style="color:#fff;background:#d63638;border-color:#d63638;">'.__('Clear Log', 'telegram-bot').'</a>'; 45 echo '</div>'; 46 echo '<div style="overflow-x:auto;">'; 47 echo '<table class="widefat fixed striped" cellspacing="0" style="min-width:700px;">'; 48 echo '<thead><tr>'; 49 echo '<th style="width: 7%;">'.__('Type', 'telegram-bot').'</th>'; 50 echo '<th style="width: 15%;">'.__('Date', 'telegram-bot').'</th>'; 51 echo '<th style="width: 15%;">'.__('Author', 'telegram-bot').'</th>'; 52 echo '<th>'.__('Description', 'telegram-bot').'</th>'; 53 echo '</tr></thead><tbody>'; 54 if ( is_array( $log ) && count($log) ) { 51 55 foreach ( $log as $line ) { 52 56 echo '<tr>'; 53 echo '<td> ' . ( isset( $line[0] ) ? $line[0] : '' ) . '</td>';54 echo '<td>' . ( isset( $line[1] ) ? $line[1]: '' ) . '</td>';55 echo '<td>' . ( isset( $line[2] ) ? $line[2]: '' ) . '</td>';56 echo '<td>' . ( isset( $line[3] ) ? $line[3]: '' ) . '</td>';57 echo '<td><span style="font-weight:bold;color:#2271b1;">' . ( isset( $line[0] ) ? esc_html($line[0]) : '' ) . '</span></td>'; 58 echo '<td>' . ( isset( $line[1] ) ? esc_html($line[1]) : '' ) . '</td>'; 59 echo '<td>' . ( isset( $line[2] ) ? esc_html($line[2]) : '' ) . '</td>'; 60 echo '<td>' . ( isset( $line[3] ) ? esc_html($line[3]) : '' ) . '</td>'; 57 61 echo '</tr>'; 58 62 } 59 } 60 61 echo '</tbody> 62 </table></div>'; 63 } else { 64 echo '<tr><td colspan="4" style="text-align:center;color:#888;">'.__('No log entries found.', 'telegram-bot').'</td></tr>'; 65 } 66 echo '</tbody></table></div>'; 67 echo '<style>.telegram-log-panel .button-danger:hover{background:#a00!important;border-color:#a00!important;}</style>'; 68 echo '</div>'; 63 69 } 64 70 … … 89 95 90 96 function telegram_defaults() { 97 // Set API key if not set 91 98 if (!get_option('wp_telegram_apikey')) { 92 99 update_option('wp_telegram_apikey', md5(microtime() . rand() . get_site_url())); 93 100 } 94 101 // Set dispatches if not set 95 102 if (!get_option('wp_telegram_dispatches')) { 96 103 update_option('wp_telegram_dispatches', 0); 97 104 } 98 99 $defaults = array(100 array('token', ''),101 array('zapier', ''),102 array('wmgroup', 'Welcome!'),103 array('wmuser', 'Welcome, %FIRST_NAME%!'),104 array('posttemplate', '%TITLE%'.PHP_EOL.PHP_EOL.'%LINK%'),105 array('bmuser', 'Bye, %FIRST_NAME%. Type /start to enable the bot again.'),106 array('keyboard', '')105 // Set main plugin options 106 $defaults = array( 107 'token' => '', 108 'zapier' => '', 109 'wmgroup' => 'Welcome!', 110 'wmuser' => 'Welcome, %FIRST_NAME%!', 111 'posttemplate' => '%TITLE%' . PHP_EOL . PHP_EOL . '%LINK%', 112 'bmuser' => 'Bye, %FIRST_NAME%. Type /start to enable the bot again.', 113 'keyboard' => '' 107 114 ); 108 109 115 $my_options = get_option('wp_telegram'); 110 111 $conta = count($defaults); 112 113 for ($i = 0; $i < $conta; $i++) { 114 if (!isset( $my_options[$defaults[$i][0]] ) || !$my_options[$defaults[$i][0]]) { 115 $my_options[$defaults[$i][0]] = $defaults[$i][1]; 116 update_option('wp_telegram', $my_options); 117 } 116 if (!is_array($my_options)) { 117 $my_options = array(); 118 } 119 $changed = false; 120 foreach ($defaults as $key => $value) { 121 if (!isset($my_options[$key])) { 122 $my_options[$key] = $value; 123 $changed = true; 124 } 125 } 126 if ($changed) { 127 update_option('wp_telegram', $my_options); 118 128 } 119 129 } … … 127 137 if ($_GET['zap'] == get_option('wp_telegram_apikey') && telegram_option('zapier')) { 128 138 status_header( 200 ); 129 130 139 $json = file_get_contents('php://input'); 131 140 if (!$json) { … … 135 144 telegram_log('------>', 'ZAPIER', json_encode((array) file_get_contents("php://input"))); 136 145 telegram_sendmessagetoall($data['hook']); 137 138 146 } 139 147 } … … 198 206 if ($o) { 199 207 $text = str_replace('%FIRST_NAME%', get_post_meta($o->ID, 'telegram_name', true), $text); 208 $text = str_replace('%LAST_NAME%', get_post_meta($o->ID, '', true), $text); 200 209 } 201 210 } -
telegram-bot/trunk/admin-messages.php
r2981438 r3300993 1 1 <?php 2 add_action( 'admin_notices', function() { 3 4 global $current_screen; 5 if ( 'telegram_subscribers' == $current_screen->post_type ) { 6 echo ' 7 <div class="notice notice-info"> 8 <p>List of bot subscribers. New users will automatically appear once they /start on the bot</p> 9 </div>'; 10 } else if ( 'telegram_groups' == $current_screen->post_type ) { 11 echo ' 12 <div class="notice notice-info"> 13 <p>List of groups where your bot has been added.<br> 14 <small>Some <strong>BotFather</strong> actions could be required to get this working.</small></p> 15 </div>'; 16 } else if ( 'telegram_commands' == $current_screen->post_type ) { 17 echo ' 18 <div class="notice notice-info"> 19 <p>List of active commands of your bot<br> 20 <small>You can use the <strong>/command</strong> format as well as <strong>command</strong> (they are different). 21 <br>You can define multiple commands by typing, without spaces, a succession of comma-separated values (example: <strong>/command,command,/command2</strong>)</small></p> 22 </div>'; 23 } else if ( 'telegram_lists' == $current_screen->taxonomy ) { 24 echo ' 25 <div class="notice notice-info"> 26 <p>You can create different distribution lists in this page. This can be used for people and groups as well.</p> 27 </div>'; 2 add_action('admin_notices', function() { 3 if (!function_exists('get_current_screen')) { 4 return; 5 } 6 $screen = get_current_screen(); 7 if (!$screen) { 8 return; 9 } 10 $notices = [ 11 'telegram_subscribers' => [ 12 'type' => 'info', 13 'message' => __('List of users who have subscribed to your bot.', 'telegram-bot'), 14 ], 15 'telegram_groups' => [ 16 'type' => 'info', 17 'message' => __('List of groups where your bot has been added.<br><small>Some <strong>BotFather</strong> actions could be required to get this working.</small>', 'telegram-bot'), 18 ], 19 'telegram_commands' => [ 20 'type' => 'info', 21 'message' => __('List of active commands of your bot<br><small>You can use the <strong>/command</strong> format as well as <strong>command</strong> (they are different).<br>You can define multiple commands by typing, without spaces, a succession of comma-separated values (example: <strong>/command,command,/command2</strong>)</small>', 'telegram-bot'), 22 ], 23 ]; 24 if (isset($screen->post_type) && isset($notices[$screen->post_type])) { 25 $notice = $notices[$screen->post_type]; 26 printf( 27 '<div class="notice notice-%s"><p>%s</p></div>', 28 esc_attr($notice['type']), 29 $notice['message'] 30 ); 31 } elseif (isset($screen->taxonomy) && $screen->taxonomy === 'telegram_lists') { 32 printf( 33 '<div class="notice notice-info"><p>%s</p></div>', 34 __('You can create different distribution lists on this page. This can be used for people and groups as well.', 'telegram-bot') 35 ); 28 36 } 29 37 }); -
telegram-bot/trunk/columns.php
r2981438 r3300993 16 16 $columns['name'] ='Group Name'; 17 17 $columns['sdate'] ='Subscribed on'; 18 unset($columns['cb']); 18 19 unset($columns['date']); 19 20 if ( defined('WP_DEBUG') && false === WP_DEBUG) { … … 23 24 } ); 24 25 25 function bulk_actions_telegram_send($bulk_actions) {26 add_filter('bulk_actions-edit-telegram_subscribers', function($bulk_actions) { 26 27 $bulk_actions['telegram-send'] = __('Send message', 'telegram-bot'); 27 28 return $bulk_actions; 28 } 29 add_filter('bulk_actions-edit-telegram_subscribers', 'bulk_actions_telegram_send' ); 30 add_filter('bulk_actions-edit-telegram_groups', 'bulk_actions_telegram_send' ); 29 }); 31 30 32 function handle_bulk_actions_telegram_send($redirect_url, $action, $post_ids) {31 add_filter('handle_bulk_actions-edit-telegram_subscribers', function($redirect_url, $action, $post_ids) { 33 32 if ($action == 'telegram-send') { 34 33 … … 37 36 } 38 37 return $redirect_url; 39 } 40 add_filter('handle_bulk_actions-edit-telegram_subscribers', 'handle_bulk_actions_telegram_send', 10, 3); 41 add_filter('handle_bulk_actions-edit-telegram_groups', 'handle_bulk_actions_telegram_send', 10, 3); 38 }, 10, 3); 39 40 #add_filter('bulk_actions-edit-telegram_subscribers', function($actions){ unset( $actions['edit'] ); return apply_filters( 'bulk_actions-edit-telegram_subscribers_filter', $actions ); }); 41 #add_filter('bulk_actions-edit-telegram_groups', function($actions){ unset( $actions['edit'] ); return apply_filters( 'bulk_actions-edit-telegram_groups_filter', $actions ); }); 42 42 43 43 add_action('manage_telegram_subscribers_posts_custom_column', 't_manage_columns', 10, 2); … … 47 47 switch ($column) { 48 48 case 'name': 49 echo '<a class="row-title" href="'.get_edit_post_link( $post_id ).'">'.get_post_meta($post_id, 'telegram_name', true).'</a>';49 printf(get_post_meta($post_id, 'telegram_name', true)); 50 50 break; 51 51 case 'user_name': -
telegram-bot/trunk/custom-post-types.php
r2981438 r3300993 90 90 ); 91 91 if ( defined('WP_DEBUG') && false === WP_DEBUG) { 92 $args['capabilities'] = array( 'create_posts' => ' false' );93 $args['map_meta_cap'] = true;92 $args['capabilities'] = array( 'create_posts' => 'do_not_allow' ); 93 $args['map_meta_cap'] = false; 94 94 } 95 95 $args = apply_filters('telegram_groups_register_capabilities', $args ); -
telegram-bot/trunk/panel/main.php
r2418686 r3300993 1 <?php 2 // Security: Only allow admins to view this page 3 if (!current_user_can('manage_options')) { 4 wp_die(__('You do not have sufficient permissions to access this page.')); 5 } 1 6 2 <div class="wrap"> 3 <div class="wrap about__container"> 7 // Fetch stats 8 $version = esc_html(get_option('wp_telegram_version')); 9 $dispatches = number_format_i18n(intval(get_option('wp_telegram_dispatches'))); 10 $subscribers = number_format_i18n(wp_count_posts('telegram_subscribers')->publish); 11 $groups = number_format_i18n(wp_count_posts('telegram_groups')->publish); 4 12 5 <div class="about__section is-feature has-accent-background-color"> 6 <h1>Telegram Bot & Channel</h1> 7 <p>Version <?php echo get_option('wp_telegram_version'); ?></p> 13 // Fetch recent log entries (last 5) 14 $log = get_option('wp_telegram_log'); 15 $recent_log = is_array($log) ? array_slice($log, 0, 5) : array(); 16 17 // Fetch plugin settings link 18 $settings_url = admin_url('admin.php?page=telegram_settings'); 19 20 // Fetch log page link 21 $log_url = admin_url('admin.php?page=telegram_log'); 22 23 ?> 24 <div class="wrap telegram-dashboard" style="max-width:900px;margin:auto;"> 25 <div class="telegram-header" style="display:flex;align-items:center;justify-content:space-between;padding:32px 0 16px 0;"> 26 <div> 27 <h1 style="margin:0;font-size:2.5em;">🤖 Telegram Bot & Channel</h1> 28 <span style="color:#888;font-size:1.1em;">v<?php echo $version; ?></span> 8 29 </div> 9 <div class=" wp-clearfix"></div> 10 11 <div class="about__section has-3-columns" style="text-align:center;"> 12 <div class="column has-subtle-background-color"> 13 <span style="font-size:3em;"><?php echo get_option('wp_telegram_dispatches'); ?></span> 14 <br> 15 messages sent 16 </div> 17 <div class="column has-subtle-background-color"> 18 <span style="font-size:3em;"><?php echo wp_count_posts('telegram_subscribers')->publish; ?></span> 19 <br> 20 subscribers 21 </div> 22 <div class="column has-subtle-background-color"> 23 <span style="font-size:3em;"><?php echo wp_count_posts('telegram_groups')->publish; ?></span> 24 <br> 25 groups 26 </div> 30 <div> 31 <a href="<?php echo esc_url($settings_url); ?>" class="button button-primary" style="font-size:1.1em;">⚙️ <?php _e('Settings', 'telegram-bot'); ?></a> 27 32 </div> 28 33 </div> 34 <div class="telegram-stats" style="display:flex;gap:32px;justify-content:space-between;margin:32px 0;"> 35 <div class="telegram-stat-card" style="flex:1;background:#f6f8fa;padding:32px 0;border-radius:12px;text-align:center;box-shadow:0 2px 8px #0001;"> 36 <div style="font-size:2.5em;color:#2271b1;font-weight:bold;"><?php echo $dispatches; ?></div> 37 <div style="color:#666;margin-top:8px;">Messages Sent</div> 38 </div> 39 <div class="telegram-stat-card" style="flex:1;background:#f6f8fa;padding:32px 0;border-radius:12px;text-align:center;box-shadow:0 2px 8px #0001;"> 40 <div style="font-size:2.5em;color:#46b450;font-weight:bold;"><?php echo $subscribers; ?></div> 41 <div style="color:#666;margin-top:8px;">Subscribers</div> 42 </div> 43 <div class="telegram-stat-card" style="flex:1;background:#f6f8fa;padding:32px 0;border-radius:12px;text-align:center;box-shadow:0 2px 8px #0001;"> 44 <div style="font-size:2.5em;color:#d63638;font-weight:bold;"><?php echo $groups; ?></div> 45 <div style="color:#666;margin-top:8px;">Groups</div> 46 </div> 47 </div> 48 <div class="telegram-actions" style="display:flex;gap:16px;justify-content:flex-end;margin-bottom:24px;"> 49 <a href="<?php echo esc_url($log_url); ?>" class="button button-secondary">📝 <?php _e('View Log', 'telegram-bot'); ?></a> 50 <a href="<?php echo esc_url(admin_url('admin.php?page=telegram_send')); ?>" class="button button-primary">✉️ <?php _e('Send Message', 'telegram-bot'); ?></a> 51 </div> 52 <div class="telegram-recent-log" style="background:#fff;border-radius:10px;box-shadow:0 1px 4px #0001;padding:24px;"> 53 <h2 style="margin-top:0;font-size:1.3em;"><?php _e('Recent Activity', 'telegram-bot'); ?></h2> 54 <?php if (!empty($recent_log)) : ?> 55 <table class="widefat striped" style="margin-top:12px;"> 56 <thead> 57 <tr> 58 <th><?php _e('Type', 'telegram-bot'); ?></th> 59 <th><?php _e('Date', 'telegram-bot'); ?></th> 60 <th><?php _e('Author', 'telegram-bot'); ?></th> 61 <th><?php _e('Description', 'telegram-bot'); ?></th> 62 </tr> 63 </thead> 64 <tbody> 65 <?php foreach ($recent_log as $line) : ?> 66 <tr> 67 <td><span style="font-weight:bold;color:#2271b1;"><?php echo isset($line[0]) ? esc_html($line[0]) : ''; ?></span></td> 68 <td><?php echo isset($line[1]) ? esc_html($line[1]) : ''; ?></td> 69 <td><?php echo isset($line[2]) ? esc_html($line[2]) : ''; ?></td> 70 <td><?php echo isset($line[3]) ? esc_html($line[3]) : ''; ?></td> 71 </tr> 72 <?php endforeach; ?> 73 </tbody> 74 </table> 75 <?php else : ?> 76 <div style="color:#888;text-align:center;padding:24px 0;">No recent activity found.</div> 77 <?php endif; ?> 78 </div> 79 <div class="telegram-quick-actions" style="margin-top:32px;display:flex;gap:24px;"> 80 <div style="flex:1;background:#f6f8fa;padding:20px 24px;border-radius:10px;"> 81 <h3 style="margin-top:0;">Subscriber Search</h3> 82 <form method="get" action="<?php echo esc_url(admin_url('edit.php')); ?>"> 83 <input type="hidden" name="post_type" value="telegram_subscribers" /> 84 <input type="search" name="s" style="width:100%;margin-bottom:8px;" placeholder="Search subscribers by name or ID..." /> 85 <button type="submit" class="button">Search</button> 86 </form> 87 </div> 88 </div> 89 <style> 90 .telegram-dashboard h1, .telegram-dashboard h2, .telegram-dashboard h3 { font-family: 'Segoe UI', 'Arial', sans-serif; } 91 .telegram-dashboard .button-primary { background:#2271b1;border-color:#2271b1; } 92 .telegram-dashboard .button-primary:hover { background:#1a5a8a;border-color:#1a5a8a; } 93 .telegram-dashboard .button-danger { background:#d63638;border-color:#d63638;color:#fff; } 94 .telegram-dashboard .button-danger:hover { background:#a00;border-color:#a00; } 95 </style> 29 96 </div> -
telegram-bot/trunk/panel/send.php
r2790989 r3300993 4 4 $count = 0; 5 5 $send_to_custom_ids = false; 6 echo '<div class="wrap"><h2>'.__('Send a message', 'telegram-bot').'</h2>'; 6 echo '<div class="wrap telegram-send-panel" style="max-width:700px;margin:auto;">'; 7 echo '<h1 style="margin-bottom:24px;">' . __('Send a Message', 'telegram-bot') . '</h1>'; 7 8 if (isset($_POST["telegram_new_message"])) { 9 if (!isset($_POST['_wpnonce']) || !wp_verify_nonce($_POST['_wpnonce'], 'telegram_send_message')) { 10 wp_die(__('Security check failed.','telegram-bot')); 11 } 8 12 $message = $_POST["telegram_new_message"]; 9 13 … … 34 38 } 35 39 36 echo '<div class="notice notice-success"> 37 <p>Your message have been sent!</p> 38 </div>'; 40 echo '<div class="notice notice-success" style="margin-bottom:24px;"><p>' . __('Your message has been sent!', 'telegram-bot') . '</p></div>'; 39 41 } 40 echo '<form method="post" id="telegram_new_message">'; 42 echo '<form method="post" id="telegram_new_message" style="background:#fff;padding:32px 32px 24px 32px;border-radius:10px;box-shadow:0 2px 8px #0001;">'; 43 wp_nonce_field('telegram_send_message'); 41 44 if ( isset( $_GET['telegram_post_ids'] ) ) { 42 45 $telegram_post_ids = explode( ',', $_GET['telegram_post_ids']); 43 echo '<div class="notice notice-warning" ><p>Note: You are sending this message to <b>'.count( $telegram_post_ids ).' subscribers</b></p></div>';46 echo '<div class="notice notice-warning" style="margin-bottom:16px;"><p>' . __('Note: You are sending this message to', 'telegram-bot') . ' <b>' . count( $telegram_post_ids ) . ' ' . __('subscribers', 'telegram-bot') . '</b></p></div>'; 44 47 $send_to_custom_ids = true; 45 48 } 46 echo '<textarea name="telegram_new_message" cols="100" rows="10"></textarea><br>'; 49 echo '<label for="telegram_new_message" style="font-weight:bold;font-size:1.1em;">' . __('Message', 'telegram-bot') . '</label><br>'; 50 echo '<textarea name="telegram_new_message" id="telegram_new_message" cols="80" rows="7" style="width:100%;margin-bottom:18px;font-size:1.1em;"></textarea><br>'; 47 51 $target = $send_to_custom_ids ? 'custom_ids' : telegram_option('target'); 48 52 49 53 if ( !$send_to_custom_ids ) { 50 echo __('Send to', 'telegram-bot').':'; 51 ?> 52 <select name="telegram_target"> 53 <option value="0"><?php _e('Users, Groups, Channel', 'telegram-bot'); ?></option> 54 <option value="1"<?php if ($target==1 ) { echo ' selected="selected"'; } ?>><?php _e('Users', 'telegram-bot'); ?></option> 55 <option value="2"<?php if ($target==2 ) { echo ' selected="selected"'; } ?>><?php _e('Groups', 'telegram-bot'); ?></option> 56 <option value="3"<?php if ($target==3 ) { echo ' selected="selected"'; } ?>><?php _e('Users, Groups', 'telegram-bot'); ?></option> 57 <option value="4"<?php if ($target==4 ) { echo ' selected="selected"'; } ?>><?php _e('Channel', 'telegram-bot'); ?></option> 58 </select> 59 <?php } 60 61 submit_button( __('Send Now', 'telegram-bot'), 'primary'); 54 echo '<label for="telegram_target" style="font-weight:bold;">' . __('Send to', 'telegram-bot') . ':</label> '; 55 echo '<select name="telegram_target" id="telegram_target" style="margin-bottom:18px;">'; 56 echo '<option value="0"' . ($target == 0 ? ' selected' : '') . '>' . __('Users, Groups, Channel', 'telegram-bot') . '</option>'; 57 echo '<option value="1"' . ($target == 1 ? ' selected' : '') . '>' . __('Users', 'telegram-bot') . '</option>'; 58 echo '<option value="2"' . ($target == 2 ? ' selected' : '') . '>' . __('Groups', 'telegram-bot') . '</option>'; 59 echo '<option value="3"' . ($target == 3 ? ' selected' : '') . '>' . __('Users, Groups', 'telegram-bot') . '</option>'; 60 echo '<option value="4"' . ($target == 4 ? ' selected' : '') . '>' . __('Channel', 'telegram-bot') . '</option>'; 61 echo '</select><br>'; 62 } 63 echo '<button type="submit" class="button button-primary" style="font-size:1.1em;padding:8px 32px;">' . __('Send Now', 'telegram-bot') . '</button>'; 62 64 echo '</form>'; 63 65 echo '<style>.telegram-send-panel textarea { font-family: inherit; } .telegram-send-panel .notice-success { border-left: 4px solid #46b450; } .telegram-send-panel .notice-warning { border-left: 4px solid #ffb900; }</style>'; 64 66 echo '</div>'; 65 67 } -
telegram-bot/trunk/panel/settings.php
r3110498 r3300993 1 <?php function telegram_settings_page() { ?> 1 <?php 2 // Security: Only allow admins to view this page 3 if (!current_user_can('manage_options')) { 4 wp_die(__('You do not have sufficient permissions to access this page.')); 5 } 2 6 3 <div class="wrap"> 4 <h2>Settings</h2> 7 $options = get_option('wp_telegram'); 8 foreach ($options as $k => $v) { 9 $options[$k] = esc_attr($v); 10 } 5 11 6 <?php if ( $_SERVER["SERVER_ADDR"] == '127.0.0.1' ) { 7 echo '<div class="notice notice-warning"><p>'.__('Warning: the plugin <b>does not</b> work in localhost environments!', 'telegram-bot').'</p></div>'; 8 } ?> 9 10 <form method="post" action="options.php"> 11 <?php 12 settings_fields( 'wp_telegram_options'); 13 $options=get_option( 'wp_telegram'); 14 foreach( $options as $k => $v ) { 15 $options[$k] = esc_attr( $v ); 16 } 17 18 if ( isset($_GET['settings-updated']) ) { 19 20 $url=telegram_geturl() . 'setWebhook?url=' . telegram_getapiurl(); 21 22 json_decode(file_get_contents($url), true); 23 telegram_log( 'sys', 'Webhook update', $url); 24 } 25 ?> 26 27 <table class="form-table"> 28 <tr valign="top"> 29 <th scope="row"> 30 <label for="apikey">Plugin Api Key 31 </label> 32 </th> 33 <td> 34 <input readonly="readonly" id="apikey" type="text" name="wp_telegram_apikey" value="<?php echo get_option('wp_telegram_apikey'); ?>" size="55" /> 35 <br> 36 <small>The unique key for your website: <b>Keep it secret!</b></small> 37 </td> 38 </tr> 39 <tr valign="top"> 40 <th scope="row"> 41 <label for="token">Bot Token<br><span style="background:darkred;font-size:0.8em;padding:2px;color:white;"><?php _e('Required', 'telegram-bot'); ?></span></label> 42 </th> 43 <td> 44 <input id="token" type="text" name="wp_telegram[token]" value="<?php echo $options['token']; ?>" size="55" /> 45 <br> 46 <small><?php _e( 'Paste here your bot token. You can obtain it from Telegram <b>BotFather</b>', 'telegram-bot'); ?></small> 47 </td> 48 </tr 49 <tr valign="top"> 50 <th scope="row"> 51 <label for="username">Bot Username<br><span style="background:darkred;font-size:0.8em;padding:2px;color:white;"><?php _e('Required', 'telegram-bot'); ?></span></label> 52 </th> 53 <td> 54 <input id="username" type="text" name="wp_telegram[username]" value="<?php echo isset( $options['username'] ) ? $options['username'] : ''; ?>" size="55" /> 55 <br> 56 <small>Telegram Bot username. Example: <b>mywebsite_bot</b></small> 57 </td> 58 </tr> 59 <tr valign="top"> 60 <th scope="row"> 61 <label for="channelusername"> 62 <?php _e('Channel Username', 'telegram-bot'); ?> 63 </label> 64 </th> 65 <td> 66 <input id="channelusername" type="text" name="wp_telegram[channelusername]" value="<?php echo isset( $options['channelusername'] ) ? $options['channelusername'] : ''; ?>" size="55" /> 67 <br> 68 <small>Insert your channel username (if you want to broadcast). Example: <b>@mywebsite</b> 69 <br>The bot must be admin in your channel 70 </small> 71 </td> 72 </tr> 73 <tr valign="top"> 74 <th scope="row"> 75 <label> 76 Webhook 77 </label> 78 </th> 79 <td> 80 <a class="page-title-action" onclick="alert('<?php echo telegram_getapiurl(); ?>');">Show private endpoint</a> 81 <p style="font-size:0.9em;"> 82 This is your private Telegram webhook. Please keep it private and make sure it bypasses cache and firewall. 12 // Handle webhook update after settings are saved 13 if (isset($_GET['settings-updated'])) { 14 $url = telegram_geturl() . 'setWebhook?url=' . telegram_getapiurl(); 15 json_decode(@file_get_contents($url), true); 16 telegram_log('sys', 'Webhook update', $url); 17 } 18 ?> 19 <div class="wrap telegram-settings" style="max-width:900px;margin:auto;"> 20 <h1 style="margin-bottom:24px;"><?php _e('Telegram Bot Settings', 'telegram-bot'); ?></h1> 21 <p style="font-size:1.1em;"> 22 <?php _e('This plugin is capable of broadcasting to channel and creating interactive bots.', 'telegram-bot'); ?><br> 23 <?php _e('You need to create a bot with BotFather and obtain the token.', 'telegram-bot'); ?><br> 24 <?php _e('To broadcast to a channel, add the bot as admin in your channel.', 'telegram-bot'); ?> 25 </p> 26 <?php if ($_SERVER["SERVER_ADDR"] == '127.0.0.1') { 27 echo '<div class="notice notice-warning"><p>' . __('Warning: the plugin <b>does not</b> work in localhost environments!', 'telegram-bot') . '</p></div>'; 28 } ?> 29 <form method="post" action="options.php"> 30 <?php settings_fields('wp_telegram_options'); ?> 31 <div id="telegram-tabs" style="margin-top:32px;"> 32 <nav class="nav-tab-wrapper"> 33 <a href="#tab-general" class="nav-tab nav-tab-active">General</a> 34 <a href="#tab-broadcast" class="nav-tab">Broadcast</a> 35 <a href="#tab-bot" class="nav-tab">Bot</a> 36 </nav> 37 <div id="tab-general" class="telegram-tab-content" style="display:block;"> 38 <table class="form-table"> 39 <tr valign="top"> 40 <th scope="row"><label for="apikey">Plugin Api Key</label></th> 41 <td> 42 <input readonly="readonly" id="apikey" type="text" name="wp_telegram_apikey" value="<?php echo get_option('wp_telegram_apikey'); ?>" size="55" /> 43 <br><small><?php _e('The unique key for your website: <b>Keep it secret!</b>', 'telegram-bot'); ?></small> 44 </td> 45 </tr> 46 <tr valign="top"> 47 <th scope="row"><label for="token">Bot Token</label></th> 48 <td> 49 <input id="token" type="text" name="wp_telegram[token]" value="<?php echo $options['token']; ?>" size="55" autocomplete="off" /> 50 <br><small><?php _e('Telegram Bot authentication key. <b>Keep it secret!</b>', 'telegram-bot'); ?></small> 51 </td> 52 </tr> 53 <tr valign="top"> 54 <th scope="row"><label for="username">Bot Username</label></th> 55 <td> 56 <input id="username" type="text" name="wp_telegram[username]" value="<?php echo isset($options['username']) ? $options['username'] : ''; ?>" size="55" /> 57 <br><small><?php _e('Telegram Bot username. Example: <b>mywebsite_bot</b>', 'telegram-bot'); ?></small> 58 </td> 59 </tr> 60 <tr valign="top"> 61 <th scope="row"><label for="channelusername"><?php _e('Channel Username', 'telegram-bot'); ?></label></th> 62 <td> 63 <input id="channelusername" type="text" name="wp_telegram[channelusername]" value="<?php echo isset($options['channelusername']) ? $options['channelusername'] : ''; ?>" size="55" /> 64 <br><small><?php _e('Insert your channel username (if you want to broadcast). Example: <b>@mywebsite</b><br>The bot must be admin in your channel', 'telegram-bot'); ?></small> 65 </td> 66 </tr> 67 <tr valign="top"> 68 <th scope="row"><label for="mode"><?php _e('Connection Mode', 'telegram-bot'); ?></label></th> 69 <td> 70 <select name="wp_telegram[mode]" disabled> 71 <option value="0" selected><?php _e('Telegram WebHooks (required)', 'telegram-bot'); ?></option> 72 </select> 73 <br><small><?php _e('Telegram WebHooks are now required. SSL is mandatory for webhook delivery.', 'telegram-bot'); ?></small> 74 </td> 75 </tr> 76 <tr valign="top"> 77 <th scope="row"><label>Webhook</label></th> 78 <td> 79 <a class="page-title-action" onclick="alert('<?php echo telegram_getapiurl(); ?>');">Show private endpoint</a> 80 <p style="font-size:0.9em;"> 81 <?php _e('This is your private Telegram webhook. Please keep it private and make sure it bypasses cache and firewall.', 'telegram-bot'); ?> 82 </p> 83 </td> 84 </tr> 85 <tr valign="top"> 86 <th scope="row"><label for="zapier"><?php _e('Enable Zapier', 'telegram-bot'); ?></label></th> 87 <td> 88 <input id="zapier" name="wp_telegram[zapier]" type="checkbox" value="1" <?php checked('1', (isset($options['zapier']) && $options['zapier']) ? 1 : 0); ?> /> 89 <br><small><?php _e('Enable Zapier integration • Beta •', 'telegram-bot'); ?> 90 <a href="https://zapier.com/developer/invite/26805/1ec54299d4307c0b86b7417d0866ff25/" target="_blank">Click here to get an invite</a> 91 </small> 92 </td> 93 </tr> 94 </table> 95 </div> 96 <div id="tab-broadcast" class="telegram-tab-content" style="display:none;"> 97 <table class="form-table"> 98 <tr valign="top"> 99 <td colspan="2"> 100 <h3><?php _e('Posts broadcast', 'telegram-bot'); ?></h3> 101 <p><?php _e('You can send post or custom post to Telegram when you publish or edit it.', 'telegram-bot'); ?></p> 102 </td> 103 </tr> 104 <tr valign="top"> 105 <th scope="row"><label for="target"><?php _e('Default content broadcast', 'telegram-bot'); ?></label></th> 106 <td> 107 <select name="wp_telegram[target]"> 108 <option><?php _e('Users, Groups, Channel', 'telegram-bot'); ?></option> 109 <option value="1"<?php if (isset($options['target']) && $options['target'] == 1) { echo ' selected="selected"'; } ?>><?php _e('Users', 'telegram-bot'); ?></option> 110 <option value="2"<?php if (isset($options['target']) && $options['target'] == 2) { echo ' selected="selected"'; } ?>><?php _e('Groups', 'telegram-bot'); ?></option> 111 <option value="3"<?php if (isset($options['target']) && $options['target'] == 3) { echo ' selected="selected"'; } ?>><?php _e('Users, Groups', 'telegram-bot'); ?></option> 112 <option value="4"<?php if (isset($options['target']) && $options['target'] == 4) { echo ' selected="selected"'; } ?>><?php _e('Channel', 'telegram-bot'); ?></option> 113 <option value="5"<?php if (isset($options['target']) && $options['target'] == 5) { echo ' selected="selected"'; } ?>><?php _e('All', 'telegram-bot'); ?></option> 114 </select> 115 <br><small><?php _e('Define the post broadcast targeting when you send content (for example posts or manual text).<br>You can also change this behaviour manually.', 'telegram-bot'); ?></small> 116 </td> 117 </tr> 118 <tr valign="top"> 119 <th scope="row"><label for="posttemplate"><?php _e('Post Template', 'telegram-bot'); ?></label></th> 120 <td> 121 <textarea id="posttemplate" rows="4" class="widefat" name="wp_telegram[posttemplate]"><?php echo $options['posttemplate']; ?></textarea> 122 <br><small><?php _e('Allowed placeholders: <b>%TITLE% %LINK% %EXCERPT% %CHAT_ID%</b>', 'telegram-bot'); ?></small> 123 </td> 124 </tr> 125 </table> 126 </div> 127 <div id="tab-bot" class="telegram-tab-content" style="display:none;"> 128 <table class="form-table"> 129 <tr valign="top"> 130 <td colspan="2"> 131 <h3><?php _e('Interactive bot', 'telegram-bot'); ?></h3> 132 <p><?php _e('Only use this section if you want to build an interactive bot', 'telegram-bot'); ?></p> 133 </td> 134 </tr> 135 <tr valign="top"> 136 <th scope="row"><label for="wmuser"><?php _e('Start Message', 'telegram-bot'); ?><br><small><?php _e('for users', 'telegram-bot'); ?></small></label></th> 137 <td> 138 <input id="wmuser" type="text" name="wp_telegram[wmuser]" value="<?php echo $options['wmuser']; ?>" size="55" /> 139 <br><small><?php _e('Cannot be blank', 'telegram-bot'); ?>.</small> 140 </td> 141 </tr> 142 <tr valign="top"> 143 <th scope="row"><label for="bmuser"><?php _e('Bye Message', 'telegram-bot'); ?><br><small><?php _e('for Private Conversations', 'telegram-bot'); ?></small></label></th> 144 <td> 145 <input id="bmuser" type="text" name="wp_telegram[bmuser]" value="<?php echo $options['bmuser']; ?>" size="55" /> 146 <br><small><?php _e('Cannot be blank', 'telegram-bot'); ?>.</small> 147 </td> 148 </tr> 149 <tr valign="top"> 150 <th scope="row"><label for="emuser"><?php _e('Error Message', 'telegram-bot'); ?><br><small><?php _e('for users', 'telegram-bot'); ?></small></label></th> 151 <td> 152 <input id="emuser" type="text" name="wp_telegram[emuser]" value="<?php echo isset($options['emuser']) ? $options['emuser'] : ''; ?>" size="55" /> 153 <br><small><?php _e('This will be shown when the command doesn\'t exist.', 'telegram-bot'); ?></small> 154 </td> 155 </tr> 156 <tr valign="top"> 157 <th scope="row"><label for="wmgroup"><?php _e('Start Message', 'telegram-bot'); ?><br><small><?php _e('for Groups', 'telegram-bot'); ?></small></label></th> 158 <td> 159 <input id="wmgroup" type="text" name="wp_telegram[wmgroup]" value="<?php echo $options['wmgroup']; ?>" size="55" /> 160 <br><small><?php _e('Cannot be blank', 'telegram-bot'); ?>.</small> 161 </td> 162 </tr> 163 <tr valign="top"> 164 <th scope="row"><label for="keyboard"><?php _e('Keyboard Template', 'telegram-bot'); ?><br><small><?php _e('for users', 'telegram-bot'); ?></small></label></th> 165 <td> 166 <input id="keyboard" type="text" name="wp_telegram[keyboard]" value="<?php echo $options['keyboard']; ?>" size="55" /> 167 <br><small><?php _e('Example: <b>1,2,3;4,5,6;Text</b>', 'telegram-bot'); ?></small> 168 </td> 169 </tr> 170 </table> 171 </div> 172 </div> 173 <div class="clear"></div> 174 <hr> 175 <p class="submit"> 176 <input type="submit" class="button-primary" value="<?php _e('Save Changes'); ?>" /> 83 177 </p> 84 </td> 85 </tr> 86 <tr valign="top"> 87 <th scope="row"> 88 <label for="zapier"> 89 <?php _e('Enable Zapier', 'telegram-bot'); ?> 90 </label> 91 </th> 92 <td> 93 <input id="zapier" name="wp_telegram[zapier]" type="checkbox" value="1" 94 <?php checked( '1', ( isset( $options[ 'zapier'] ) && $options[ 'zapier'] ) ? 1 : 0 ); ?> /> 95 <br> 96 <small>Zapier allows you to send messages from your own platforms 97 <a href="https://zapier.com/developer/public-invite/88225/1d9f5d9ec76cde2aac6e356298aee8e8/">Click here to get an invite</a> 98 </small> 99 </td> 100 </tr> 101 <tr valign="top"> 102 <td colspan="2"> 103 <h3><?php _e('Posts broadcast', 'telegram-bot'); ?></h3> 104 <p><?php _e('You can send post or custom post to Telegram when you publish or edit it.', 'telegram-bot'); ?></p> 105 <p><?php _e('If you want to broadcast to a channel, please add the bot as admin in your channel.', 'telegram-bot'); ?></p> 106 </td> 107 </tr> 108 <tr valign="top"> 109 <th scope="row"> 110 <label for="mode"> 111 <?php _e('Default content broadcast', 'telegram-bot'); ?> 112 </label> 113 </th> 114 <td> 115 <select name="wp_telegram[target]"> 116 <option><?php _e('Users, Groups, Channel', 'telegram-bot'); ?></option> 117 <option value="1"<?php if (isset($options['target'])&&$options['target']==1 ) { echo ' selected="selected"'; } ?>><?php _e('Users', 'telegram-bot'); ?></option> 118 <option value="2"<?php if (isset($options['target'])&&$options['target']==2 ) { echo ' selected="selected"'; } ?>><?php _e('Groups', 'telegram-bot'); ?></option> 119 <option value="3"<?php if (isset($options['target'])&&$options['target']==3 ) { echo ' selected="selected"'; } ?>><?php _e('Users, Groups', 'telegram-bot'); ?></option> 120 <option value="4"<?php if (isset($options['target'])&&$options['target']==4 ) { echo ' selected="selected"'; } ?>><?php _e('Channel', 'telegram-bot'); ?></option> 121 <option value="5"<?php if (isset($options['target'])&&$options['target']==5 ) { echo ' selected="selected"'; } ?>><?php _e('All', 'telegram-bot'); ?></option> 122 </select> 123 <br> 124 <small> 125 <?php _e('Define the post broadcast targeting when you send content (for example posts or manual text).', 'telegram-bot'); ?> 126 <br> 127 <?php _e('You can also change this behaviour manually.', 'telegram-bot'); ?> 128 </small> 129 </td> 130 </tr> 131 <tr valign="top"> 132 <th scope="row"> 133 <label for="posttemplate"><?php _e('Post Template', 'telegram-bot'); ?></label> 134 </th> 135 <td> 136 <textarea id="posttemplate" rows="4" class="widefat" name="wp_telegram[posttemplate]"><?php echo $options['posttemplate']; ?></textarea> 137 <br><small><?php _e('Allowed placeholders: <b>%TITLE% %LINK% %EXCERPT% %CHAT_ID%</b>', 'telegram-bot'); ?></small> </td></td> 138 </tr> 139 <tr valign="top"> 140 <td colspan="2"> 141 <h3><?php _e('Interactive bot', 'telegram-bot'); ?></h3> 142 <p>Only use this section if you want to build an interactive bot</p> 143 </td> 144 </tr> 145 <tr valign="top"> 146 <th scope="row"> 147 <label for="wmuser"> 148 <?php _e('Start Message', 'telegram-bot'); ?> 149 <br> 150 <small> 151 <?php _e('for users', 'telegram-bot'); ?> 152 </small> 153 </label> 154 </th> 155 <td> 156 <input id="wmuser" type="text" name="wp_telegram[wmuser]" value="<?php echo $options['wmuser']; ?>" size="55" /> 157 <br> 158 <small> 159 <?php _e('Cannot be blank', 'telegram-bot'); ?>. 160 </small> 161 </td> 162 </tr> 163 <tr valign="top"> 164 <th scope="row"> 165 <label for="bmuser"> 166 <?php _e('Bye Message', 'telegram-bot'); ?> 167 <br> 168 <small> 169 <?php _e('for Private Conversations', 'telegram-bot'); ?> 170 </small> 171 </label> 172 </th> 173 <td> 174 <input id="bmuser" type="text" name="wp_telegram[bmuser]" value="<?php echo $options['bmuser']; ?>" size="55" /> 175 <br> 176 <small> 177 <?php _e('Cannot be blank', 'telegram-bot'); ?>. 178 </small> 179 </td> 180 </tr> 181 <tr valign="top"> 182 <th scope="row"> 183 <label for="emuser"> 184 <?php _e('Error Message', 'telegram-bot'); ?> 185 <br> 186 <small> 187 <?php _e('for users', 'telegram-bot'); ?> 188 </small> 189 </label> 190 </th> 191 <td> 192 <input id="emuser" type="text" name="wp_telegram[emuser]" value="<?php echo isset( $options['emuser'] ) ? $options['emuser'] : ''; ?>" size="55" /> 193 <br> 194 <small><?php _e('This will be shown when the command doesn\'t exist.', 'telegram-bot'); ?></small> 195 </td> 196 </tr> 197 <tr valign="top"> 198 <th scope="row"> 199 <label for="wmgroup"> 200 <?php _e('Start Message', 'telegram-bot'); ?> 201 <br> 202 <small>for Groups 203 </small> 204 </label> 205 </th> 206 <td> 207 <input id="wmgroup" type="text" name="wp_telegram[wmgroup]" value="<?php echo $options['wmgroup']; ?>" size="55" /> 208 <br> 209 <small> 210 <?php _e('Cannot be blank', 'telegram-bot'); ?>. 211 </small> 212 </td> 213 </tr> 214 <tr valign="top"> 215 <th scope="row"> 216 <label for="keyboard"> 217 <?php _e('Keyboard Template', 'telegram-bot'); ?> 218 <br> 219 <small><?php _e('for users', 'telegram-bot'); ?></small> 220 </label> 221 </th> 222 <td> 223 <input id="keyboard" type="text" name="wp_telegram[keyboard]" value="<?php echo $options['keyboard']; ?>" size="55" /> 224 <br> 225 <small><?php _e('Example: <b>1,2,3;4,5,6;Text</b>', 'telegram-bot'); ?></small> 226 </td> 227 </tr> 228 </table> 229 230 <p class="submit"> 231 <input type="submit" class="button-primary" value="<?php _e('Save Changes'); ?>" /> 232 </p> 233 </form> 178 </form> 179 <style> 180 .telegram-settings .nav-tab-wrapper { margin-bottom: 0; } 181 .telegram-settings .nav-tab { font-size: 1.1em; } 182 .telegram-settings .telegram-tab-content { background: #fff; border: 1px solid #ccd0d4; border-top: none; padding: 24px 32px; border-radius: 0 0 8px 8px; } 183 .telegram-settings table.form-table { width: 100%; } 184 .telegram-settings th { width: 220px; } 185 </style> 186 <script> 187 (function(){ 188 const tabs = document.querySelectorAll('.nav-tab'); 189 const contents = document.querySelectorAll('.telegram-tab-content'); 190 tabs.forEach(tab => { 191 tab.addEventListener('click', function(e) { 192 e.preventDefault(); 193 tabs.forEach(t => t.classList.remove('nav-tab-active')); 194 this.classList.add('nav-tab-active'); 195 contents.forEach(c => c.style.display = 'none'); 196 const sel = this.getAttribute('href'); 197 document.querySelector(sel).style.display = 'block'; 198 }); 199 }); 200 })(); 201 </script> 234 202 </div> 235 <?php } ?> -
telegram-bot/trunk/parse.php
r2981438 r3300993 3 3 4 4 if (!$json) { 5 telegram_log(' Warning','Webhook URL','Endpoint was called without input.');5 telegram_log('returned','',''); 6 6 return; 7 7 } … … 13 13 die(); 14 14 } 15 update_option('wp_telegram_last_id', $data['message']['message_id'] );15 update_option('wp_telegram_last_id', $data['message']['message_id']); 16 16 17 17 if ( $data['message']['chat']['type'] == 'private' ) { … … 25 25 $GROUP = true; $PRIVATE = false; 26 26 $COMMAND = $data['message']['text']; 27 } else if ( $data['my_chat_member']['chat']['type'] == 'supergroup' ) {28 $USERID = $data['my_chat_member']['chat']['id'];29 $CPT = 'telegram_groups';30 $GROUP = true; $PRIVATE = false;31 $COMMAND = '';32 27 } else if ( $data['callback_query']['message']['text'] ) { 33 28 $USERID = $data['callback_query']['message']['chat']['id']; … … 60 55 telegram_sendmessage( $USERID, telegram_option('wmuser') ); 61 56 } else if ( $GROUP ) { 62 $name = ''; 63 if ( isset( $data['message']['chat']['title'] ) ) { 64 $name = $data['message']['chat']['title']; 65 } else if ( isset( $data['my_chat_member']['chat']['title'] ) ) { 66 $name = $data['my_chat_member']['chat']['title']; 67 } 68 update_post_meta($p, 'telegram_name', $name ); 57 update_post_meta($p, 'telegram_name', $data['message']['chat']['title']); 69 58 telegram_log('', '', 'Bot added to <strong>'.$data['message']['chat']['title'].'</strong>'); 70 59 telegram_sendmessage( $USERID, telegram_option('wmgroup') ); … … 83 72 update_post_meta( $POST_ID, 'telegram_counter', $counter ); 84 73 } else if ($GROUP) { 85 update_post_meta($o->ID, 'telegram_name', 'xx');74 update_post_meta($o->ID, 'telegram_name', $data['message']['chat']['title']); 86 75 } 87 76 -
telegram-bot/trunk/readme.txt
r3110525 r3300993 1 1 === Telegram Bot & Channel === 2 Contributors: Milmor 3 Version: 3.8.24 Stable tag: 3.8.25 Author: Marco Milesi6 Author URI: https://profiles.wordpress.org/milmor/2 Contributors: Milmor, marcomilesi 3 Version: 4.0 4 Stable tag: 4.0 5 Author: Marco Milesi 6 Author URI: https://profiles.wordpress.org/milmor/ 7 7 Donate link: https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=F2JK36SCXKTE2 8 Tags: telegram, bot, newsletter, channel, group, automatic, stream, classicpress9 Requires at least: 3.810 Requires PHP: 5.611 Tested up to: 6. 58 Tags: telegram, bot, newsletter, channel, group, broadcast, automation, notifications, autoresponder, webhook, ssl, zapier, integration, marketing, customer-engagement, chatbot, wordpress, classicpress 9 Requires at least: 4.6 10 Requires PHP: 7.0 11 Tested up to: 6.9 12 12 License: GPLv2 or later 13 13 License URI: http://www.gnu.org/licenses/gpl-2.0.html 14 14 15 S end your posts to Telegram and build an interactive bot. Zapier integrated!15 Supercharge your WordPress site with Telegram! Broadcast posts, automate notifications, and build interactive bots for your users, groups, and channels. Secure, modern, and easy to use. Zapier integration included! 16 16 17 17 == Description == 18 18 19 This plugin allows you to accomplish a variety of tasks, including teaching, playing, searching, broadcasting, reminding, connecting, and integrating with your services. 20 21 With this powerful bot builder, you can: 22 23 🤖 **Build a bot**: create interactive autoresponders for users and groups 24 📣 **Broadcast to a channel**: utilize the broadcast feature to send messages to your channels and bot subscribers 25 26 https://youtu.be/8fckoWSmAks 27 28 = Bot features = 29 30 Enhance your content distribution strategy with these **free** advanced features: 31 32 📰 Send your content (post, page or custom messages) with templates 33 📅 Support for scheduled post broadcast 34 ⌨️ Utilize **keyboards** and **inline buttons** for enhanced user engagement 35 💬 Broadcast to various channels including chats, groups, supergroups, and channels 36 ↩️ Create unlimited autoresponders 37 📊 View insights about users and groups subscribed to your bot 38 📡 Haversine algorithm to get users' location and provide geo-focused content 39 🎨 Create custom applicatons with **/$command $var1 $var2** format for custom application creation 40 💡 **[Zapier](https://zapier.com)** integration to ensure seamless connectivity with your other tools 41 42 = Channel features = 43 📰 Send your content (post, page or custom messages) with configurable templates 44 📅 Support for scheduled post broadcast 45 💡 **[Zapier](https://zapier.com)** integration 46 47 **Note:** your bot must be administrator of your channel for sending messages 48 49 🔐 Every connection relies on secure webhooks for maximum security. Telegram requires **SSL** to manage a Telegram Bot. If you don't have it, just choose the free opt-in service [botpress.org](https://botpress.org) in options (the feature will send some data to our server). 50 51 = Zapier and IoT features = 52 Zapier makes it easy to automate tasks between web apps. For example: 53 54 * send a news published on a website (based on RSS) 55 * send the weather to your subscribers, every day 56 * inform users when you upload an image on Instagram 57 * and much more… With 400+ Zapier Apps supported! 58 59 https://www.youtube.com/watch?v=14aEV0_FHFk 60 61 = DEMO = 62 * **[CosenzApp_bot](http://telegram.me/CosenzApp_bot)** (italian) - Guide for Cosenza city 63 Want to showcase your work? contact us! 19 **Telegram Bot & Channel** is the all-in-one solution to connect your WordPress site with Telegram. Instantly broadcast posts, automate notifications, and create interactive bots for your audience. No coding required! 20 21 **Key Features:** 22 - 🤖 **Bot builder:** Create interactive autoresponders for users and groups 23 - 📣 **Broadcast:** Send posts, pages, or custom messages to your channels, groups, and subscribers 24 - 🔔 **Automated notifications:** Instantly notify your audience about new content 25 - 🔗 **Zapier integration:** Connect Telegram with 400+ apps and automate your workflows 26 - 🔐 **Secure:** All connections use Telegram WebHooks and require SSL for maximum security 27 - 🛡️ **Modern UI:** Clean, user-friendly admin panels with stats, logs, and quick actions 28 29 **Why choose this plugin?** 30 - 100% free and open source 31 - No third-party servers: your data stays on your site 32 - Easy setup: just add your bot token and go 33 - Developer-friendly: extend with custom PHP actions and filters 34 35 == Features == 36 37 **Bot & Broadcast:** 38 - Send posts, pages, or custom messages with flexible templates 39 - Schedule broadcasts for future posts 40 - Use custom keyboards and inline buttons for rich user interaction 41 - Broadcast to users, groups, supergroups, and channels 42 - Unlimited autoresponders and command triggers 43 - View insights about your Telegram audience 44 - Haversine algorithm for geo-targeted content 45 - Create custom applications with command variables 46 47 **Zapier & Automation:** 48 - Connect Telegram to 400+ apps (RSS, Instagram, Google Sheets, and more) 49 - Automate news, weather, social, and IoT notifications 50 - Easy Zapier invite and setup 51 52 **Security & Privacy:** 53 - All actions protected by WordPress nonces (CSRF protection) 54 - Only supports secure Telegram WebHooks (SSL required) 55 - No data sent to third-party servers (except optional Zapier integration) 56 57 **Screenshots:** 58 1. Modern dashboard with stats and recent activity 59 2. Subscribers list 60 3. Commands and autoresponders 61 4. Zapier integration 62 5. Plugin settings with tabs 63 6. Dynamic replies and inline buttons 64 7. Keyboard example 65 8. Post broadcasting 66 9. Native Gutenberg support 64 67 65 68 == Installation == 66 This section describes how to install the plugin and get it working. 67 68 1. Upload `telegram-bot` directory to the `/wp-content/plugins/` directory 69 2. Activate the plugin through the 'Plugins' menu in WordPress 69 1. Upload the `telegram-bot` directory to `/wp-content/plugins/` 70 2. Activate the plugin in the WordPress admin 70 71 3. Go to the Telegram settings page 71 4. Go through the steps and hit update! 72 4. Enter your bot token and configure your preferences 73 5. Enjoy automated Telegram notifications and bot features! 72 74 73 75 == Frequently Asked Questions == 74 More documentation is available on [www.botpress.org/docs](https://www.botpress.org/docs) 75 76 = How do I create a bot? = 77 [www.botpress.org/docs/telegram/how-to-create-a-bot](https://www.botpress.org/docs/telegram/how-to-create-a-bot/) 78 79 = How can i let users subscribe? = 80 [www.botpress.org/docs/telegram/how-do-users-subscribe](https://www.botpress.org/docs/telegram/how-do-users-subscribe/) 81 82 = What is Zapier and how do i integrate it? = 83 [www.botpress.org/docs/telegram/zapier-integration](https://www.botpress.org/docs/telegram/zapier-integration/) 84 85 = How to enable debug mode? = 86 If you are a developer, or just want a more complete "Telegram > Log" enable WP_DEBUG mode. 87 The plugin debug mode also allows to explore Telegram users and groups as standard posts. This let you to check custom fields for each users and modify them in real time. You'll notice a new column (= Telegram id for the user) in Subscribers and Groups page. 88 We don't suggest to keep WP_DEBUG if not for testing purposes. 89 90 = How to make dynamic replies? (PHP required) = 91 The best way to integrate PHP code is to build a custom integration plugin, but you can also add PHP to /$commands directly in your WordPress admin dashboard using the [Insert Php](https://wordpress.org/plugins/insert-php) plugin. 92 93 In case you want to scale and choose the first option, you can create a new file called **telegram-bot-custom.php** and upload it to wp-content/plugins. 94 95 The following example, once activated in the plugins list, will reply to `/command`: 96 97 `<?php 98 /* 99 Plugin Name: Telegram Bot & Channel (Custom) 100 Description: My Custom Telegram Plugin 101 Author: My name 102 Version: 1 103 */ 104 105 add_action('telegram_parse','telegramcustom_parse', 10, 2); 106 107 function telegramcustom_parse( $telegram_user_id, $text ) { 108 $plugin_post_id = telegram_getid( $telegram_user_id ); 109 110 if ( !$plugin_post_id ) { 111 return; 112 } 113 114 /* 115 Here is the dynamic processing and how to reply. 116 You can: 117 - use if, switch and everything that works in php 118 - check if $text is made of multiple words (create an array from $text) 119 - customize and code other actions (ex. create WordPress post is $telegram_user_id is your id) 120 */ 121 122 if ( $text == '/command') { 123 telegram_sendmessage( $telegram_user_id, 'Oh, yes you typed /command'); 124 } 125 126 return; 127 } 128 129 ?>` 130 131 = How to set up dynamic keyboards? = 132 You can send custom keyboards directly in php. Every keyboard can be set only when you send a message, and is kept in the client side until another keyboard is sent (in another message). You can also change this behaviour by setting the $one_time_keyboard true or false. 133 134 `telegram_sendmessage( $telegram_user_id, 'Hello from the other side!'); //Message with no keyboard (or with default one if set in plugin options) 135 telegram_sendmessage( $telegram_user_id, 'Hello from the other side!', telegram_build_reply_markup( '11,12,13;21,22', true )); //Message with custom keyboard` 136 137 Here is the details of telegram_build_reply_markup (an array is returned): 138 `telegram_build_reply_markup( 139 '11,12,13;21,22', //The keyboard template (eg. 2 row, 3 columns for the first one and two columns for the second one 140 true, // $one_time_keyboard (optional) (default false = kept until a new keyboard is sent) (true = kept until the user send something to the bot) 141 true // $resize_keyboard (optional) (default true) 142 );` 143 144 You can also alter keyboards for commands defined in the **admin area**. Start from the previous custom plugin created, and add the following filter: 145 146 `add_filter( 'telegram_get_reply_markup_filter', 'telegram_get_reply_markup_filter_custom', 1 ); 147 148 function telegram_get_reply_markup_filter_custom( $id ) { 149 if ( $id ) { 150 switch ( $id ) { 151 case 7: //Your command ID (found in the url while editing the command) 152 telegram_log('####', $id, 'custom keyboard'); //Useful for debug 153 return array( 154 'keyboard' => array(array('Top Left', 'Top Right'),array('Bottom')), 155 'resize_keyboard' => true, //true or false (suggested: true) 156 'one_time_keyboard' => true //true or false 157 ); 158 default: 159 return; 160 } 161 } 162 }` 163 164 = How to get user location? = 165 It's easy, with harvesine algorithm (one-point radius) or standard geolocation (4-points). 166 These snippets only cover the harvesine algorithm, that is simple and supported by the plugin. To use the standard 4-points geolocation it's enough to do some php-calc with basic if-then structures. 167 168 You can start from the previous custom plugin created, and add the following action: 169 170 `add_action('telegram_parse_location','telegramcustom_c_parse_location', 10, 3); 171 172 function telegramcustom_c_parse_location ( $telegram_user_id, $lat, $long ) { 173 174 if ( telegram_location_haversine_check ( 45.85, 9.70, $lat, $long, 20 ) ) { 175 telegram_sendmessage( $telegram_user_id, 'Inside the radius'); 176 } 177 178 }` 179 180 The examples sends a "Inside the radius" message when the user is inside the **20-meters** radius centered in 45.85 Lat, 9.70 Long. 181 182 You have two developer functions to use: 183 184 `//Check if point is within a distance (max_distance required) 185 $boolean = telegram_location_haversine_check ( $latitudeFrom, $longitudeFrom, $latitudeTo, $longitudeTo, $max_distance, $min_distance = 0, $earthRadius = 6371000); 186 187 //Calculate the distance 188 $int = telegram_location_haversine_distance ( $latitudeFrom, $longitudeFrom, $latitudeTo, $longitudeTo, $earthRadius = 6371000);` 189 190 The first function returns a boolean (true/false) depending on given parameters. Please note that $min_distance and $earthRadius are optional. 191 The second one returns a int (in meters) of the distance. $earthRadius optional. 192 193 Both the functions calculates distances on meters. If you want another type of result, just change the $earthRadius. 194 195 = How to get user photos? = 196 We've written simple functions to let developers build everything. 197 Photos are saved in **/wp-content/uploads/telegram-bot/'.$plugin_post_id.'/'.$file_name** where $plugin_post_id is the custom post type id associated with the Telegram subscription (ex. '24') and $file_name is time().$extension 198 199 `<?php 200 /* 201 Plugin Name: Telegram Bot & Channel (Custom) 202 Description: My Custom Telegram Plugin 203 Author: My name 204 Version: 1 205 */ 206 207 add_action('telegram_parse_photo','telegramcustom_parse_photo', 10, 2); 208 209 function telegramcustom_parse_photo ( $telegram_user_id, $photo ) { 210 211 $plugin_post_id = telegram_getid( $telegram_user_id ); 212 213 if ( !$plugin_post_id ) { 214 return; 215 } 216 217 /* 218 Here is the dynamic processing and how to reply. 219 You can: 220 - use if, switch and everything that works in php 221 - check if $text is made of multiple words (create an array from $text) 222 - customize and code other actions (ex. create WordPress post is $telegram_user_id is your id) 223 */ 224 225 /* 226 $photo[2]['file_id'] is only one of available sizes. You should make sure that this size exist, or check for another size. 227 $photo[1]['file_id'] has lower resolution 228 */ 229 $url = telegram_download_file( $telegram_user_id, $photo[2]['file_id'] ); //Fetch and save photo to your server 230 231 if ( $url ) { //$url is the local url because photo is already saved 232 233 //You can save the entry in your db 234 global $wpdb; 235 $arr = array( 'telegram_id' => $telegram_user_id, 'plugin_post_id' => $plugin_post_id, 'url' => $url ); 236 237 $wpdb->insert( 238 $wpdb->prefix . 'your_table_name_that_must_already_exist', $arr, array( '%s' ) 239 ); 240 241 //Or save it as custom field and use it for a Finite State Machine 242 update_post_meta( $plugin_post_id, 'telegram_custom_last_photo_received', $url ); 243 244 telegram_sendmessage( $telegram_user_id, 'Photo received. Thank you!'); 245 } 246 247 ?>` 248 249 Another example, that is a "emergency bot" created for the mid-italy earthquake (24 august 2016) is available on [GitHub](https://github.com/milesimarco/terremotocentroitalia-bot-telegram/) 76 77 = How do I create a Telegram bot? = 78 Visit [Telegram’s BotFather](https://core.telegram.org/bots#botfather) and follow the instructions to create a new bot and get your token. 79 80 = How do users subscribe? = 81 Users can start your bot or join your channel/group where the bot is an admin. 82 83 = How do I enable Zapier integration? = 84 Enable Zapier in the plugin settings and follow the invite link for setup instructions. 85 86 = Is SSL required? = 87 Yes, Telegram WebHooks require SSL. Your site must use HTTPS for the plugin to work. 88 89 = Can I extend the plugin? = 90 Yes! Use WordPress hooks and filters to add custom commands, keyboards, and integrations. See the FAQ and code comments for examples. 250 91 251 92 == Screenshots == 252 1. Plugin dashboard93 1. Modern dashboard with stats and recent activity 253 94 2. Subscribers list 254 3. Commands list 255 4. Autoresponders 256 5. Zapier integration 257 6. plugin options 258 7. Dynamic repliles and inline buttons example from [IcBrendola_bot](http://telegram.me/IcBrendola_bot) 259 8. Keyboard example from [CosenzApp_bot](http://telegram.me/CosenzApp_bot) 260 9. Post broadcasting (all post types) 261 10. Native Gutenberg support 95 3. Commands and autoresponders 96 4. Zapier integration 97 5. Plugin settings with tabs 98 6. Dynamic replies and inline buttons 99 7. Keyboard example 100 8. Post broadcasting 101 9. Native Gutenberg support 262 102 263 103 == Changelog == 264 104 265 = 3.8 2024-07-01 = 266 267 * [IMPROVE] Redesigned settings page with old settings cleanup 268 * [IMPROVE] Better Zapier handling 269 * [IMPROVE] Minor changes, code cleanup, security hardening and optimizations 270 271 = 3.7 20231020 = 272 * [NEW] Added ability to selectively send message to subscribed groups 273 * [BUGFIX] Fixed critical bug when sending to groups 274 * [BUGFIX] Minor changes and optimizations 275 * [NEW] Github deploy flow setup - https://github.com/WPGov/telegram-bot 105 = 4.0 20250526 = 106 * [SECURITY] Added CSRF protection (WordPress nonces) to all sensitive actions (log clear, send message, etc.) 107 * [SECURITY] Hardened webhook and Zapier endpoints, removed BotPress.org fallback (now only Telegram WebHooks are supported) 108 * [SECURITY] Improved admin access checks and output escaping throughout the plugin 109 * [IMPROVE] Redesigned all admin pages for a modern, user-friendly experience (dashboard, log, send message, settings) 110 * [IMPROVE] Settings page now uses tabs for easier navigation and clarity 111 * [IMPROVE] Removed all BotPress.org logic and references (service discontinued, SSL is now required) 112 * [IMPROVE] Inlined and refactored plugin defaults (removed defaults.php) 113 * [IMPROVE] Refactored admin notices for maintainability 114 * [IMPROVE] Enhanced log panel with better design and empty state 115 * [IMPROVE] Enhanced dashboard with stats, recent activity, and quick actions 116 * [IMPROVE] Improved send message panel with modern UI 117 * [IMPROVE] Cleaned up and secured Zapier integration 118 * [IMPROVE] General code cleanup, improved maintainability and best practices 119 * [IMPROVE] Updated documentation and removed outdated references 120 * [DEPRECATED] Removed all support for BotPress.org and non-SSL fallback 121 * [NOTE] This is a major update. Please review your settings and test your integration after updating. 276 122 277 123 = 3.6.3 20230527 = -
telegram-bot/trunk/telegram-bot.php
r3110525 r3300993 4 4 Plugin URI: https://wordpress.org/plugins/telegram-bot/ 5 5 Description: Broadcast your content to Telegram, build interactive bots and boost your omnichannel customer experience 6 Version: 3. 8.26 Version: 3.6.3 7 7 Author: Marco Milesi 8 8 Author URI: https://www.marcomilesi.com … … 15 15 require 'admin-messages.php'; 16 16 require 'panel/send.php'; 17 require 'panel/settings.php';18 17 19 18 add_action( 'plugins_loaded', function(){ … … 27 26 add_submenu_page('telegram_main', __('Send a message', 'telegram-bot'), __('Send a message', 'telegram-bot'), 'manage_options', 'telegram_send', 'telegram_send_panel' ); 28 27 add_submenu_page('telegram_main', __('Responders', 'telegram-bot'), __('Responders', 'telegram-bot'), 'manage_options', 'edit.php?post_type=telegram_commands'); 29 add_submenu_page('telegram_main', __('Settings', 'telegram-bot'), __('Settings', 'telegram-bot'), 'manage_options', 'telegram_settings', function(){ telegram_settings_page();});28 add_submenu_page('telegram_main', __('Settings', 'telegram-bot'), __('Settings', 'telegram-bot'), 'manage_options', 'telegram_settings', function(){require 'panel/settings.php';}); 30 29 add_submenu_page('telegram_main', 'Log', 'Log', 'manage_options', 'telegram_log', 'telegram_log_panel'); 31 30 }); 32 31 33 32 function telegram_log_panel() { 34 if (isset($_GET['tbclear'])) { 35 delete_option('wp_telegram_log'); 36 } 33 if (isset($_GET['tbclear'])) { 34 if (!isset($_GET['_wpnonce']) || !wp_verify_nonce($_GET['_wpnonce'], 'telegram_log_clear')) { 35 wp_die(__('Security check failed.','telegram-bot')); 36 } 37 delete_option('wp_telegram_log'); 38 } 37 39 $log = get_option('wp_telegram_log'); 38 39 echo '<div class="wrap"><h2>Activity log <a href="admin.php?page=telegram_log" class="add-new-h2">'.__('Reload', 'telegram-bot').'</a><a href="admin.php?page=telegram_log&tbclear=1" class="add-new-h2">'.__('Clear', 'telegram-bot').'</a></h2> 40 <table class="widefat fixed" cellspacing="0"> 41 <thead> 42 <tr> 43 <th style="width: 5%;" class="manage-column" scope="col">'.__('Type', 'telegram-bot').'</th> 44 <th style="width: 10%;" class="manage-column" scope="col">'.__('Date', 'telegram-bot').'</th> 45 <th style="width: 10%;" class="manage-column" scope="col">'.__('Author', 'telegram-bot').'</th> 46 <th id="columnname" class="manage-column" scope="col">'.__('Description', 'telegram-bot').'</th> 47 </tr> 48 </thead> 49 <tbody>'; 50 if ( is_array( $log ) ) { 40 echo '<div class="wrap telegram-log-panel">'; 41 echo '<h1 style="margin-bottom:24px;">'.__('Activity Log', 'telegram-bot').'</h1>'; 42 echo '<div style="margin-bottom:20px;">'; 43 echo '<a href="admin.php?page=telegram_log" class="button button-secondary" style="margin-right:10px;">'.__('Reload', 'telegram-bot').'</a>'; 44 echo '<a href="'.wp_nonce_url('admin.php?page=telegram_log&tbclear=1', 'telegram_log_clear').'" class="button button-danger" style="color:#fff;background:#d63638;border-color:#d63638;">'.__('Clear Log', 'telegram-bot').'</a>'; 45 echo '</div>'; 46 echo '<div style="overflow-x:auto;">'; 47 echo '<table class="widefat fixed striped" cellspacing="0" style="min-width:700px;">'; 48 echo '<thead><tr>'; 49 echo '<th style="width: 7%;">'.__('Type', 'telegram-bot').'</th>'; 50 echo '<th style="width: 15%;">'.__('Date', 'telegram-bot').'</th>'; 51 echo '<th style="width: 15%;">'.__('Author', 'telegram-bot').'</th>'; 52 echo '<th>'.__('Description', 'telegram-bot').'</th>'; 53 echo '</tr></thead><tbody>'; 54 if ( is_array( $log ) && count($log) ) { 51 55 foreach ( $log as $line ) { 52 56 echo '<tr>'; 53 echo '<td> ' . ( isset( $line[0] ) ? $line[0] : '' ) . '</td>';54 echo '<td>' . ( isset( $line[1] ) ? $line[1]: '' ) . '</td>';55 echo '<td>' . ( isset( $line[2] ) ? $line[2]: '' ) . '</td>';56 echo '<td>' . ( isset( $line[3] ) ? $line[3]: '' ) . '</td>';57 echo '<td><span style="font-weight:bold;color:#2271b1;">' . ( isset( $line[0] ) ? esc_html($line[0]) : '' ) . '</span></td>'; 58 echo '<td>' . ( isset( $line[1] ) ? esc_html($line[1]) : '' ) . '</td>'; 59 echo '<td>' . ( isset( $line[2] ) ? esc_html($line[2]) : '' ) . '</td>'; 60 echo '<td>' . ( isset( $line[3] ) ? esc_html($line[3]) : '' ) . '</td>'; 57 61 echo '</tr>'; 58 62 } 59 } 60 61 echo '</tbody> 62 </table></div>'; 63 } else { 64 echo '<tr><td colspan="4" style="text-align:center;color:#888;">'.__('No log entries found.', 'telegram-bot').'</td></tr>'; 65 } 66 echo '</tbody></table></div>'; 67 echo '<style>.telegram-log-panel .button-danger:hover{background:#a00!important;border-color:#a00!important;}</style>'; 68 echo '</div>'; 63 69 } 64 70 … … 89 95 90 96 function telegram_defaults() { 97 // Set API key if not set 91 98 if (!get_option('wp_telegram_apikey')) { 92 99 update_option('wp_telegram_apikey', md5(microtime() . rand() . get_site_url())); 93 100 } 94 101 // Set dispatches if not set 95 102 if (!get_option('wp_telegram_dispatches')) { 96 103 update_option('wp_telegram_dispatches', 0); 97 104 } 98 99 $defaults = array(100 array('token', ''),101 array('zapier', ''),102 array('wmgroup', 'Welcome!'),103 array('wmuser', 'Welcome, %FIRST_NAME%!'),104 array('posttemplate', '%TITLE%'.PHP_EOL.PHP_EOL.'%LINK%'),105 array('bmuser', 'Bye, %FIRST_NAME%. Type /start to enable the bot again.'),106 array('keyboard', '')105 // Set main plugin options 106 $defaults = array( 107 'token' => '', 108 'zapier' => '', 109 'wmgroup' => 'Welcome!', 110 'wmuser' => 'Welcome, %FIRST_NAME%!', 111 'posttemplate' => '%TITLE%' . PHP_EOL . PHP_EOL . '%LINK%', 112 'bmuser' => 'Bye, %FIRST_NAME%. Type /start to enable the bot again.', 113 'keyboard' => '' 107 114 ); 108 109 115 $my_options = get_option('wp_telegram'); 110 111 $conta = count($defaults); 112 113 for ($i = 0; $i < $conta; $i++) { 114 if (!isset( $my_options[$defaults[$i][0]] ) || !$my_options[$defaults[$i][0]]) { 115 $my_options[$defaults[$i][0]] = $defaults[$i][1]; 116 update_option('wp_telegram', $my_options); 117 } 116 if (!is_array($my_options)) { 117 $my_options = array(); 118 } 119 $changed = false; 120 foreach ($defaults as $key => $value) { 121 if (!isset($my_options[$key])) { 122 $my_options[$key] = $value; 123 $changed = true; 124 } 125 } 126 if ($changed) { 127 update_option('wp_telegram', $my_options); 118 128 } 119 129 } … … 127 137 if ($_GET['zap'] == get_option('wp_telegram_apikey') && telegram_option('zapier')) { 128 138 status_header( 200 ); 129 130 139 $json = file_get_contents('php://input'); 131 140 if (!$json) { … … 135 144 telegram_log('------>', 'ZAPIER', json_encode((array) file_get_contents("php://input"))); 136 145 telegram_sendmessagetoall($data['hook']); 137 138 146 } 139 147 } … … 198 206 if ($o) { 199 207 $text = str_replace('%FIRST_NAME%', get_post_meta($o->ID, 'telegram_name', true), $text); 208 $text = str_replace('%LAST_NAME%', get_post_meta($o->ID, '', true), $text); 200 209 } 201 210 }
Note: See TracChangeset
for help on using the changeset viewer.