Skip to content

netresearch/matrix-skill / skills/matrix-communication

matrix-communication

Flagged

Use when communicating via Matrix chat, notifying teams, or managing E2EE. Triggers on #room:server references, Matrix URLs, and chat requests.

FileKindSize
README.mdmarkdown2.9 KB
SKILL.mdskill md6.7 KB
evals/evals.jsonconfig12.6 KB
references/agent-governance.mdmarkdown2.0 KB
references/api-reference.mdmarkdown7.3 KB
references/command-reference.mdmarkdown8.9 KB
references/e2ee-guide.mdmarkdown17.2 KB
references/hookshot-integration.mdmarkdown10.7 KB
references/messaging-guide.mdmarkdown13.8 KB
references/no-editorializing.mdmarkdown331 B
references/setup-guide.mdmarkdown11.1 KB
references/troubleshooting.mdmarkdown7.8 KB
scripts/_lib/__init__.pyscript3.6 KB
scripts/_lib/backup_mac.pyscript1.2 KB
scripts/_lib/config.pyscript4.6 KB
scripts/_lib/daemon_client.pyscript3.0 KB
scripts/_lib/deps.pyscript1.9 KB
scripts/_lib/downloads.pyscript1.1 KB
scripts/_lib/e2ee.pyscript13.2 KB
scripts/_lib/formatting.pyscript14.4 KB
scripts/_lib/http.pyscript4.8 KB
scripts/_lib/reactions.pyscript2.9 KB
scripts/_lib/roomlog.pyscript13.7 KB
scripts/_lib/rooms.pyscript15.5 KB
scripts/_lib/secret_input.pyscript2.0 KB
scripts/_lib/test_backup_mac.pyscript1.5 KB
scripts/_lib/test_config.pyscript7.1 KB
scripts/_lib/test_daemon_client.pyscript5.9 KB
scripts/_lib/test_downloads.pyscript2.3 KB
scripts/_lib/test_e2ee.pyscript14.3 KB
scripts/_lib/test_formatting.pyscript15.5 KB
scripts/_lib/test_http.pyscript4.1 KB
scripts/_lib/test_reactions.pyscript15.2 KB
scripts/_lib/test_roomlog.pyscript20.2 KB
scripts/_lib/test_rooms.pyscript13.7 KB
scripts/_lib/test_secret_input.pyscript2.2 KB
scripts/_lib/test_trust.pyscript8.3 KB
scripts/_lib/trust.pyscript5.3 KB
scripts/_lib/utils.pyscript1.7 KB
scripts/matrix-create-room.pyexecutablescript4.7 KB
scripts/matrix-doctor.pyexecutablescript22.2 KB
scripts/matrix-download-e2ee.pyexecutablescript7.7 KB
scripts/matrix-e2ee-setup.pyexecutablescript9.2 KB
scripts/matrix-e2ee-verify.pyexecutablescript29.2 KB
scripts/matrix-edit-e2ee.pyexecutablescript7.9 KB
scripts/matrix-edit.pyexecutablescript5.3 KB
scripts/matrix-fetch-keys.pyexecutablescript9.1 KB
scripts/matrix-invite.pyexecutablescript3.0 KB
scripts/matrix-key-backup.pyexecutablescript21.3 KB
scripts/matrix-power-level.pyexecutablescript7.0 KB
scripts/matrix-react.pyexecutablescript14.1 KB
scripts/matrix-read-e2ee.pyexecutablescript12.8 KB
scripts/matrix-read.pyexecutablescript4.7 KB
scripts/matrix-redact.pyexecutablescript5.0 KB
scripts/matrix-resolve.pyexecutablescript1.7 KB
scripts/matrix-rooms.pyexecutablescript3.8 KB
scripts/matrix-send-e2ee.pyexecutablescript19.4 KB
scripts/matrix-send.pyexecutablescript9.4 KB
scripts/matrix-watch.pyexecutablescript5.3 KB
scripts/matrix-watchd.pyexecutablescript23.5 KB
scripts/test_matrix_doctor.pyscript14.2 KB
scripts/test_matrix_read_e2ee.pyscript2.7 KB

scripts/matrix-edit-e2ee.py

