The button and event type "KeyboardButtonRequestChat" does not exist!
Lucasmm016 opened this issue · comments
Code that causes the issue
button = Button.request_chat("Select channel") # button type dont exist!
# or
button = KeyboardButtonRequestChat("Select channel") # "KeyboardButtonRequestChat" button type dont exist!
# or
@bot.on(telethon.events.KeyboardButtonRequestChat) # event dont exist!
async def handler(event): ...
Expected behavior
It is expected that there will be a button and an event of the type "request_chat" or "KeyboardButtonRequestChat", as found in the Telegram documentation at https://core.telegram.org/bots/api#keyboardbuttonrequestchat
Actual behavior
AttributeError: type object 'Button' has no attribute 'request_chat'
# or
AttributeError: module 'telethon.events' has no attribute 'KeyboardButtonRequestChat'
Traceback
No response
Telethon version
1.35.0
Python version
3.11.2
Operating system (including distribution name and version)
macOS
Other details
Here is the link to the official Telegram API documentation: https://core.telegram.org/bots/api#keyboardbuttonrequestchat
Example of use with the Bot API to get around the Button type not existing:
buttons = [
{
"text": "Select Channel",
"request_chat": {
"request_id": 1, # button id
"chat_is_channel": True,
"title": "Select channel",
}
}
]
reply_markup = {"keyboard": [buttons],
"resize_keyboard": True, "one_time_keyboard": True}
url = f"https://api.telegram.org/bot{token}/sendMessage"
payload = {
"chat_id": chat_id,
"text": "Click in the button and select channel",
"reply_markup": json.dumps(reply_markup)
}
response = requests.post(url, data=payload)
Example of use to get around the non-existing Event type:
@bot.on(events.Raw(types=UpdateNewMessage))
async def on_requested_peer_channel(event):
try:
if event.message.action.peers[0].__class__.__name__ == "RequestedPeerChannel":
button_id = event.message.action.button_id
if button_id == 1: # button id
peer = event.message.action.peers[0]
channel_id = peer.channel_id
title = peer.title
except:
...
The same applies to "KeyboardButtonRequestUsers".
Checklist
- The error is in the library's code, and not in my own.
- I have searched for this issue before posting it and there isn't an open duplicate.
- I ran
pip install -U https://github.com/LonamiWebs/Telethon/archive/v1.zip
and triggered the bug in the latest version.
No new features are intended for v1. events.Raw
is the correct type for the time being.
No new features are intended for v1.
events.Raw
is the correct type for the time being.
I understood! I thought it was a glitch! Thanks for letting me know, this is a very useful feature, I hope it exists in the next versions.