A
A
ambal2452021-12-31 15:53:03
PHP
ambal245, 2021-12-31 15:53:03

Why is the channel subscription check condition not working?

private function scanChannelUser($chat_id) {
$scan = json_decode($this->botApiQuery("getChatMember", ['chat_id' =>  $this->channel, 'user_id' => $chat_id]), true);
         if($scan['rusult']['status'] == 'left'){
             return false; 
         } else {
            return true;
         }
}

I check participation with the code above. Then I send a message to the user
$this->sendMessage($user_id, $text, $buttons);
private function sendMessage($user_id, $text, $buttons = NULL) {
        if ($this->scanChannelUser($user_id) == true) {
            // готовим массив данных
            $data_send = [ 'chat_id' => $user_id,
                           'text' => $text,
                           'parse_mode' => 'html' ];
            // если переданны кнопки то добавляем их к сообщению
            if (!is_null($buttons) && is_array($buttons)) {
                $data_send['reply_markup'] = $this->buildInlineKeyBoard($buttons);
            }
            // отправляем текстовое сообщение
            return $this->botApiQuery("sendMessage", $data_send);
        } else {
            // готовим кнопку на подписку
            $button[] = [$this->buildInlineKeyBoardButton('ПОДПИСАТЬСЯ', '', $this->subscribeLink)];
            // отправляем текстовое сообщение
            return $this->botApiQuery("sendMessage", [  'chat_id' => $user_id, 
                                                        'text' =>  $this->subscribeText,
                                                        'reply_markup' => $this->buildInlineKeyBoard($button)]);
            }
        }

And the subscription message is not being sent.

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question