← All changes
|
includes/Core/Integration/Telegram/TelegramHandler.php
+17
-12
2.0
→
2.15.3
View file →
| @@ -13,14 +13,16 @@ | ||
| 13 | 13 | |
| 14 | 14 | /** |
| 15 | 15 | * Provide functionality for Telegram integration |
| 16 | 16 | */ |
| 17 | -class TelegramHandler { | |
| 17 | +class TelegramHandler | |
| 18 | +{ | |
| 18 | 19 | private $_formID; |
| 19 | 20 | private $_integrationID; |
| 20 | - public const API_ENDPOINT = 'https://api.telegram.org/bot'; | |
| 21 | + public static $api_endpoint = 'https://api.telegram.org/bot'; | |
| 21 | 22 | |
| 22 | - public function __construct($integrationID, $fromID) { | |
| 23 | + public function __construct($integrationID, $fromID) | |
| 24 | + { | |
| 23 | 25 | $this->_formID = $fromID; |
| 24 | 26 | $this->_integrationID = $integrationID; |
| 25 | 27 | } |
| 26 | 28 | |
| @@ -28,9 +30,10 @@ | ||
| 28 | 30 | * Helps to register ajax function's with wp |
| 29 | 31 | * |
| 30 | 32 | * @return null |
| 31 | 33 | */ |
| 32 | - public static function registerAjax() { | |
| 34 | + public static function registerAjax() | |
| 35 | + { | |
| 33 | 36 | add_action('wp_ajax_bitforms_telegram_authorize', [__CLASS__, 'telegramAuthorize']); |
| 34 | 37 | add_action('wp_ajax_bitforms_refresh_get_updates', [__CLASS__, 'refreshGetUpdates']); |
| 35 | 38 | } |
| 36 | 39 | |
| @@ -38,9 +41,10 @@ | ||
| 38 | 41 | * Process ajax request for generate_token |
| 39 | 42 | * |
| 40 | 43 | * @return JSON zoho crm api response and status |
| 41 | 44 | */ |
| 42 | - public static function telegramAuthorize() { | |
| 45 | + public static function telegramAuthorize() | |
| 46 | + { | |
| 43 | 47 | $authorizationHeader = null; |
| 44 | 48 | if (isset($_REQUEST['_ajax_nonce']) && wp_verify_nonce($_REQUEST['_ajax_nonce'], 'bitforms_save')) { |
| 45 | 49 | $inputJSON = file_get_contents('php://input'); |
| 46 | 50 | $requestsParams = json_decode($inputJSON); |
| @@ -55,9 +59,9 @@ | ||
| 55 | 59 | 400 |
| 56 | 60 | ); |
| 57 | 61 | } |
| 58 | 62 | |
| 59 | - $apiEndpoint = self::API_ENDPOINT . $requestsParams->bot_api_key . '/getMe'; | |
| 63 | + $apiEndpoint = self::$api_endpoint . $requestsParams->bot_api_key . '/getMe'; | |
| 60 | 64 | $authorizationHeader['Accept'] = 'application/x-www-form-urlencoded'; |
| 61 | 65 | $apiResponse = HttpHelper::get($apiEndpoint, null, $authorizationHeader); |
| 62 | 66 | |
| 63 | 67 | if (is_wp_error($apiResponse) || !$apiResponse->ok) { |
| @@ -65,9 +69,9 @@ | ||
| 65 | 69 | empty($apiResponse->error_code) ? 'Unknown' : $apiResponse, |
| 66 | 70 | 400 |
| 67 | 71 | ); |
| 68 | 72 | } |
| 69 | - $apiEndpoint = self::API_ENDPOINT . $requestsParams->bot_api_key . '/getUpdates'; | |
| 73 | + $apiEndpoint = self::$api_endpoint . $requestsParams->bot_api_key . '/getUpdates'; | |
| 70 | 74 | $authorizationHeader['Accept'] = 'application/x-www-form-urlencoded'; |
| 71 | 75 | $apiResponse = HttpHelper::get($apiEndpoint, null, $authorizationHeader); |
| 72 | 76 | |
| 73 | 77 | if (is_wp_error($apiResponse) || !$apiResponse->ok) { |
| @@ -93,9 +97,10 @@ | ||
| 93 | 97 | * Process ajax request for refresh telegram get Updates |
| 94 | 98 | * |
| 95 | 99 | * @return JSON telegram get Updates data |
| 96 | 100 | */ |
| 97 | - public static function refreshGetUpdates() { | |
| 101 | + public static function refreshGetUpdates() | |
| 102 | + { | |
| 98 | 103 | $authorizationHeader = null; |
| 99 | 104 | $response = null; |
| 100 | 105 | if (isset($_REQUEST['_ajax_nonce']) && wp_verify_nonce($_REQUEST['_ajax_nonce'], 'bitforms_save')) { |
| 101 | 106 | $inputJSON = file_get_contents('php://input'); |
| @@ -110,9 +115,9 @@ | ||
| 110 | 115 | ), |
| 111 | 116 | 400 |
| 112 | 117 | ); |
| 113 | 118 | } |
| 114 | - $apiEndpoint = self::API_ENDPOINT . $requestsParams->bot_api_key . '/getUpdates'; | |
| 119 | + $apiEndpoint = self::$api_endpoint . $requestsParams->bot_api_key . '/getUpdates'; | |
| 115 | 120 | $authorizationHeader['Accept'] = 'application/json'; |
| 116 | 121 | $telegramResponse = HttpHelper::get($apiEndpoint, null, $authorizationHeader); |
| 117 | 122 | |
| 118 | 123 | $allList = []; |
| @@ -147,11 +152,11 @@ | ||
| 147 | 152 | ); |
| 148 | 153 | } |
| 149 | 154 | } |
| 150 | 155 | |
| 151 | - public function execute(IntegrationHandler $integrationHandler, $integrationData, $fieldValues, $entryID, $logID) { | |
| 156 | + public function execute(IntegrationHandler $integrationHandler, $integrationData, $fieldValues, $entryID, $logID) | |
| 157 | + { | |
| 152 | 158 | $integrationDetails = is_string($integrationData->integration_details) ? json_decode($integrationData->integration_details) : $integrationData->integration_details; |
| 153 | - // var_dump($integrationDetails); die; | |
| 154 | 159 | |
| 155 | 160 | $bot_api_key = $integrationDetails->bot_api_key; |
| 156 | 161 | $parse_mode = $integrationDetails->parse_mode; |
| 157 | 162 | $chat_id = $integrationDetails->chat_id; |
| @@ -164,9 +169,9 @@ | ||
| 164 | 169 | || empty($body) |
| 165 | 170 | ) { |
| 166 | 171 | return new WP_Error('REQ_FIELD_EMPTY', __('module, fields are required for Telegram api', 'bit-form')); |
| 167 | 172 | } |
| 168 | - $recordApiHelper = new RecordApiHelper(self::API_ENDPOINT . $bot_api_key, $this->_integrationID, $logID, $entryID); | |
| 173 | + $recordApiHelper = new RecordApiHelper(self::$api_endpoint . $bot_api_key, $this->_integrationID, $logID, $entryID); | |
| 169 | 174 | $telegramApiResponse = $recordApiHelper->executeRecordApi( |
| 170 | 175 | $integrationDetails, |
| 171 | 176 | $fieldValues, |
| 172 | 177 | $this->_formID, |