Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from pyrogram import Client, filters
- from pyrogram.types import ReplyKeyboardRemove
- from pyrogram.utils import get_peer_id
- from pyrogram.raw.functions.messages import SendMessage
- from pyrogram.raw.types import (
- ReplyKeyboardMarkup,
- KeyboardButtonRow as row,
- KeyboardButtonRequestPeer as btn,
- RequestPeerTypeBroadcast as broadcast,
- RequestPeerTypeChat as group,
- RequestPeerTypeUser as user,
- UpdateNewMessage,
- MessageService,
- MessageActionRequestedPeer as action,
- )
- @Client.on_message(filters.private & filters.command("pick"))
- async def send_button(client, message):
- reply_markup = ReplyKeyboardMarkup(
- rows=[
- row(
- buttons=[
- btn(text="Select Channel", button_id=1, peer_type=broadcast()),
- btn(text="Select Group", button_id=2, peer_type=group()),
- ]
- ),
- row(
- buttons=[
- btn(text="Select User", button_id=3, peer_type=user(bot=False)),
- btn(text="Select Bot", button_id=4, peer_type=user(bot=True)),
- ]
- ),
- ],
- resize=True,
- )
- await client.invoke(
- SendMessage(
- peer=await client.resolve_peer(message.chat.id),
- message="Pick a chat:",
- reply_markup=reply_markup,
- random_id=client.rnd_id(),
- )
- )
- chat_types = {1: "channel", 2: "group", 3: "user", 4: "bot"}
- @Client.on_raw_update()
- async def get_selected_chat(client, update, _, __):
- if not isinstance(update, UpdateNewMessage):
- return
- if not isinstance(update.message, MessageService):
- return
- if not isinstance(update.message.action, action):
- return
- from_user = get_peer_id(update.message.peer_id)
- chat = get_peer_id(update.message.action.peer)
- type = chat_types.get(update.message.action.button_id)
- await client.send_message(
- from_user,
- f"`You have shared a {type} with ID: {chat}`",
- reply_markup=ReplyKeyboardRemove(),
- )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement