/** * Send a Telegram notification if the API Token has been set up * * @param string $message * @param string $intro * @access protected * @author Anton Zaroutski <*****@*****.**> */ protected function _send_suggestion_notification_to_telegram($intro, $message) { global $tdata; global $current_user; $telegram_api_token = $current_user->telegram_api_token; $nt = new Notifcaster_Class(); $_apitoken = $telegram_api_token; $_msg = "\n" . $intro . "\n\n" . $message; if ($tdata['twp_hashtag']->option_value != '') { $_msg = $tdata['twp_hashtag']->option_value . "\n" . $_msg; } $nt->Notifcaster($_apitoken); if (mb_strlen($_msg) > 4096) { $splitted_text = $this->str_split_unicode($_msg, 4096); foreach ($splitted_text as $text_part) { $nt->notify($text_part); } } else { $nt->notify($_msg); } }
function twp_ajax_test_callback() { $nt = new Notifcaster_Class(); switch ($_POST['subject']) { case 'm': //This will send a test message. $nt->Notifcaster($_POST['api_token']); $result = $nt->notify($_POST['msg']); echo json_encode($result); wp_die(); break; case 'c': $nt->_telegram($_POST['bot_token'], $_POST['markdown'], $_POST['web_preview']); $msg = str_replace("\\", "", $_POST['msg']); $result = $nt->channel_text($_POST['channel_username'], $msg); echo json_encode($result); wp_die(); break; case 'b': $nt->_telegram($_POST['bot_token']); $result = $nt->get_bot(); echo json_encode($result); wp_die(); break; default: return "Invalid POST request"; break; } }