Skip to content
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

Telegram message interface made asynchronous #365

Closed
wants to merge 152 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
152 commits
Select commit Hold shift + click to select a range
ae091ab
new telegram message proposal
pseusys Jan 22, 2024
b1c4da9
only required attachments remain
pseusys Jan 22, 2024
86c15c2
keyboard implemented
pseusys Jan 23, 2024
a0a859c
tests reworked
pseusys Jan 29, 2024
89fa2c7
telegram examples debugged
pseusys Jan 31, 2024
3745cff
optional attachment processing added
pseusys Jan 31, 2024
26dc2d6
download all removed, special downloading method created
pseusys Feb 4, 2024
7e65068
callback query added as an attachment
pseusys Feb 7, 2024
efece76
callback query conditions added
pseusys Feb 7, 2024
c947b4e
remove tg tests; move message tests to core tests
RLKRo Feb 22, 2024
25b8ac9
buttons pulled out of attachments list
pseusys Feb 28, 2024
a6c1172
merge
RLKRo Mar 7, 2024
b67b497
some errors fixed
pseusys Mar 12, 2024
68b4a37
review issues fixed
pseusys Mar 18, 2024
efde7c3
Merge remote-tracking branch 'origin/dev' into feat/telegram_interfac…
pseusys Mar 18, 2024
f9a9d79
Merge branch 'dev' into feat/telegram_interface_upgrade
pseusys Mar 18, 2024
6f8de0b
lock file updated
pseusys Mar 18, 2024
771370d
typing fixed
pseusys Mar 18, 2024
1c85052
circular import resolved
pseusys Mar 18, 2024
0cebb97
one more attempt to fix circular import
pseusys Mar 18, 2024
a5f0e02
populate attachment method made implemented
pseusys Mar 19, 2024
01947dd
CLI interface separated
pseusys Mar 19, 2024
5e35935
data message equation fixed
pseusys Mar 19, 2024
513f77a
lint applied
pseusys Mar 19, 2024
48bb29f
move callback query to script.conditions
RLKRo Mar 20, 2024
e2ea371
condition signature fix
pseusys Mar 21, 2024
ea66537
messenger interface parameter added to `get_bytes` method
pseusys Mar 21, 2024
db1de9a
async def removed from `extract_message_from_telegram` function
pseusys Mar 21, 2024
19d00f3
docs fixed
pseusys Mar 21, 2024
11cc1a3
condition import added
pseusys Mar 21, 2024
66f82b1
two attachment tutorials fixed
pseusys Mar 22, 2024
2773c9d
attachment tuples changed to sets
pseusys Mar 22, 2024
80fceb5
lint applied
pseusys Mar 22, 2024
a5fbe60
docs links fixed
pseusys Mar 22, 2024
8e970c9
Merge branch 'dev' into feat/telegram_interface_upgrade
pseusys Mar 27, 2024
3f815e7
Merge branch 'feat/telegram_interface_upgrade' of https://github.com/…
pseusys Mar 27, 2024
f8cecdf
telegram formatted
pseusys Mar 27, 2024
95019ad
lock update
pseusys Mar 27, 2024
8c90763
tuples replaced with sets everywhere
pseusys Mar 27, 2024
30db35a
telegram-specific request attachments added
pseusys Apr 4, 2024
1432893
attachment subclasses moved to extras
pseusys Apr 9, 2024
1bfe524
extras added
pseusys Apr 10, 2024
82e7a3e
lint fixed
pseusys Apr 11, 2024
334cd74
ui replaced with keyboard
pseusys Apr 16, 2024
fb2e90a
Merge branch 'feat/telegram_interface_upgrade' of https://github.com/…
pseusys Apr 16, 2024
bc406f6
"check_if_" removed
pseusys Apr 16, 2024
b08e8f3
undefined message removed
pseusys Apr 16, 2024
c79a732
unnecessary type casting removed
pseusys Apr 16, 2024
7853dbc
args and kwargs removed
pseusys Apr 16, 2024
5b9992f
default poll option voter count added
pseusys Apr 16, 2024
a3beac9
telegram import check added
pseusys Apr 16, 2024
5dd0751
interface attachments sorted
pseusys Apr 16, 2024
b951772
temp attachment dir warning added
pseusys Apr 16, 2024
fe99c4c
attachment message clarified
pseusys Apr 16, 2024
595d55d
single attachment sending proposal + sticker
pseusys Apr 18, 2024
b31ea18
request and response attachments sorted
pseusys Apr 18, 2024
c882abf
Merge branch 'feat/telegram_interface_upgrade' of https://github.com/…
pseusys Apr 18, 2024
dd57886
attachments tutorial added
pseusys Apr 22, 2024
33c72cb
advanced tutorial added
pseusys Apr 23, 2024
17280e3
`cached_filename` field added
pseusys Apr 26, 2024
2a1f01a
Tutorial texts altered.
pseusys Apr 26, 2024
fb58bda
happy path removed, use cache flag added
pseusys Apr 26, 2024
a2e0ca3
literals added + tests started
pseusys May 1, 2024
a07b73b
Attachment links updated
pseusys May 7, 2024
87001c0
new_attachment_tests_added
pseusys May 7, 2024
aabb3f8
Merge branch 'feat/telegram_interface_upgrade' of https://github.com/…
pseusys May 7, 2024
b4dd7fc
Merge branch 'dev' into feat/telegram_interface_upgrade
pseusys May 7, 2024
f478972
Merge branch 'feat/telegram_interface_upgrade' of https://github.com/…
pseusys May 7, 2024
f1a140a
parametrize fixed for telegram testing
pseusys May 7, 2024
3b04c03
Some lint fixed
pseusys May 7, 2024
4db3d6f
file path fixed
pseusys May 7, 2024
74a0402
attachments type fixed
pseusys May 8, 2024
9bc4b3c
supported attachment sets renamed
pseusys May 8, 2024
cb28fe3
final message test fixed
pseusys May 8, 2024
d30358b
dot path used instead of slash
pseusys May 8, 2024
eaad6d2
tutorial tests fixed
pseusys May 8, 2024
c77f41f
fixed getattribute stack overflow exception
pseusys May 8, 2024
28d7f8a
true transition fixed
pseusys May 8, 2024
786b3c7
async function marked
pseusys May 8, 2024
2277af7
cache dir clear and create reversed
pseusys May 8, 2024
6e218b6
pytest warning fixed
pseusys May 8, 2024
e6d1226
tutorial testing done
pseusys May 21, 2024
eb07fae
last test step added
pseusys May 24, 2024
97be6b9
attachments migrated to wiki
pseusys May 24, 2024
33a5c73
pragma removed, inheritance added
pseusys May 27, 2024
140f014
some review parts fixed
pseusys May 27, 2024
47610a3
venv ignore added back
pseusys May 27, 2024
0362fc8
some review comments updated
pseusys Jun 3, 2024
07d887e
erview notes taken into account
pseusys Jun 5, 2024
121b092
additional `Message` serialization test introduced
pseusys Jun 5, 2024
5172f0c
extra field verification added
pseusys Jun 7, 2024
27205bb
github action fixes #1
pseusys Jun 7, 2024
0de3e2b
github action fixes N2
pseusys Jun 7, 2024
83cb8a0
github action fixes N3
pseusys Jun 7, 2024
27678f5
misc typing fixed
pseusys Jun 7, 2024
f88e454
Attachment name changed (for windows)
pseusys Jun 7, 2024
85487c3
typing.Annotated fixed
pseusys Jun 7, 2024
e634436
Naming fixed once again
pseusys Jun 7, 2024
5ca6e20
telegram import in tests fixed
pseusys Jun 7, 2024
209d975
telegram import fix (again)
pseusys Jun 7, 2024
2f67816
PathStep quotes added
pseusys Jun 7, 2024
b61c42d
aiofiles dependency fixed
pseusys Jun 8, 2024
cc5772e
typing fixed
pseusys Jun 9, 2024
ae35fb9
naming error fixed
pseusys Jun 10, 2024
a1df33f
ok, we'll just use any I guess
pseusys Jun 10, 2024
d6fbaaf
telegram skip setup correctly
pseusys Jun 10, 2024
4416801
telegram import guarding fixed
pseusys Jun 10, 2024
b4d9942
Docs for new DFF classes and functions
pseusys Jun 18, 2024
4cc00b7
tests fixed and updated
pseusys Jun 19, 2024
d74a2bc
telegram interfaces renamed
pseusys Jun 19, 2024
de12ca2
tutorial documentation introduced
pseusys Jun 19, 2024
eeb1bf7
lockfile updated
pseusys Jun 19, 2024
3f0b86e
Merge branch 'dev' into feat/telegram_interface_upgrade
pseusys Jun 19, 2024
21d5af2
locked
pseusys Jun 19, 2024
eef4498
dummy type annotation added
pseusys Jun 20, 2024
25ed6b2
field doclink fixed
pseusys Jun 20, 2024
3aa7046
lint fixed partly
pseusys Jun 20, 2024
0c12ad2
formatting fixed
pseusys Jun 21, 2024
652453c
Once again string concatenation fixed
pseusys Jun 21, 2024
a50fabe
once again: reformatting
pseusys Jun 21, 2024
e55d801
one whitespace removed
pseusys Jun 21, 2024
23ee7f2
json dump fixed
pseusys Jun 21, 2024
f82d4ed
import error check added
pseusys Jun 21, 2024
c6cd39c
non-native hashes used
pseusys Jun 22, 2024
e95d236
hashing description fixed
pseusys Jun 22, 2024
d02fa87
log level for tmpdir attachment_dir set to info
RLKRo Jun 24, 2024
680d6b6
add abstract class MessengerInterfaceWithAttachments
RLKRo Jun 24, 2024
d8ad2f1
revert init call changes
RLKRo Jun 24, 2024
386f028
return venv ignores
RLKRo Jun 24, 2024
1bd7fff
fix typo
RLKRo Jun 24, 2024
39ca58c
doc improvements
RLKRo Jun 24, 2024
4415606
json-serialization improvements
RLKRo Jun 25, 2024
fc98008
patch TG_BOT_TOKEN for tutorial tests
RLKRo Jun 25, 2024
4f49b99
remove pytest.mark.telegram
RLKRo Jun 25, 2024
1765a33
lint
RLKRo Jun 25, 2024
85e84a4
standardize main block in tutorials
RLKRo Jun 25, 2024
2412ba8
merge utils as development utils
RLKRo Jun 25, 2024
1602242
fix test data
RLKRo Jun 25, 2024
7e1d77c
fix MessengerInterfaceWithAttachments usage in tests
RLKRo Jun 25, 2024
dfbccf7
cached filename check added
pseusys Jun 26, 2024
037a5d3
telegram API connections updated
pseusys Jun 26, 2024
4313477
media group attachment introduced
pseusys Jun 26, 2024
7b894c7
pickle validator parameter removed
pseusys Jun 26, 2024
64fbef0
Type definition sorted
pseusys Jun 26, 2024
2042186
mediagroup tests added
pseusys Jun 27, 2024
d6dfccd
lint fixed
pseusys Jun 27, 2024
b1131ef
message send order updated
pseusys Jun 27, 2024
40c7ad5
Asynchronous interfaces for telegram created
pseusys Jul 1, 2024
a5f18a5
Merge branch 'dev' into feat/telegram_async_interface
pseusys Jul 2, 2024
4fbf39b
one whitespace removed
pseusys Jul 2, 2024
4f1e1fc
lint fixed
pseusys Jul 2, 2024
77fe9eb
happy file updated
pseusys Jul 2, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 26 additions & 1 deletion dff/messengers/telegram/abstract.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
Telegram API.
"""

from abc import abstractmethod, ABC
from asyncio import Future
from pathlib import Path
from typing import Any, Callable, Optional

Expand Down Expand Up @@ -53,7 +55,7 @@
telegram_available = False


class _AbstractTelegramInterface(MessengerInterfaceWithAttachments):
class _AbstractTelegramInterface(MessengerInterfaceWithAttachments, ABC):
"""
Messenger interface mixin for Telegram API usage.
"""
Expand Down Expand Up @@ -656,5 +658,28 @@ async def on_callback(self, update: Update, _: Any) -> None:
update, _, lambda s: Message(attachments=[CallbackQuery(query_string=s.callback_query.data)])
)

@abstractmethod
async def updater_coroutine(self):
raise NotImplementedError

async def connect(self, pipeline_runner: PipelineRunnerFunction, *args, **kwargs):
self._pipeline_runner = pipeline_runner

try:
await self.application.initialize()
if self.application.post_init:
await self.application.post_init(self.application)
await self.updater_coroutine()
await self.application.start()
await Future()

finally:
if self.application.updater.running:
await self.application.updater.stop()
if self.application.running:
await self.application.stop()
if self.application.post_stop:
await self.application.post_stop(self.application)
await self.application.shutdown()
if self.application.post_shutdown:
await self.application.post_shutdown(self.application)
29 changes: 19 additions & 10 deletions dff/messengers/telegram/interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,18 @@
:py:class:`~._AbstractTelegramInterface`.
"""

