|
6 | 6 |
|
7 | 7 | namespace BitCode\FI\Actions\Telegram; |
8 | 8 |
|
9 | | -use BitCode\FI\Core\Util\HttpHelper; |
10 | 9 | use WP_Error; |
| 10 | +use BitCode\FI\Core\Util\HttpHelper; |
11 | 11 |
|
12 | 12 | /** |
13 | 13 | * Provide functionality for Telegram integration |
@@ -88,26 +88,24 @@ public static function refreshGetUpdates($requestsParams) |
88 | 88 | $authorizationHeader['Accept'] = 'application/json'; |
89 | 89 | $telegramResponse = HttpHelper::get($apiEndpoint, null, $authorizationHeader); |
90 | 90 |
|
| 91 | + if (is_wp_error($telegramResponse) || empty($telegramResponse->ok)) { |
| 92 | + wp_send_json_error($telegramResponse->description, 400); |
| 93 | + } |
| 94 | + |
91 | 95 | $allList = []; |
92 | | - if (!is_wp_error($telegramResponse) && $telegramResponse->ok) { |
93 | | - $telegramChatLists = $telegramResponse->result; |
94 | | - |
95 | | - foreach ($telegramChatLists as $list) { |
96 | | - $allList[$list->my_chat_member->chat->title] = (object) [ |
97 | | - 'id' => $list->my_chat_member->chat->id, |
98 | | - 'name' => $list->my_chat_member->chat->title, |
99 | | - ]; |
| 96 | + foreach ($telegramResponse->result as $list) { |
| 97 | + if (empty($list->my_chat_member)) { |
| 98 | + continue; |
100 | 99 | } |
101 | | - uksort($allList, 'strnatcasecmp'); |
102 | 100 |
|
103 | | - $response['telegramChatLists'] = $allList; |
104 | | - } else { |
105 | | - wp_send_json_error( |
106 | | - $telegramResponse->description, |
107 | | - 400 |
108 | | - ); |
| 101 | + $allList[$list->my_chat_member->chat->title] = (object) [ |
| 102 | + 'id' => $list->my_chat_member->chat->id, |
| 103 | + 'name' => $list->my_chat_member->chat->title, |
| 104 | + ]; |
109 | 105 | } |
110 | | - wp_send_json_success($response, 200); |
| 106 | + uksort($allList, 'strnatcasecmp'); |
| 107 | + |
| 108 | + wp_send_json_success(['telegramChatLists' => $allList], 200); |
111 | 109 | } |
112 | 110 |
|
113 | 111 | public function execute($integrationData, $fieldValues) |
|
0 commit comments