-
Notifications
You must be signed in to change notification settings - Fork 1.6k
[V2] add inlinecallback to buttoncallback event #4252
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: v2
Are you sure you want to change the base?
Changes from 3 commits
8948c8c
c2509ad
51c2db9
69e741f
508a0ab
f726d1d
7408a43
8fdc255
fe87031
c0e09e9
5b33b4b
fbf0adb
9db309b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,6 @@ | ||
| from __future__ import annotations | ||
|
|
||
| from typing import TYPE_CHECKING, Dict, Optional, Self | ||
| from typing import TYPE_CHECKING, Dict, Optional, Self, Union | ||
|
|
||
| from ...tl import abcs, functions, types | ||
| from ..types import Chat, Message | ||
|
|
@@ -22,7 +22,7 @@ class ButtonCallback(Event): | |
| def __init__( | ||
| self, | ||
| client: Client, | ||
| update: types.UpdateBotCallbackQuery, | ||
| update: Union[types.UpdateBotCallbackQuery, types.UpdateInlineBotCallbackQuery], | ||
| chat_map: Dict[int, Chat], | ||
| ): | ||
| self._client = client | ||
|
|
@@ -33,7 +33,10 @@ def __init__( | |
| def _try_from_update( | ||
| cls, client: Client, update: abcs.Update, chat_map: Dict[int, Chat] | ||
| ) -> Optional[Self]: | ||
| if isinstance(update, types.UpdateBotCallbackQuery) and update.data is not None: | ||
| if ( | ||
| isinstance(update, (types.UpdateBotCallbackQuery, types.UpdateInlineBotCallbackQuery)) | ||
| and update.data is not None | ||
| ): | ||
| return cls._create(client, update, chat_map) | ||
| else: | ||
| return None | ||
|
|
@@ -43,6 +46,16 @@ def data(self) -> bytes: | |
| assert self._raw.data is not None | ||
| return self._raw.data | ||
|
|
||
| @property | ||
| def chat(self) -> Optional[Chat]: | ||
| """ | ||
| The :term:`chat` when the message was sent. | ||
| Only available if the event was triggered by a button under a usual message, not an inline one. | ||
| """ | ||
| if isinstance(self._raw, types.UpdateInlineBotCallbackQuery): | ||
| return None | ||
| return self._chat_map.get(peer_id(self._raw.peer)) | ||
|
|
||
| async def answer( | ||
| self, | ||
| text: Optional[str] = None, | ||
|
|
@@ -75,8 +88,10 @@ async def get_message(self) -> Optional[Message]: | |
| """ | ||
| Get the :class:`~telethon.types.Message` containing the button that was clicked. | ||
|
|
||
| If the message is too old and is no longer accessible, :data:`None` is returned instead. | ||
| If the message is inline, or too old and is no longer accessible, :data:`None` is returned instead. | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. But isn't the purpose of using But we should be able to fetch the message without a chat. So maybe we need to rethink this method's implementation. |
||
| """ | ||
| if isinstance(self._raw, types.UpdateInlineBotCallbackQuery): | ||
| return None | ||
|
|
||
| pid = peer_id(self._raw.peer) | ||
| chat = self._chat_map.get(pid) | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.