from asyncio import get_event_loop
from pathlib import Path
from typing import Any, Optional

from dff.pipeline.types import PipelineRunnerFunction

from .abstract import _AbstractTelegramInterface

try:
from telegram import Update
from telegram.error import TelegramError

except ImportError:
Update = Any
TelegramError = Any


class LongpollingInterface(_AbstractTelegramInterface):
Expand All @@ -35,10 +36,15 @@ def __init__(
self.interval = interval
self.timeout = timeout

async def connect(self, pipeline_runner: PipelineRunnerFunction, *args, **kwargs):
await super().connect(pipeline_runner, *args, **kwargs)
self.application.run_polling(
poll_interval=self.interval, timeout=self.timeout, allowed_updates=Update.ALL_TYPES
def error_callback(self, exc: TelegramError) -> None:
get_event_loop().create_task(self.application.process_error(error=exc, update=None))

async def updater_coroutine(self):
await self.application.updater.start_polling(
poll_interval=self.interval,
timeout=self.timeout,
allowed_updates=Update.ALL_TYPES,
error_callback=self.error_callback,
)


Expand All @@ -60,6 +66,9 @@ def __init__(
self.listen = host
self.port = port

async def connect(self, pipeline_runner: PipelineRunnerFunction, *args, **kwargs):
await super().connect(pipeline_runner, *args, **kwargs)
self.application.run_webhook(listen=self.listen, port=self.port, allowed_updates=Update.ALL_TYPES)
async def updater_coroutine(self):
await self.application.updater.start_webhook(
listen=self.listen,
port=self.port,
allowed_updates=Update.ALL_TYPES,
)
4 changes: 2 additions & 2 deletions tests/messengers/telegram/test_happy_paths.json
Original file line number Diff line number Diff line change
Expand Up @@ -510,15 +510,15 @@
"original_message": "gASV+g8AAAAAAACMEHRlbGVncmFtLl91cGRhdGWUjAZVcGRhdGWUk5QpgZR9lCiMD19lZmZlY3Rp\ndmVfY2hhdJSMDnRlbGVncmFtLl9jaGF0lIwEQ2hhdJSTlCmBlH2UKIwKZmlyc3RfbmFtZZSMBFRl\nc3SUjAJpZJRLKowIaXNfZm9ydW2UTowJbGFzdF9uYW1llIwEVXNlcpSMBXRpdGxllE6MBHR5cGWU\njBJ0ZWxlZ3JhbS5jb25zdGFudHOUjAhDaGF0VHlwZZSTlIwHcHJpdmF0ZZSFlFKUjAh1c2VybmFt\nZZSMCXRlc3RfdXNlcpSMB19mcm96ZW6UiIwJX2lkX2F0dHJzlEsqhZSMCmFwaV9rd2FyZ3OUfZR1\nYowSX2VmZmVjdGl2ZV9tZXNzYWdllE6MEV9lZmZlY3RpdmVfc2VuZGVylE6MD19lZmZlY3RpdmVf\ndXNlcpROjBNidXNpbmVzc19jb25uZWN0aW9ulE6MEGJ1c2luZXNzX21lc3NhZ2WUTowOY2FsbGJh\nY2tfcXVlcnmUjBd0ZWxlZ3JhbS5fY2FsbGJhY2txdWVyeZSMDUNhbGxiYWNrUXVlcnmUk5QpgZR9\nlCiMDWNoYXRfaW5zdGFuY2WUjAItMZSMBGRhdGGUjAlmb3JtYXR0ZWSUjAlmcm9tX3VzZXKUjA50\nZWxlZ3JhbS5fdXNlcpRoEJOUKYGUfZQojBhhZGRlZF90b19hdHRhY2htZW50X21lbnWUTowXY2Fu\nX2Nvbm5lY3RfdG9fYnVzaW5lc3OUTowPY2FuX2pvaW5fZ3JvdXBzlE6MG2Nhbl9yZWFkX2FsbF9n\ncm91cF9tZ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ZXKUTowUY2hvc2VuX2lubGluZV9yZXN1bHSUTowZZGVsZXRl\nZF9idXNpbmVzc19tZXNzYWdlc5ROjBdlZGl0ZWRfYnVzaW5lc3NfbWVzc2FnZZROjBNlZGl0ZWRf\nY2hhbm5lbF9wb3N0lE6MDmVkaXRlZF9tZXNzYWdllE6MDGlubGluZV9xdWVyeZROaEJOjBBtZXNz\nYWdlX3JlYWN0aW9ulE6MFm1lc3NhZ2VfcmVhY3Rpb25fY291bnSUTowObXlfY2hhdF9tZW1iZXKU\nTmiXTowLcG9sbF9hbnN3ZXKUTowScHJlX2NoZWNrb3V0X3F1ZXJ5lE6MEnJlbW92ZWRfY2hhdF9i\nb29zdJROjA5zaGlwcGluZ19xdWVyeZROjAl1cGRhdGVfaWSUSwJoG4hoHEsChZRoHn2UdWIu\n"
},
"response_message": {
"text": "\nVisit [this link](https://core.telegram.org/bots/api#formatting-options)\nfor more information about formatting options in telegram\\.\n\nRun /start command again to restart\\.\n",
"text": "\nHere's your formatted text\\!\nYou can see **text in bold**, _text in italic_ and a \\`code snippet\\`\\.\n\\> Here's a [link](https://core.telegram.org/bots/api\\#formatting-options) in a quote\\.\n\\> Visit the link for more information about formatting options in telegram\\.\nRun /start command again to restart\\.\n",
"attachments": null,
"annotations": null,
"misc": null,
"original_message": null,
"parse_mode": "MarkdownV2"
},
"response_functions": [
"send_message(42, '\\nVisit [this link](https://core.telegram.org/bots/api#formatting-options)\\nfor more information about formatting options in telegram\\\\.\\n\\nRun /start command again to restart\\\\.\\n', parse_mode=<ParseMode.MARKDOWN_V2>, disable_notification=None, protect_content=None, reply_markup=None, message_effect_id=None, reply_to_message_id=None, disable_web_page_preview=None)"
"send_message(42, \"\\nHere's your formatted text\\\\!\\nYou can see **text in bold**, _text in italic_ and a \\\\`code snippet\\\\`\\\\.\\n\\\\> Here's a [link](https:\/\/core.telegram.org/bots/api\\\\#formatting-options) in a quote\\\\.\\n\\\\> Visit the link for more information about formatting options in telegram\\\\.\\nRun /start command again to restart\\\\.\\n\", parse_mode=<ParseMode.MARKDOWN_V2>, disable_notification=None, protect_content=None, reply_markup=None, message_effect_id=None, reply_to_message_id=None, disable_web_page_preview=None)"
]
},
{
Expand Down
12 changes: 6 additions & 6 deletions tests/messengers/telegram/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@
from contextlib import contextmanager
from importlib import import_module
from hashlib import sha256
from typing import Any, Dict, Hashable, Iterator, List, Optional, Tuple, Union
from typing import Any, Dict, Hashable, Iterator, List, Optional, Tuple

from dff.pipeline.types import PipelineRunnerFunction
from pydantic import BaseModel
from telegram import InputFile, InputMedia, Update
from typing_extensions import TypeAlias
Expand All @@ -15,7 +16,7 @@
PathStep: TypeAlias = Tuple[Update, Message, Message, List[str]]


def cast_dict_to_happy_step(dictionary: Dict, update_only: bool = False) -> Union[List["PathStep"]]:
def cast_dict_to_happy_step(dictionary: Dict, update_only: bool = False) -> List["PathStep"]:
imports = globals().copy()
imports.update(import_module("telegram").__dict__)
imports.update(import_module("telegram.ext").__dict__)
Expand Down Expand Up @@ -73,6 +74,7 @@ class MockApplication(BaseModel, arbitrary_types_allowed=True):
@classmethod
def create(cls, interface: _AbstractTelegramInterface, happy_path: List[PathStep]) -> "MockApplication":
instance = cls(bot=MockBot(), happy_path=happy_path, interface=interface)
interface.connect = instance.pseudo_connect
return instance

@contextmanager
Expand Down Expand Up @@ -123,8 +125,6 @@ def _run_bot(self) -> None:
else:
raise RuntimeError(f"Update {update} type unknown!")

def run_polling(self, poll_interval: float, timeout: int, allowed_updates: List[str]) -> None:
return self._run_bot()

def run_webhook(self, listen: str, port: str, allowed_updates: List[str]) -> None:
async def pseudo_connect(self, pipeline_runner: PipelineRunnerFunction, *args, **kwargs) -> None:
self.interface._pipeline_runner = pipeline_runner
return self._run_bot()
1 change: 0 additions & 1 deletion tutorials/messengers/telegram/2_attachments.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,6 @@ class and [python-telegram-bot](https://docs.python-telegram-bot.org/)

QUOTED_ATTACHMENTS = [f'"{attachment}"' for attachment in ATTACHMENTS]


# %% [markdown]
"""
The bot below sends different attachments on request.
Expand Down
11 changes: 6 additions & 5 deletions tutorials/messengers/telegram/3_advanced.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,12 +69,13 @@ class for information about different arguments

image_url = HttpUrl(f"{EXAMPLE_ATTACHMENT_SOURCE}/deeppavlov.png")

formatted_text = """
Visit [this link](https://core.telegram.org/bots/api#formatting-options)
for more information about formatting options in telegram\.

formatted_text = r"""
Here's your formatted text\!
You can see **text in bold**, _text in italic_ and a \`code snippet\`\.
\> Here's a [link](https://core.telegram.org/bots/api\#formatting-options) in a quote\.
\> Visit the link for more information about formatting options in telegram\.
Run /start command again to restart\.
""" # noqa: W605
""" # noqa: E501

location_data = {"latitude": 59.9386, "longitude": 30.3141}

Expand Down
Loading