Telegram integration error: RuntimeError: Event loop is closed

Hi! I initiated the Rasa 3. I’m trying to connect it to the Telegram bot. I did all the procedures according to the documentation. But after launching (ras run), a message constantly pops up, and the bot does not work.

PS D:\Rasa\test_4> rasa run
C:\Users\Maxim\anaconda3\envs\RASA\lib\site-packages\rasa\core\tracker_store.py:1044: MovedIn20Warning: Deprecated API features detected! These feature(s) are not compatible with SQLAlchemy 2.0. To prevent incompatible upgrades prior to updating applications, ensure requirements files are pinned to "sqlalchemy<2.0". Set environment variable SQLALCHEMY_WARN_20=1 to show all deprecation warnings.  Set environment variable SQLALCHEMY_SILENCE_UBER_WARNING=1 to silence this message. (Background on SQLAlchemy 2.0 at: https://sqlalche.me/e/b8d9)
  Base: DeclarativeMeta = declarative_base()
C:\Users\Maxim\anaconda3\envs\RASA\lib\site-packages\rasa\shared\utils\validation.py:134: DeprecationWarning: pkg_resources is deprecated as an API. See https://setuptools.pypa.io/en/latest/pkg_resources.html
  import pkg_resources
C:\Users\Maxim\anaconda3\envs\RASA\lib\site-packages\pkg_resources\__init__.py:2871: DeprecationWarning: Deprecated call to `pkg_resources.declare_namespace('mpl_toolkits')`.
Implementing implicit namespace packages (as specified in PEP 420) is preferred to `pkg_resources.declare_namespace`. See https://setuptools.pypa.io/en/latest/references/keywords.html#keyword-namespace-packages
  declare_namespace(pkg)
C:\Users\Maxim\anaconda3\envs\RASA\lib\site-packages\pkg_resources\__init__.py:2871: DeprecationWarning: Deprecated call to `pkg_resources.declare_namespace('ruamel')`.
Implementing implicit namespace packages (as specified in PEP 420) is preferred to `pkg_resources.declare_namespace`. See https://setuptools.pypa.io/en/latest/references/keywords.html#keyword-namespace-packages
  declare_namespace(pkg)
C:\Users\Maxim\anaconda3\envs\RASA\lib\site-packages\sanic_cors\extension.py:39: DeprecationWarning: distutils Version classes are deprecated. Use packaging.version instead.
  SANIC_VERSION = LooseVersion(sanic_version)
2024-02-27 22:45:16 INFO     root  - Starting Rasa server on http://0.0.0.0:5005
2024-02-27 22:45:16 INFO     rasa.core.processor  - Loading model models\20240227-222811-dichotomic-electrolysis.tar.gz...
2024-02-27 22:45:40 WARNING  rasa.shared.utils.common  - The UnexpecTED Intent Policy is currently experimental and might change or be removed in the future 🔬 Please share your feedback on it in the forum (https://forum.rasa.com) to help us make this feature ready for production.
2024-02-27 22:45:51 INFO     root  - Rasa server is up and running.
Exception occurred while handling uri: 'http://0164-91-222-218-227.ngrok-free.app/webhooks/telegram/webhook'
Traceback (most recent call last):
  File "handle_request", line 83, in handle_request
    )
  File "C:\Users\Maxim\anaconda3\envs\RASA\lib\site-packages\rasa\core\channels\telegram.py", line 223, in message
    credentials = await out_channel.get_me()
  File "C:\Users\Maxim\anaconda3\envs\RASA\lib\site-packages\aiogram\bot\bot.py", line 215, in get_me
    result = await self.request(api.Methods.GET_ME, payload)
  File "C:\Users\Maxim\anaconda3\envs\RASA\lib\site-packages\aiogram\bot\base.py", line 208, in request
    return await api.make_request(self.session, self.server, self.__token, method, data, files,
  File "C:\Users\Maxim\anaconda3\envs\RASA\lib\site-packages\aiogram\bot\api.py", line 139, in make_request
    async with session.post(url, data=req, **kwargs) as response:
  File "C:\Users\Maxim\anaconda3\envs\RASA\lib\site-packages\aiohttp\client.py", line 1194, in __aenter__
    self._resp = await self._coro
  File "C:\Users\Maxim\anaconda3\envs\RASA\lib\site-packages\aiohttp\client.py", line 476, in _request
    handle = tm.start()
  File "C:\Users\Maxim\anaconda3\envs\RASA\lib\site-packages\aiohttp\helpers.py", line 660, in start
    return self._loop.call_at(when, self.__call__)
  File "C:\Users\Maxim\anaconda3\envs\RASA\lib\asyncio\base_events.py", line 698, in call_at
    self._check_closed()
  File "C:\Users\Maxim\anaconda3\envs\RASA\lib\asyncio\base_events.py", line 508, in _check_closed
    raise RuntimeError('Event loop is closed')
RuntimeError: Event loop is closed
Exception occurred while handling uri: 'http://0164-91-222-218-227.ngrok-free.app/webhooks/telegram/webhook'
Traceback (most recent call last):
  File "handle_request", line 83, in handle_request
    )
  File "C:\Users\Maxim\anaconda3\envs\RASA\lib\site-packages\rasa\core\channels\telegram.py", line 223, in message
    credentials = await out_channel.get_me()
  File "C:\Users\Maxim\anaconda3\envs\RASA\lib\site-packages\aiogram\bot\bot.py", line 215, in get_me
    result = await self.request(api.Methods.GET_ME, payload)
  File "C:\Users\Maxim\anaconda3\envs\RASA\lib\site-packages\aiogram\bot\base.py", line 208, in request
    return await api.make_request(self.session, self.server, self.__token, method, data, files,
  File "C:\Users\Maxim\anaconda3\envs\RASA\lib\site-packages\aiogram\bot\api.py", line 139, in make_request
    async with session.post(url, data=req, **kwargs) as response:
  File "C:\Users\Maxim\anaconda3\envs\RASA\lib\site-packages\aiohttp\client.py", line 1194, in __aenter__
    self._resp = await self._coro
  File "C:\Users\Maxim\anaconda3\envs\RASA\lib\site-packages\aiohttp\client.py", line 476, in _request
    handle = tm.start()
  File "C:\Users\Maxim\anaconda3\envs\RASA\lib\site-packages\aiohttp\helpers.py", line 660, in start
    return self._loop.call_at(when, self.__call__)
  File "C:\Users\Maxim\anaconda3\envs\RASA\lib\asyncio\base_events.py", line 698, in call_at
    self._check_closed()
  File "C:\Users\Maxim\anaconda3\envs\RASA\lib\asyncio\base_events.py", line 508, in _check_closed
    raise RuntimeError('Event loop is closed')
RuntimeError: Event loop is closed

below is the content of the file credentiala.yml

telegram:
  access_token: "7060144411:AAGJ6NxtNWS0qKDT6jmsQRyoAwh8K9RAps0"
  verify: "Rasa_Test_001_Bot"
  webhook_url: "https://0164-91-222-218-227.ngrok-free.app/webhooks/telegram/webhook"

rasa:
  url: "http://localhost:5002/api"
1 Like

Did you get the solution? I am getting the same error.

1 Like

Do you get it solved! Im facing the same error while trying to connect. Ngrok shows that it successfully connected to: Localhost:5005, so the problem sounds like Rasa’s side!

You still have it?

I guess it was library versions incompatibility or something. I used Rasa 3.4 and now it works. And also need to run core-server in CORS enabled mode like rasa run --enable-api --cors "*" --debug.

1 Like

it did work for me too, thank you for replying :raised_hands:

1 Like

Hi! I’m facing same issue but rasa run --enable-api --cors "*" --debug did not worked for me :frowning: Any more actions required?

1 Like

Problem solved : installed python 3.8.10 and Rasa 3.6.6

2 Likes

@Dzordz still getting same error trying since 2 days

I’m getting the same error as well for the past 2 days.

I’m using the version below:

Rasa Version : 3.6.19 Minimum Compatible Version: 3.5.0 Rasa SDK Version : 3.6.2 Python Version : 3.9.6

I tried every possible solution which is available on web runing it on cors and doubled checked every YouTube tutorial and rasa documentation still getting this error …

I’m guessing the telegram has not been updated with the latest API.

I’ve tested it with Google Chat and it’s working out of the box just by following the instructions in the doc.

yeah may be , i hope rasa team will fix the issue, if you find any fix let me know

Did you manage to get it working?

The issue for me is the same as the Jira Issue.

I fixed by updating aiogram to a newer version with:

pip install -U aiogram==2.25.2

2 Likes

Yes… yes … yes… that work… THANKS!!!

2 Likes

Had the same issue. Tried different versions of Python (3.10 and 3.8) and rasa (3.22 and 3.6) as well as other methods do fix.

Default aiogram version was really outdates. Changing it to 2.25.2 fixed the issue.

Cheers!