Giter VIP home page Giter VIP logo

python-appservice-framework's Introduction

Matrix Appservice Framework

The objective of this package is to provide a framework for writing bridging appservices for matrix. These bridges can be double puppet or single puppet or a combination of both.

The objective of this framework is that the framework handles maintaining state and the matrix operations and provides an easy to use API to developers to implement the service specific components.

Implementation

This framework is written using the asyncio module and the co-routine syntax which was introduced in Python 3.5. It uses aiohttp for making HTTP requests and for the web server component. It uses SQLAlchemy to have a database of users and rooms that the bridge is configured for.

Planning

UX Flow

Double Puppet bridge

  1. Auth with bot
  2. Ask for invite to room

Single Puppet bridge

Assume everything is public (like IRC bridge but unknown rooms on service side):

Telegram Bot or Discord Bot

  1. Invite bot user to service room
  2. Link to matrix room posted in service room.
  3. Join matrix room.

Keeping rooms invite only on matrix side.

  1. Invite bot to matrix room
  2. Invite bot to service room
  3. Some token printed in the service room
  4. Issue command in the matrix room with the token.

Dual Mode - Double and Single Puppet

  1. Auth with bot
  2. Ask for invite to room
  3. Auth'ed user gets admin in room
  4. Non-authed matrix users are puppeted by service bot user.

python-appservice-framework's People

Contributors

cadair avatar martijnbraam avatar turboss avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

python-appservice-framework's Issues

adding true double puppet functionality

Currently the framework does not support puppeting the matrix user, that is being bridged.

That means that using the framework also involves keeping track of an additonal matrix client/api in order to puppet this user as well. It also requires own code to decide in which way an event is supposed to be handled - either relaying the message via the framework (relay_service_message) or relaying it as the real user (again, having to write own code for submitting messages and room events via the matrix api since the framework cannot masquerade a user not in the user-namespace).

Do you have any plans or ideas regarding this already ?

aiohttp throws "RuntimeError: Timeout context manager should be used inside a task" on linked room creation

Traceback (most recent call last):
  File "/usr/local/lib/python3.6/site-packages/matrix_discord_bridge-0.0.1.dev0-py3.6.egg/appservice/app.py", line 179, in on_message
    return await self.handle_discord_message(message)
  File "/usr/local/lib/python3.6/site-packages/matrix_discord_bridge-0.0.1.dev0-py3.6.egg/appservice/app.py", line 109, in handle_discord_message
    room = await self.create_new_room(auth_user, service_roomid)
  File "/usr/local/lib/python3.6/site-packages/matrix_discord_bridge-0.0.1.dev0-py3.6.egg/appservice/app.py", line 154, in create_new_room
    room = await self.apps.create_linked_room(auth_user, service_roomid, matrix_roomname=channel_name)
  File "/usr/local/lib/python3.6/site-packages/appservice_framework-0.1.0-py3.6.egg/appservice_framework/appservice.py", line 879, in create_linked_room
    query_params={'auth_token': self.api.token})
  File "/usr/local/lib/python3.6/site-packages/appservice_framework-0.1.0-py3.6.egg/appservice_framework/matrix_api.py", line 74, in _send
    async with request as response:
  File "/usr/local/lib/python3.6/site-packages/aiohttp-3.3.2-py3.6.egg/aiohttp/client.py", line 843, in __aenter__
    self._resp = await self._coro
  File "/usr/local/lib/python3.6/site-packages/aiohttp-3.3.2-py3.6.egg/aiohttp/client.py", line 317, in _request
    with timer:
  File "/usr/local/lib/python3.6/site-packages/aiohttp-3.3.2-py3.6.egg/aiohttp/helpers.py", line 662, in __enter__
    raise RuntimeError('Timeout context manager should be used '
RuntimeError: Timeout context manager should be used inside a task

The AppService get initialised in a similar fashion to the way it is done in the hangoutsas:

    def run(self):
        self.apps = AppService(
            matrix_server=self.args[CPNs.MX_HS],
            server_domain=self.args[CPNs.MX_HS_DOMAIN],
            access_token=self.args[CPNs.MX_AS_TOKEN],
            user_namespace=self.args[CPNs.AS_USER_NS],
            sender_localpart=self.args[CPNs.AS_SENDER_LOCAL],
            room_namespace=self.args[CPNs.AS_ROOM_NS],
            database_url=self.args[CPNs.DB_URI],
            loop=self.loop, # in class __init__: self.loop = loop or asyncio.get_event_loop()
            invite_only_rooms=self.args[CPNs.AS_INVITE_ONLY_ROOMS]
        )

        # service_connect handler and user creation snipped 

        with self.apps.run() as run_forever:
            run_forever()

Any idea why this is happening ? Any idea on how to troubleshoot it or information you would need to fix/give help ?

adding relay_service_file

Currently the framework supports relaying images (w/ m.image message type). What about m.file ?

When implementing relay_service_file, should it be and additonal method (similar code structure to relay_service_image) or should the relay_service_image method be renamed to relay_service_file with added support for custom message type (file, image) and maybe custom content_pack/info parameters ?

Support bot style bridges

We should support the ability to have one service user and have the AS invited into rooms, i.e. telegram / gitter bridges

Reuse existing rooms with AS alias for prevent M_FORBIDDEN events

For post new messages to AS-managed rooms, AS user must be a member (maybe with admin permissions?) of all rooms.

But sometimes it can not be a member of room:

  • If this room was already exists before AS is added to server (eq if user use other AS with same sender_localpart and replace it to new AS).
  • If user kick manually this user from room.

In this situations now AS shows the error:

matrix_client.errors.MatrixRequestError: 403: {"errcode":"M_FORBIDDEN","error":"User @hangouts:homeserver.org not in room !uJsAiCcPjyKuXTJHTo:homeserver.org (None)"}

And when user try to manually invite @hangouts user to room - we got another error:

appservice_framework ERROR    Membership event received, handling is not yet implemented.

For solve this problems, we must implement managing membership events (for accept manual invites of AS user to rooms), and force joining AS user to managed rooms, if it missed in room member list.

Add a table to the database for events

Along the lines of telematrix we should store a mapping of events on the service and matrix side, this would allow for relates_to linking and also things like read marker / timestamp syncing.

Update rooms and members on startup

On startup of we should iterate over all the rooms in the database and query their state, things like names, members, if the rooms still exists etc.

This will probably need some extra service side hooks.

Add a bunch of (yaml) config helpers

Should support a way to define all the __init__ parameters of the Appservice class as well as providing easy ways for users to specify custom config for the service they are using.

Writing a protocol other than irc

Hello:

I'm willing to write a appservice for a game server lobby (SpringRTS)
I would like to help develop this project as I ee it has a lot of potential
but I'm pretty lost :D is there a room where we can talk?

Thanks

edit: what I need is a transparent bridging from matrix to springrts ( not behind a bot (I already have this))

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.