View on GitHub
#!/usr/bin/env -S uv run --script
# SPDX-License-Identifier: MIT
# SPDX-FileCopyrightText: Netresearch DTT GmbH
# /// script
# requires-python = ">=3.11"
# dependencies = ["matrix-nio[e2e]<0.26"]
# ///
"""Edit an existing message in an E2EE Matrix room.

Usage:
    matrix-edit-e2ee.py ROOM EVENT_ID NEW_MESSAGE
    matrix-edit-e2ee.py --help

Arguments:
    ROOM        Room alias (#room:server), room ID (!id:server), or room name
    EVENT_ID    Event ID of the message to edit ($xxx:server)
    NEW_MESSAGE The new message content (replaces original)

Options:
    --no-prefix Don't add bot_prefix from config
    --json      Output as JSON
    --quiet     Minimal output
    --debug     Show debug information
    --help      Show this help
"""

import asyncio
import json
import os
import sys

# Add script directory to path for _lib imports
sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))

from _lib import (
    UntrustedDevicesError,
    add_bot_prefix,
    check_e2ee_dependencies,
    clean_message,
    daemon_request,
    find_room_in_nio_client,
    get_store_path,
    load_config,
    load_credentials,
    markdown_to_html,
    normalize_room_input,
    prefer_ipv4,
    restore_login_checked,
    send_checked,
    suppress_nio_logging,
)

# Check dependencies before importing nio
check_e2ee_dependencies()

from nio import (
    AsyncClient,
    AsyncClientConfig,
    RoomResolveAliasResponse,
    RoomSendResponse,
)

sys.stdout.reconfigure(line_buffering=True)
sys.stderr.reconfigure(line_buffering=True)


async def edit_message_e2ee(
    config: dict,
    room: str,
    event_id: str,
    message: str,
    debug: bool = False,
    trust_unverified_devices: bool = False,
) -> dict:
    # A running daemon holds the store; opening it here would be the second
    # opener. Before this branch existed, edits went direct and produced events
    # the daemon could not decrypt - holes in its own log. See #95.
    response = daemon_request(
        {
            "op": "edit",
            "room": room,
            "event_id": event_id,
            "body": message,
            "trust_unverified_devices": trust_unverified_devices,
        }
    )
    if response is not None:
        if response.get("ok"):
            return {"event_id": response["event_id"], "room_id": room}
        return {"error": response.get("error", "daemon refused the edit")}

    store_path = get_store_path()
    stored_creds = load_credentials()

    if stored_creds and stored_creds.get("user_id") == config["user_id"]:
        device_id = stored_creds["device_id"]
        access_token = stored_creds["access_token"]
        if debug:
            print(f"Using dedicated device: {device_id}", file=sys.stderr)
    elif "access_token" in config:
        access_token = config["access_token"]
        from nio import WhoamiResponse

        temp_client = AsyncClient(config["homeserver"], config["user_id"])
        temp_client.access_token = access_token
        whoami = await temp_client.whoami()
        await temp_client.close()
        if isinstance(whoami, WhoamiResponse):
            device_id = whoami.device_id
        else:
            return {"error": f"Failed to get device info: {whoami}"}
    else:
        return {"error": "No credentials found. Run matrix-e2ee-setup.py first"}

    client_config = AsyncClientConfig(store_sync_tokens=True, encryption_enabled=True)
    client = AsyncClient(
        homeserver=config["homeserver"],
        user=config["user_id"],
        device_id=device_id,
        store_path=str(store_path),
        config=client_config,
    )

    try:
        restore_login_checked(client, config["user_id"], device_id, access_token)
        if client.store:
            client.load_store()
        if client.should_upload_keys:
            await client.keys_upload()

        # Sync first, then resolve room from client.rooms
        await client.sync(timeout=0, full_state=True)

        room_id = room
        if room.startswith("#"):
            response = await client.room_resolve_alias(room)
            if isinstance(response, RoomResolveAliasResponse):
                room_id = response.room_id
            else:
                return {"error": f"Could not resolve room alias: {response}"}
        elif not room.startswith("!"):
            found = find_room_in_nio_client(client.rooms, room)
            if found:
                room_id = found
            else:
                return {
                    "error": f"Could not find room '{room}'. Use 'matrix-rooms.py' to list rooms."
                }

        room_obj = client.rooms.get(room_id)
        if room_obj and room_obj.encrypted and client.olm and client.should_query_keys:
            await client.keys_query()

        # Build edit content
        content = {
            "msgtype": "m.text",
            "body": f"* {message}",
            "m.new_content": {"msgtype": "m.text", "body": message},
            "m.relates_to": {"rel_type": "m.replace", "event_id": event_id},
        }
        html = markdown_to_html(message)
        if html != message:
            content["format"] = "org.matrix.custom.html"
            content["formatted_body"] = f"* {html}"
            content["m.new_content"]["format"] = "org.matrix.custom.html"
            content["m.new_content"]["formatted_body"] = html

        members = list(room_obj.users) if room_obj and room_obj.encrypted else []
        try:
            response = await send_checked(
                client,
                room_id,
                members,
                "m.room.message",
                content,
                trust_unverified=trust_unverified_devices,
            )
        except UntrustedDevicesError as exc:
            return {"error": str(exc)}

        if isinstance(response, RoomSendResponse):
            return {"event_id": response.event_id, "room_id": room_id}
        return {"error": str(response)}
    finally:
        await client.close()


