From 2930f5494e3d238e73ee37b660895a762b4c59ae Mon Sep 17 00:00:00 2001 From: kuhyx <147418882+kuhyx@users.noreply.github.com> Date: Mon, 24 Jun 2024 12:19:18 +0200 Subject: [PATCH 1/7] Update readme.md --- readme.md | 88 +++++++++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 83 insertions(+), 5 deletions(-) diff --git a/readme.md b/readme.md index 1af21f3..99106ec 100644 --- a/readme.md +++ b/readme.md @@ -1,8 +1,12 @@ -Usefull: -https://bbernhard.github.io/signal-cli-rest-api/ +# Signal CLI REST API Integration Guide +This guide will help you set up and run a Signal bot using the Signal CLI REST API. For more details, refer to the [signal cli rest api examples](https://bbernhard.github.io/signal-cli-rest-api/). -If the message was send from the same account as the bot is connected to: +## Message Formats + +### Message Sent from the Same Account as the Bot + +```json { "envelope": { "source": "NAME", @@ -25,8 +29,11 @@ If the message was send from the same account as the bot is connected to: }, "account": "BOT_ACCOUNT_PHONE_NUMBER" } +``` -If the message was send from other account: +### Message Sent from Another Account + +```json { "envelope": { "source": "NAME", @@ -47,4 +54,75 @@ If the message was send from other account: } }, "account": "BOT_ACCOUNT_PHONE_NUMBER" -} \ No newline at end of file +} +``` + +## Setting Up the WebSocket Server + +The bot uses `asyncio` for running the WebSocket server and simple Python fetch requests/responses for sending and receiving data. + +### How to Run + +1. Follow the instructions on the [Signal CLI REST API GitHub page](https://github.com/bbernhard/signal-cli-rest-api#getting-started). + + The main steps are summarized below: + + ```sh + sudo docker run -d --name signal-api --restart=always -p 9922:8080 \ + -v /home/user/signal-api:/home/.local/share/signal-cli \ + -e 'MODE=native' bbernhard/signal-cli-rest-api + ``` + +2. Access the Signal CLI setup page: + + ```sh + http://localhost:9922/v1/qrcodelink?device_name=signal-api + ``` + +3. Scan the QR code to complete the Signal CLI setup. + +### Clone the Repository + +```sh +git clone https://github.com/kuhyx/signal-bot +``` + +### Initialize the Python Virtual Environment + +```sh +python -m venv venv +``` + +### Add Necessary API Information + +Edit the `venv/bin/activate` file: + +```sh +vim venv/bin/activate +``` + +Add the following lines at the end of the file: + +```sh +export PHONE_NUMBER="+69YOURPHONENUMBER" +export CAT_API="CAN_LEAVE_BLANK" +export GROUP_ID="MESSAGES_SEND_HERE_WILL_TRIGGER_COMMANDS" +export GROUP_ID_SEND="TRIGGERED_COMMANDS_WILL_SEND_DATA_HERE" +``` +And source the venv shell: +```sh +source venv/bin/activate +``` +### Install Required Python Packages + +```sh +pip install -r requirements.txt +``` + +### Run the Server + +```sh +python main.py +``` + +Now your Signal bot should be up and running, ready to send and receive messages via the Signal CLI REST API. From bcd3e6f2750d017b32a4650d961f5dc18bfdc51f Mon Sep 17 00:00:00 2001 From: kuhyx <147418882+kuhyx@users.noreply.github.com> Date: Mon, 24 Jun 2024 12:20:18 +0200 Subject: [PATCH 2/7] Update readme.md --- readme.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/readme.md b/readme.md index 99106ec..202cc5e 100644 --- a/readme.md +++ b/readme.md @@ -70,7 +70,7 @@ The bot uses `asyncio` for running the WebSocket server and simple Python fetch ```sh sudo docker run -d --name signal-api --restart=always -p 9922:8080 \ -v /home/user/signal-api:/home/.local/share/signal-cli \ - -e 'MODE=native' bbernhard/signal-cli-rest-api + -e 'MODE=json-rpc' bbernhard/signal-cli-rest-api ``` 2. Access the Signal CLI setup page: From d016c625108d24ca1db5448efcc43a78ddb5f1bc Mon Sep 17 00:00:00 2001 From: kuhyx <147418882+kuhyx@users.noreply.github.com> Date: Mon, 24 Jun 2024 12:20:47 +0200 Subject: [PATCH 3/7] Create python-app.yml --- .github/workflows/python-app.yml | 39 ++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 .github/workflows/python-app.yml diff --git a/.github/workflows/python-app.yml b/.github/workflows/python-app.yml new file mode 100644 index 0000000..1168bd9 --- /dev/null +++ b/.github/workflows/python-app.yml @@ -0,0 +1,39 @@ +# This workflow will install Python dependencies, run tests and lint with a single version of Python +# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-python + +name: Python application + +on: + push: + branches: [ "main" ] + pull_request: + branches: [ "main" ] + +permissions: + contents: read + +jobs: + build: + + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v4 + - name: Set up Python 3.10 + uses: actions/setup-python@v3 + with: + python-version: "3.10" + - name: Install dependencies + run: | + python -m pip install --upgrade pip + pip install flake8 pytest + if [ -f requirements.txt ]; then pip install -r requirements.txt; fi + - name: Lint with flake8 + run: | + # stop the build if there are Python syntax errors or undefined names + flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics + # exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide + flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics + - name: Test with pytest + run: | + pytest From c04621d6341bc62f1721b550cc6a138e68889adf Mon Sep 17 00:00:00 2001 From: kuhyx <147418882+kuhyx@users.noreply.github.com> Date: Mon, 24 Jun 2024 12:21:00 +0200 Subject: [PATCH 4/7] Create python-package-conda.yml --- .github/workflows/python-package-conda.yml | 34 ++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 .github/workflows/python-package-conda.yml diff --git a/.github/workflows/python-package-conda.yml b/.github/workflows/python-package-conda.yml new file mode 100644 index 0000000..f358604 --- /dev/null +++ b/.github/workflows/python-package-conda.yml @@ -0,0 +1,34 @@ +name: Python Package using Conda + +on: [push] + +jobs: + build-linux: + runs-on: ubuntu-latest + strategy: + max-parallel: 5 + + steps: + - uses: actions/checkout@v4 + - name: Set up Python 3.10 + uses: actions/setup-python@v3 + with: + python-version: '3.10' + - name: Add conda to system path + run: | + # $CONDA is an environment variable pointing to the root of the miniconda directory + echo $CONDA/bin >> $GITHUB_PATH + - name: Install dependencies + run: | + conda env update --file environment.yml --name base + - name: Lint with flake8 + run: | + conda install flake8 + # stop the build if there are Python syntax errors or undefined names + flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics + # exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide + flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics + - name: Test with pytest + run: | + conda install pytest + pytest From 38f69c69b9b6eb4ff870fe9e7d783f65674a6340 Mon Sep 17 00:00:00 2001 From: kuhyx <147418882+kuhyx@users.noreply.github.com> Date: Mon, 24 Jun 2024 12:25:43 +0200 Subject: [PATCH 5/7] Create pylint.yml --- .github/workflows/pylint.yml | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 .github/workflows/pylint.yml diff --git a/.github/workflows/pylint.yml b/.github/workflows/pylint.yml new file mode 100644 index 0000000..c73e032 --- /dev/null +++ b/.github/workflows/pylint.yml @@ -0,0 +1,23 @@ +name: Pylint + +on: [push] + +jobs: + build: + runs-on: ubuntu-latest + strategy: + matrix: + python-version: ["3.8", "3.9", "3.10"] + steps: + - uses: actions/checkout@v4 + - name: Set up Python ${{ matrix.python-version }} + uses: actions/setup-python@v3 + with: + python-version: ${{ matrix.python-version }} + - name: Install dependencies + run: | + python -m pip install --upgrade pip + pip install pylint + - name: Analysing the code with pylint + run: | + pylint $(git ls-files '*.py') From f32cecd78ab4c2fab35de5af31ac1c101bddaf62 Mon Sep 17 00:00:00 2001 From: kuhyx <147418882+kuhyx@users.noreply.github.com> Date: Mon, 24 Jun 2024 12:26:18 +0200 Subject: [PATCH 6/7] Create SECURITY.md --- SECURITY.md | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 SECURITY.md diff --git a/SECURITY.md b/SECURITY.md new file mode 100644 index 0000000..034e848 --- /dev/null +++ b/SECURITY.md @@ -0,0 +1,21 @@ +# Security Policy + +## Supported Versions + +Use this section to tell people about which versions of your project are +currently being supported with security updates. + +| Version | Supported | +| ------- | ------------------ | +| 5.1.x | :white_check_mark: | +| 5.0.x | :x: | +| 4.0.x | :white_check_mark: | +| < 4.0 | :x: | + +## Reporting a Vulnerability + +Use this section to tell people how to report a vulnerability. + +Tell them where to go, how often they can expect to get an update on a +reported vulnerability, what to expect if the vulnerability is accepted or +declined, etc. From e1264ce58f7efc8ab30c1b8edbf2743cbe73e77a Mon Sep 17 00:00:00 2001 From: kuhyx <147418882+kuhyx@users.noreply.github.com> Date: Mon, 24 Jun 2024 12:27:52 +0200 Subject: [PATCH 7/7] Removed sensitive signal server console log --- main.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/main.py b/main.py index 9368f0f..9a5e8a8 100644 --- a/main.py +++ b/main.py @@ -152,7 +152,7 @@ async def scheduled_task(queue): async def listen_to_server(queue): uri = f"ws://localhost:9922/v1/receive/{PHONE_NUMBER}?send_read_receipts=false" async with websockets.connect(uri) as websocket: - print(f"Connected to server at {uri}") + print(f"Connected to signal server") try: async for message in websocket: message_content = extract_message_content(message)