Skip to content

Commit 0c2e39f

Browse files
committed
fix: telegram fetch chat list issue
1 parent 8be4ef9 commit 0c2e39f

File tree

1 file changed

+15
-17
lines changed

1 file changed

+15
-17
lines changed

includes/Actions/Telegram/TelegramController.php

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66

77
namespace BitCode\FI\Actions\Telegram;
88

9-
use BitCode\FI\Core\Util\HttpHelper;
109
use WP_Error;
10+
use BitCode\FI\Core\Util\HttpHelper;
1111

1212
/**
1313
* Provide functionality for Telegram integration
@@ -88,26 +88,24 @@ public static function refreshGetUpdates($requestsParams)
8888
$authorizationHeader['Accept'] = 'application/json';
8989
$telegramResponse = HttpHelper::get($apiEndpoint, null, $authorizationHeader);
9090

91+
if (is_wp_error($telegramResponse) || empty($telegramResponse->ok)) {
92+
wp_send_json_error($telegramResponse->description, 400);
93+
}
94+
9195
$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;
10099
}
101-
uksort($allList, 'strnatcasecmp');
102100

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+
];
109105
}
110-
wp_send_json_success($response, 200);
106+
uksort($allList, 'strnatcasecmp');
107+
108+
wp_send_json_success(['telegramChatLists' => $allList], 200);
111109
}
112110

113111
public function execute($integrationData, $fieldValues)

0 commit comments

Comments
 (0)