def main():
    import argparse

    parser = argparse.ArgumentParser(
        description="Edit a message in an E2EE Matrix room"
    )
    parser.add_argument(
        "room", help="Room alias (#room:server), room ID (!id:server), or room name"
    )
    parser.add_argument("event_id", help="Event ID to edit")
    parser.add_argument("message", help="New message content")
    parser.add_argument("--no-prefix", action="store_true", help="Don't add bot_prefix")
    parser.add_argument(
        "--trust-unverified-devices",
        action="store_true",
        help="Share this edit's room key with devices that are not verified. "
        "By default the message is not sent while the room has such devices.",
    )
    parser.add_argument("--json", action="store_true", help="Output as JSON")
    parser.add_argument("--quiet", "-q", action="store_true", help="Minimal output")
    parser.add_argument("--debug", action="store_true", help="Show debug info")
    args = parser.parse_args()

    prefer_ipv4()
    if not args.debug:
        suppress_nio_logging()

    config = load_config(require_user_id=True)
    message = clean_message(args.message)
    room_input = normalize_room_input(clean_message(args.room))

    if not args.no_prefix and config.get("bot_prefix"):
        message = add_bot_prefix(message, config["bot_prefix"])

    # Room name resolution happens post-sync inside the async function
    room = room_input

    result = asyncio.run(
        edit_message_e2ee(
            config,
            room,
            args.event_id,
            message,
            args.debug,
            trust_unverified_devices=args.trust_unverified_devices,
        )
    )

    if "error" in result:
        if args.json:
            print(json.dumps(result))
        else:
            print(f"Error: {result['error']}", file=sys.stderr)
        sys.exit(1)

    if args.json:
        print(json.dumps(result))
    elif args.quiet:
        print(result.get("event_id", ""))
    else:
        print(f"Message edited in {args.room}")
        print(f"Edit event ID: {result.get('event_id')}")


if __name__ == "__main__":
    main()
slack-gif-creatoranthropics/skillsKnowledge and utilities for creating animated GIFs optimized for Slack. Provides constraints, validation tools, and animation concepts. Use when users request animated GIFs for Slack like "make me a GIF of X doing Y for Slack."Stars: 197kUpdated Claude CodeCodexVerifiedInstall
ponytailDietrichGebert/ponytailLazy senior dev mode for any coding task: the smallest change that fully solves it, and a reply a busy human understands in one read.Stars: 194kUpdated Claude CodeCodexVerifiedInstall
ponytail-debtDietrichGebert/ponytailHarvest every shortcut: comment into one debt ledger, so deferrals get tracked instead of forgotten. One-shot report.Stars: 194kUpdated Claude CodeCodexVerifiedInstall
ponytail-debtDietrichGebert/ponytailList every `shortcut:` comment (and older `ponytail:` ones) as a debt ledger. One-shot report, changes nothing. Use for "ponytail debt", "what did ponytail defer", "list the shortcuts", /ponytail-debt.Stars: 194kUpdated Claude CodeCodexVerifiedInstall