Skip to content

Instantly share code, notes, and snippets.

@JamshidbekAkhlidinov
Created July 26, 2024 06:31
Show Gist options
  • Save JamshidbekAkhlidinov/6f94010a471cedf7aa8e006b72f7aaa0 to your computer and use it in GitHub Desktop.
Save JamshidbekAkhlidinov/6f94010a471cedf7aa8e006b72f7aaa0 to your computer and use it in GitHub Desktop.
Telegram bot check join telegram channel
<?php
private function checkChannel()
{
$channels = KinoBotChannel::find()
->andWhere([
'status' => StatusEnum::ACTIVE
])
->all();
$channel_arr_status = [];
$channel_keyboard = new Keyboard();
$bot = $this->botApi;
$from_id = $bot->chat_id;
foreach ($channels as $channel) {
$join = $bot->getChatMember($channel->user_name, "$from_id");
if ($join['ok']) {
$result = $join['result'];
$chanel_status = in_array($result['status'], ['left', 'kicked']);
if ($chanel_status) {
$name = strtoupper(str_replace('@', '', $channel->user_name));
$channel_keyboard->addUrlButton(
"♻️ " . $name . " 📢",
str_replace('@', 'https://t.me/', $channel->user_name)
);
$channel_keyboard->newRow();
}
$channel_arr_status[] = $chanel_status;
}
}
$channel_keyboard->addCallbackDataButton(Yii::t('kino', "Confirm"), 'confirm_chanel');
if (in_array(1, $channel_arr_status)) {
$this->sendFrame(
new SubscriberChannelFrame($channel_keyboard),
);
return false;
}
return true;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment