from aiogram import Bot as AiogramBot, Dispatcher, executor, types
from aiogram.types.reply_keyboard import (ReplyKeyboardMarkup, KeyboardButton, KeyboardButtonRequestChat,
KeyboardButtonRequestUser)
from aiogram.types import CallbackQuery
bot_token = ""
bot = AiogramBot(bot_token)
dp = Dispatcher(bot)
@dp.message_handler(content_types=['text'])
async def text_handler(message: types.Message):
await message.answer("I'm here", reply_markup=ReplyKeyboardMarkup(
[
[
KeyboardButton("test1", request_chat=KeyboardButtonRequestChat(
request_id=1,
user_is_bot=False,
chat_is_channel=True,
chat_is_forum=False
)),
KeyboardButton("test2", request_user=KeyboardButtonRequestUser(
request_id=2,
user_is_bot=False,
chat_is_channel=False,
chat_is_forum=False
)),
]
]
))
@dp.callback_query_handler(lambda c: c.request_chat and c.request_chat.request_id == 1)
async def handle_request_chat(callback_query: CallbackQuery):
chat_info = callback_query.message.chat
await bot.send_message(callback_query.from_user.id, f"Вы выбрали канал с ID: {chat_info.id}")
if __name__ == "__main__":
executor.start_polling(dp)
import asyncio
from aiogram import Bot, Dispatcher, F
from aiogram.filters.callback_data import CallbackData
from aiogram.fsm.storage.memory import MemoryStorage
from aiogram.filters import Command, BaseFilter
from aiogram.types import InlineKeyboardMarkup, InlineKeyboardButton, CallbackQuery, ReplyKeyboardMarkup, \
KeyboardButtonRequestChat
from aiogram.utils.keyboard import InlineKeyboardBuilder
from aiogram.types import (
KeyboardButton,
Message)
TOKEN = ""
bot = Bot(TOKEN)
dp = Dispatcher(storage=MemoryStorage())
@dp.message(F.text.contains("/start"))
async def text_handler(message: Message):
await message.answer("I'm here", reply_markup=ReplyKeyboardMarkup(keyboard=
[
[
KeyboardButton(text="test1", request_chat=KeyboardButtonRequestChat(
request_id=1,
user_is_bot=False,
chat_is_channel=True,
chat_is_forum=False
)),
KeyboardButton(text="test2", request_chat=KeyboardButtonRequestChat(
request_id=2,
user_is_bot=False,
chat_is_channel=False,
chat_is_forum=False
)),
]
]
))
@dp.message(F.chat)
async def handle_request_chat(msg: Message):
chat_info = msg.chat_shared.chat_id
await bot.send_message(msg.from_user.id, f"Вы выбрали канал с ID: {chat_info}")
async def main():
await dp.start_polling(bot)
if __name__ == "__main__":
asyncio.run(main())