!JiiOHXrIUCtcOJsZCa:matrix.org

nio

357 Members
The nio matrix python library | Latest release 0.4 https://pypi.org/project/matrix-nio/ | Documentation: https://matrix-nio.readthedocs.io/en/stable/137 Servers

Load older messages


SenderMessageTime
15 Feb 2025
@dom:matrix.domnomnom.comDomNomNom heya, I'm trying to get a nio python client to listen to an e2ee room. While it receives messages in unexcrypted rooms fine as well as messages sent from the same account in that channel, messages from others give me this error:
Received a undecryptable Megolm event from a device with no Olm sessions: @dom:matrix.domnomnom.com RZMVOBKBTU
Error decrypting megolm event, no session found with session id Z/YrictfuJ/8ro4A53ZPnGzRQvqxtVqX9uy8TNwkPxI for room !sZpfYzLsRbnIOKJlPH:matrix.domnomnom.com
Any hints on what to do to address this?
09:34:24
@d3v1l-h4cker:4d2.org[}3√1[_I have recently asked here about encryption, they didn't answer anything09:37:06
@d3v1l-h4cker:4d2.org[}3√1[_Show your code09:37:16
@dom:matrix.domnomnom.comDomNomNom
In reply to@d3v1l-h4cker:4d2.org
Show your code
https://git.domnomnom.com/dom/getbot/src/branch/main/getbot/main.py
09:48:23
@d3v1l-h4cker:4d2.org[}3√1[_

This code decrypts encrypted messages

import asyncio
from nio import AsyncClient, AsyncClientConfig, MatrixRoom, RoomMessageText, MegolmEvent, EncryptionError, OlmUnverifiedDeviceError
import os

store_path = "../configs/store/"

class Bot:
    def __init__(self, homeserver, user_id, password, room_id, store_path="store/"):
        self.password = password
        self.room_id = room_id

        os.makedirs(store_path, exist_ok=True)
        config = AsyncClientConfig(encryption_enabled=True)
        self.client = AsyncClient(homeserver, user_id, config=config, store_path=store_path)

    async def start(self):
        await self.client.login(password=self.password)
        self.client.add_event_callback(self.message_callback, (RoomMessageText, MegolmEvent))
        await self.client.sync_forever(timeout=30000)

    async def message_callback(self, room: MatrixRoom, event):
        if event.sender == self.client.user_id:
            return

        if isinstance(event, MegolmEvent):
            try:
                event = self.client.decrypt_event(event)
            except EncryptionError:
                await self.send_notice("Ошибка шифрования. Пожалуйста, попробуйте позже.")
                return

        if isinstance(event, RoomMessageText):
            if room.room_id != self.room_id:
                return

            message = event.body.strip()

            if message.lower() == "!ping":
                help_message = (
                    "pong!"
                )
                await self.send_message(help_message)

    async def send_message(self, message):
        try:
            await self.client.room_send(
                room_id=self.room_id,
                message_type="m.room.message",
                content={
                    "msgtype": "m.text",
                    "body": message
                },
                ignore_unverified_devices=True
            )
        except OlmUnverifiedDeviceError as e:
            pass

    async def send_notice(self, message):
        try:
            await self.client.room_send(
                room_id=self.room_id,
                message_type="m.notice",
                content={
                    "msgtype": "m.notice",
                    "body": message
                },
                ignore_unverified_devices=True
            )
        except OlmUnverifiedDeviceError as e:
            pass

async def main():
    bot = Bot(homeserver="https://matrix.org", user_id="@:matrix.org",
                       password="pass",
                       room_id="!:4d2.org", store_path=store_path)
    await bot.start()

if __name__ == "__main__":
    asyncio.run(main())
11:22:44
@d3v1l-h4cker:4d2.org[}3√1[_ *

This code decrypts encrypted messages

import asyncio
from nio import AsyncClient, AsyncClientConfig, MatrixRoom, RoomMessageText, MegolmEvent, EncryptionError, OlmUnverifiedDeviceError
import os

store_path = "../configs/store/"

class Bot:
    def __init__(self, homeserver, user_id, password, room_id, store_path="store/"):
        self.password = password
        self.room_id = room_id

        os.makedirs(store_path, exist_ok=True)
        config = AsyncClientConfig(encryption_enabled=True)
        self.client = AsyncClient(homeserver, user_id, config=config, store_path=store_path)

    async def start(self):
        await self.client.login(password=self.password)
        self.client.add_event_callback(self.message_callback, (RoomMessageText, MegolmEvent))
        await self.client.sync_forever(timeout=30000)

    async def message_callback(self, room: MatrixRoom, event):
        if event.sender == self.client.user_id:
            return

        if isinstance(event, MegolmEvent):
            try:
                event = self.client.decrypt_event(event)
            except EncryptionError:
                await self.send_notice("Ошибка шифрования. Пожалуйста, попробуйте позже.")
                return

        if isinstance(event, RoomMessageText):
            if room.room_id != self.room_id:
                return

            message = event.body.strip()

            if message.lower() == "!ping":
                help_message = (
                    "pong!"
                )
                await self.send_message(help_message)

    async def send_message(self, message):
        try:
            await self.client.room_send(
                room_id=self.room_id,
                message_type="m.room.message",
                content={
                    "msgtype": "m.text",
                    "body": message
                },
                ignore_unverified_devices=True
            )
        except OlmUnverifiedDeviceError as e:
            pass

    async def send_notice(self, message):
        try:
            await self.client.room_send(
                room_id=self.room_id,
                message_type="m.notice",
                content={
                    "msgtype": "m.notice",
                    "body": message
                },
                ignore_unverified_devices=True
            )
        except OlmUnverifiedDeviceError as e:
            pass

async def main():
    bot = Bot(homeserver="https://matrix.org", user_id="@:matrix.org",
                       password="pass",
                       room_id="!:4d2.org", store_path=store_path)
    await bot.start()

if __name__ == "__main__":
    asyncio.run(main())
11:22:50
@d3v1l-h4cker:4d2.org[}3√1[_ DomNomNom 11:26:09
16 Feb 2025
@nicocool:matrix.orgnicocool Hey all! I am trying to implement key verification for my client, I followed https://matrix-nio.readthedocs.io/en/latest/examples.html#interactive-encryption-key-verification 15:52:35
@nicocool:matrix.orgnicocool However, I don't receive any event when I initiate the session verification from element. I only receive something a KeyVerificationCancel when I cancel the process from element. What am I doing wrong? 15:54:00
@nicocool:matrix.orgnicocool* However, I don't receive any event when I initiate the session verification from element. I only receive a `KeyVerificationCancel` when I cancel the process from element. What am I doing wrong?15:54:09
@nicocool:matrix.orgnicocool Oh I guess all key verification stuff is broken, cf https://github.com/matrix-nio/matrix-nio/issues/430 16:12:54
@dom:matrix.domnomnom.comDomNomNom@nico19:31:02
@dom:matrix.domnomnom.comDomNomNom @nicocool here's a patch to the example, which allows you to verify: https://github.com/wreald/matrix-nio/commit/5cb8e99965bcb622101b1d6ad6fa86f5a9debb9a 19:31:26
17 Feb 2025
@nicocool:matrix.orgnicocoolOh, thanks a lot!05:20:55
@nicocool:matrix.orgnicocool The docs link in the room topic is broken, it should be /latest/ instead of /stable/ 13:13:32
@nicocool:matrix.orgnicocool Are we supposed to receive an event we can hook to when we leave a room from another client? 16:49:24
@nicocool:matrix.orgnicocool DomNomNom, I basically copy pasted your contrib in https://codeberg.org/slidge/matridge/commit/f3f6cf7d21c5b514333aef4a94a053ccab8caa2e I hope that's OK 16:50:39
19 Feb 2025
@ff777:nerdsin.spaceFF777 joined the room.17:14:19
20 Feb 2025
@schuub:matrix.orgschuub joined the room.01:02:29
@me:shahpaarth.comPaarth Shah - Github Maintainer changed the room topic to "The nio matrix python library | Latest stable release 0.25.2 | https://pypi.org/project/matrix-nio/ | Documentation: https://matrix-nio.readthedocs.io/en/latest/" from "The nio matrix python library | Latest stable release 0.25.2 | https://pypi.org/project/matrix-nio/ | Documentation: https://matrix-nio.readthedocs.io/en/stable/".06:20:15
@me:shahpaarth.comPaarth Shah - Github MaintainerGoot catch ty06:20:23
@me:shahpaarth.comPaarth Shah - Github Maintainer* Good catch ty06:20:29
@tom:lant.uktom changed their display name from tom to tom [back 2025-02-24].10:23:51
22 Feb 2025
@pbsntby:matrix.org@pbsntby:matrix.org joined the room.17:13:46
@pbsntby:matrix.org@pbsntby:matrix.org left the room.18:07:14
23 Feb 2025
@jazzpar:matrix.org@jazzpar:matrix.org joined the room.07:17:30
@jazzpar:matrix.org@jazzpar:matrix.org left the room.07:18:50
@exaltia:chat.exaltia.frExaltia joined the room.11:51:43
@exaltia:chat.exaltia.frExaltia

Hello. made my very first step in using matrix-nio this week end.
I may need a push in the right direction.
I have nested spaces with a room at the end

SpaceA 
    SpaceB 
        Room1

i want to display spaces and room in the right order
I'm using space_get_hierarchy for each room my account see, to get room and spaces, but they are sent to my client in this order : SpaceB[has child room Room1], SpaceA[Has child space SpaceB]

Do i use the right function to try to get space and rooms in order to display them?

12:05:15
@exaltia:chat.exaltia.frExaltiai think i finally managed it14:20:04

Show newer messages


Back to Room ListRoom Version: 4