@@ -13,7 +13,7 @@ discard block |
||
| 13 | 13 | use CURLFile; |
| 14 | 14 | |
| 15 | 15 | class webhook extends receiver {
|
| 16 | - public static function init () {
|
|
| 16 | + public static function init() {
|
|
| 17 | 17 | if (settings::$multi) {
|
| 18 | 18 | multi::init(); |
| 19 | 19 | } |
@@ -42,26 +42,26 @@ discard block |
||
| 42 | 42 | } |
| 43 | 43 | } |
| 44 | 44 | |
| 45 | - protected static function setWebhook(string $url,string $secret = '') {
|
|
| 45 | + protected static function setWebhook(string $url, string $secret = '') {
|
|
| 46 | 46 | $res = telegram::setWebhook($url, settings::$certificate, max_connections:settings::$max_connection, allowed_updates : settings::$allowed_updates, secret_token: $secret); |
| 47 | 47 | if (telegram::$status) {
|
| 48 | - logger::write('Webhook was set successfully',loggerTypes::INFO);
|
|
| 48 | + logger::write('Webhook was set successfully', loggerTypes::INFO);
|
|
| 49 | 49 | } |
| 50 | 50 | else {
|
| 51 | - logger::write("There is some problem happened , telegram response : \n".json_encode($res),loggerTypes::ERROR);
|
|
| 52 | - BPT::exit(print_r($res,true)); |
|
| 51 | + logger::write("There is some problem happened , telegram response : \n".json_encode($res), loggerTypes::ERROR);
|
|
| 52 | + BPT::exit(print_r($res, true)); |
|
| 53 | 53 | } |
| 54 | 54 | } |
| 55 | 55 | |
| 56 | 56 | protected static function checkURL() {
|
| 57 | 57 | if (!(isset($_SERVER['SERVER_NAME']) && isset($_SERVER['REQUEST_URI']))) {
|
| 58 | - logger::write('For using webhook receiver , you should open this file in your webserver(by domain)',loggerTypes::ERROR);
|
|
| 58 | + logger::write('For using webhook receiver , you should open this file in your webserver(by domain)', loggerTypes::ERROR);
|
|
| 59 | 59 | throw new bptException('WEBHOOK_NEED_URL');
|
| 60 | 60 | } |
| 61 | 61 | } |
| 62 | 62 | |
| 63 | 63 | private static function setURL(): string {
|
| 64 | - return (isset(settings::$certificate) ? 'http://' : 'https://') . $_SERVER['SERVER_NAME'] . $_SERVER['SCRIPT_NAME']; |
|
| 64 | + return (isset(settings::$certificate) ? 'http://' : 'https://').$_SERVER['SERVER_NAME'].$_SERVER['SCRIPT_NAME']; |
|
| 65 | 65 | } |
| 66 | 66 | |
| 67 | 67 | protected static function setCertificate() {
|
@@ -83,15 +83,15 @@ discard block |
||
| 83 | 83 | self::setCertificate(); |
| 84 | 84 | $url = self::setURL(); |
| 85 | 85 | $secret = tools::randomString(64); |
| 86 | - self::setWebhook($url,$secret); |
|
| 87 | - lock::save('BPT-HOOK',$secret);
|
|
| 86 | + self::setWebhook($url, $secret); |
|
| 87 | + lock::save('BPT-HOOK', $secret);
|
|
| 88 | 88 | BPT::exit('Done');
|
| 89 | 89 | } |
| 90 | 90 | |
| 91 | 91 | private static function checkSecret() {
|
| 92 | 92 | $secret = lock::read('BPT-HOOK');
|
| 93 | 93 | if (!isset($_SERVER['HTTP_X_TELEGRAM_BOT_API_SECRET_TOKEN']) || $_SERVER['HTTP_X_TELEGRAM_BOT_API_SECRET_TOKEN'] != $secret) {
|
| 94 | - logger::write('This is not webhook set by BPT, webhook will reset',loggerTypes::WARNING);
|
|
| 94 | + logger::write('This is not webhook set by BPT, webhook will reset', loggerTypes::WARNING);
|
|
| 95 | 95 | self::processSetWebhook(); |
| 96 | 96 | } |
| 97 | 97 | } |
@@ -16,15 +16,13 @@ discard block |
||
| 16 | 16 | public static function init () {
|
| 17 | 17 | if (settings::$multi) {
|
| 18 | 18 | multi::init(); |
| 19 | - } |
|
| 20 | - else {
|
|
| 19 | + } else {
|
|
| 21 | 20 | if (lock::exist('BPT-HOOK')) {
|
| 22 | 21 | receiver::telegramVerify(); |
| 23 | 22 | self::checkSecret(); |
| 24 | 23 | receiver::processUpdate(); |
| 25 | 24 | logger::write('Update received , lets process it ;)');
|
| 26 | - } |
|
| 27 | - else {
|
|
| 25 | + } else {
|
|
| 28 | 26 | self::processSetWebhook(); |
| 29 | 27 | } |
| 30 | 28 | } |
@@ -46,8 +44,7 @@ discard block |
||
| 46 | 44 | $res = telegram::setWebhook($url, settings::$certificate, max_connections:settings::$max_connection, allowed_updates : settings::$allowed_updates, secret_token: $secret); |
| 47 | 45 | if (telegram::$status) {
|
| 48 | 46 | logger::write('Webhook was set successfully',loggerTypes::INFO);
|
| 49 | - } |
|
| 50 | - else {
|
|
| 47 | + } else {
|
|
| 51 | 48 | logger::write("There is some problem happened , telegram response : \n".json_encode($res),loggerTypes::ERROR);
|
| 52 | 49 | BPT::exit(print_r($res,true)); |
| 53 | 50 | } |
@@ -69,8 +66,7 @@ discard block |
||
| 69 | 66 | if (is_string(settings::$certificate)) {
|
| 70 | 67 | if (file_exists(settings::$certificate)) {
|
| 71 | 68 | settings::$certificate = new CURLFile(settings::$certificate); |
| 72 | - } |
|
| 73 | - else {
|
|
| 69 | + } else {
|
|
| 74 | 70 | settings::$certificate = null; |
| 75 | 71 | } |
| 76 | 72 | } |