polychatproject / polychat-appservice

A Matrix AppService to connect people via Polychats
https://www.polychat.de
GNU Affero General Public License v3.0
0 stars 1 forks source link

Polychat AppService

The bot written with ExpressJS in TypeScript.

Run

# Use npm to install the dependencies.
# Bun fails to install `matrix-bot-sdk` correctly.
npm install
# Use bun to run this application.
# Its written in TypeScript and there's no transpilation configured for NodeJS.
bun run start

Environment variables

Networks

Debugging and testing

Experimental features

Logging

The project uses the JSON logger pino. It can be configured with a file called $PATH_CONFIG/pino.json.

To learn about its configuration options, see https://getpino.io/#/docs/api?id=options.

Pretty CLI logging

# You may still need to install pino-pretty
npm install --global pino-pretty

# When you run it directly
bun run start | pino-pretty

# When you run it as a Docker container
docker logs polychat-appservice | pino-pretty

Documentation

There are

Sub Rooms

Stages:

  1. created - The Matrix room has been created.
  2. ready - The room is linked to a 3rd-party network and ready to be claimed.
  3. claimed - The room is assigned to a Polychat and a user who has not joined yet. We may not know the third-party identity of the user.
  4. active - The room has been joined by a user and messages are being bridged.

State events

Main room

{
    "type": "de.polychat.room",
    "state_key": "",
    "content": {
        "type": "main"
    }
}
Per attached sub room
{
    "type": "de.polychat.room.participant",
    "state_key": "!abc:localhost",
    "content": {
        "room_id": "!abc:locahost",
        "user_id": "@abc:localhost"
    }
}

Sub Room

{
    "type": "de.polychat.room",
    "state_key": "",
    "content": {
        "type": "sub",
        "network": "telegram",
        "polychat_user_id": "@polychat_000001:polychat.de",
        "timestamp_created": 1708750797214,
    }
}
After it is ready to be claimed
{
    "type": "de.polychat.room",
    "state_key": "",
    "content": {
        "type": "sub",
        "network": "telegram",
        "polychat_user_id": "@bridged_to_telegram_001:polychat.de",
        "timestamp_created": 1708750797214,
        "timestamp_ready": 1708750815712,
        "invite_link": "https://t.me/+O_22QPKlYkswYzAy"
    }
}
After it has been claimed
{
    "type": "de.polychat.room",
    "state_key": "",
    "content": {
        "type": "sub",
        "network": "telegram",
        "polychat_user_id": "@polychat_000001:polychat.de",
        "timestamp_created": 1708750797214,
        "timestamp_ready": 1708750815712,
        "invite_link": "https://t.me/+O_22QPKlYkswYzAy",
        "timestamp_claimed": 1708751064269,
        "user": {
            "identity": "inherit",
            "localpart_in_main_room": "@polychat_000001:polychat.de",
        }
    }
}
After a user has joined
{
    "type": "de.polychat.room",
    "state_key": "",
    "content": {
        "type": "sub",
        "network": "telegram",
        "polychat_user_id": "@polychat_000001:polychat.de",
        "timestamp_created": 1708750797214,
        "timestamp_ready": 1708750815712,
        "invite_link": "https://t.me/+O_22QPKlYkswYzAy",
        "timestamp_claimed": 1708751064269,
        "user": {
            "identity": "inherit",
            "localpart_in_main_room": "@polychat_000001:polychat.de",
        },
        "timestamp_joined": 1708751938226,
        "user_id": "@telegram_01010101:polychat.de"
    }
}
After a user has left
{
    "type": "de.polychat.room",
    "state_key": "",
    "content": {
        "type": "sub",
        "network": "telegram",
        "polychat_user_id": "@polychat_000001:polychat.de",
        "timestamp_created": 1708750797214,
        "timestamp_ready": 1708750815712,
        "invite_link": "https://t.me/+O_22QPKlYkswYzAy",
        "timestamp_claimed": 1708751064269,
        "user": {
            "identity": "inherit",
            "localpart_in_main_room": "@polychat_000001:polychat.de",
        },
        "timestamp_joined": 1708751938226,
        "user_id": "@telegram_01010101:polychat.de",
        "timestamp_left": 1708752077566,
    }
}