mirror of
https://github.com/kuhyx/signal-bot.git
synced 2026-07-04 11:43:03 +02:00
Merge branch 'main' of https://github.com/kuhyx/signal-bot
This commit is contained in:
commit
824c79dbf7
23
.github/workflows/pylint.yml
vendored
Normal file
23
.github/workflows/pylint.yml
vendored
Normal file
@ -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')
|
||||
39
.github/workflows/python-app.yml
vendored
Normal file
39
.github/workflows/python-app.yml
vendored
Normal file
@ -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
|
||||
34
.github/workflows/python-package-conda.yml
vendored
Normal file
34
.github/workflows/python-package-conda.yml
vendored
Normal file
@ -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
|
||||
21
SECURITY.md
Normal file
21
SECURITY.md
Normal file
@ -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.
|
||||
2
main.py
2
main.py
@ -184,7 +184,7 @@ async def get_attachments():
|
||||
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)
|
||||
|
||||
88
readme.md
88
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"
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
## 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=json-rpc' 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.
|
||||
|
||||
Loading…
Reference in New Issue
Block a user