{"id":21171162,"url":"https://github.com/fuchs-fabian/matrix-notify-py-template","last_synced_at":"2025-03-14T17:25:27.322Z","repository":{"id":225350863,"uuid":"765738716","full_name":"fuchs-fabian/matrix-notify-py-template","owner":"fuchs-fabian","description":"Simple Python template for sending HTML messages to a Matrix room, optionally with E2E.","archived":false,"fork":false,"pushed_at":"2024-09-14T21:18:47.000Z","size":42,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-01-21T10:51:07.508Z","etag":null,"topics":["automation","element-io","matrix-org","notifier","scripting","template-repository"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/fuchs-fabian.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-03-01T14:19:57.000Z","updated_at":"2024-10-20T16:46:39.000Z","dependencies_parsed_at":"2024-03-03T20:28:01.686Z","dependency_job_id":"c41003e3-fd39-4221-aa07-9cc99929b78c","html_url":"https://github.com/fuchs-fabian/matrix-notify-py-template","commit_stats":null,"previous_names":["fuchs-fabian/matrix-notify-py","fuchs-fabian/matrix-notify-py-template"],"tags_count":0,"template":true,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fuchs-fabian%2Fmatrix-notify-py-template","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fuchs-fabian%2Fmatrix-notify-py-template/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fuchs-fabian%2Fmatrix-notify-py-template/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fuchs-fabian%2Fmatrix-notify-py-template/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/fuchs-fabian","download_url":"https://codeload.github.com/fuchs-fabian/matrix-notify-py-template/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243617059,"owners_count":20320001,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["automation","element-io","matrix-org","notifier","scripting","template-repository"],"created_at":"2024-11-20T16:03:12.506Z","updated_at":"2025-03-14T17:25:27.298Z","avatar_url":"https://github.com/fuchs-fabian.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# matrix-notify-py-template\n\nSimple Python template for sending HTML messages to a [Matrix](https://matrix.org/) room, optionally with E2E.\n\nIt took some time to find a good solution for sending encrypted messages to Matrix in a simple and uncomplicated way. I have therefore endeavoured to document everything as well as possible.\n\nIf you have any suggestions for improvement or ideas, I would be very grateful if you would simply create an issue or open a PR with your proposed solution.\n\nYou are welcome to use this template and adapt it to your needs.\n\nTo get it:\n\n```bash\nwget https://raw.githubusercontent.com/fuchs-fabian/matrix-notify-py-template/main/matrix.py\n```\n\nMake the script executable if required:\n\n```bash\nchmod +x ./matrix.py\n```\n\n## Preparations\n\n\u003e Create a special (bot) user / account! Don't use your main account!\n\nInstalling required packages:\n\n```bash\npip install requests matrix-commander\n```\n\n## Without E2E\n\n```python\nUSE_E2E = False\n```\n\nSending **unencrypted** messages to an **encrypted**/**unencrypted** room.\n\n![Example without E2E](/images/example_without_e2e.png)\n\n### Requirements\n\n|                | example / additional information                                                                                                                                                                                          |\n| -------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |\n| homeserver url | E.g. for a standard Matrix user `https://matrix-client.matrix.org` (available in _account_ settings)                                                                                                                      |\n| access token   | To get it in [Element](https://element.io/), log in as the created user, tap on the profile picture on the top left, and go to `All settings` → `Help \u0026 About`. There should be a dropdown menu on the bottom (`Access Token`) |\n| room id        | **You have to join** with this special account to **this room** before! (available in _room_ settings)                                                                                                                    |\n\n### Usage\n\nThe following must be adjusted in the code:\n\n```python\nMATRIX_ACCESS_TOKEN = \"\"\nMATRIX_ROOM_ID = \"\"\n```\n\nIf necessary also:\n\n```python\nMATRIX_HOMESERVER_URL = \"https://matrix-client.matrix.org\"\n```\n\n## With E2E\n\n```python\nUSE_E2E = True\n```\n\nSending **encryptet** messages to an **encrypted** room.\n\n![Example with E2E](/images/example_with_e2e.png)\n\n\u003e No 100% guarantee that it will work straight away.\n\n### Requirements\n\n- Python 3.10+\n- [`matrix-commander`](https://github.com/8go/matrix-commander/tree/master)\n\n|         | example / additional information                                                                       |\n| ------- | ------------------------------------------------------------------------------------------------------ |\n| room id | **You have to join** with this special account to **this room** before! (available in _room_ settings) |\n\nIf you want to use E2E without carrying out the following steps, you will receive the following error messages:\n\n```\nERROR: matrix-commander: E153: Credentials file was not found. Provide credentials file or use --login to create a credentials file.\nINFO: matrix-commander: 1 error and 0 warnings occurred.\nFailed to send message (with E2E). Error: Command '['matrix-commander', '--room', '!xyz:matrix.org', '-m', '\u003cb\u003eHello World!\u003c/b\u003e', '--html']' returned non-zero exit status 1.\n```\n\n#### `matrix-commander` parameters\n\n| parameter      | description                         | example                          |\n| -------------- | ----------------------------------- | -------------------------------- |\n| `device`       | name for the sending device         | matrix-commander-notifier        |\n| `user-login`   | your username                       | @test:matrix.org                 |\n| `password`     | login password for your bot account |                                  |\n| `homeserver`   | homeserver of your bot account      | https://matrix-client.matrix.org |\n| `room-default` | room id                             | !xyz:matrix.org                  |\n\n#### Installation\n\nA credentials file must be created for the `matrix-commander`. To do this, execute the following:\n\n```bash\nmatrix-commander --login PASSWORD --device 'REPLACE-ME' --user-login 'REPLACE-ME' --password 'REPLACE-ME' --homeserver 'REPLACE-ME' --room-default 'REPLACE-ME'\n```\n\n\u003e You have to replace all `REPLACE-ME` with your own credentials!\n\nTo verify a room session, once you have been invited and accepted into the room, you will need to go to the bot account in the room settings with the account you want to receive the encrypted messages with and verify the current session using emojis.\n\nIn this case, it is better to start from an [Element](https://element.io/) room of the account with which you want to receive the encrypted messages, for example.\n\nTo verify a session immediately, send a message directly to a room:\n\n```bash\nmatrix-commander --room 'REPLACE-ME' -m 'First encrypted message :)'\n```\n\nTherefore:\n\n```bash\nmatrix-commander --verify emoji\n```\n\n\u003e If you do not perform this step, the messages will be sent encrypted, but the session will not be verified and a warning will be displayed along with the message in messenger.\n\n## Test and try with [Conda](https://docs.conda.io/en/latest/)\n\n```bash\nconda create --name matrix_env python=3.10\n```\n\n```bash\nconda activate matrix_env\n```\n\nUpdate Python:\n\n```bash\nconda update python\n```\n\n(Upgrade Python:)\n\n```bash\nconda upgrade python\n```\n\nRun [`matrix.py`](./matrix.py):\n\n```bash\npython3 matrix.py\n```\n\n## Repository that uses this template\n\n- [Checkmk-Matrix-Notifications](https://github.com/fuchs-fabian/Checkmk-Matrix-Notifications)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffuchs-fabian%2Fmatrix-notify-py-template","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffuchs-fabian%2Fmatrix-notify-py-template","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffuchs-fabian%2Fmatrix-notify-py-template/lists"}