Signal CLI is a command-line interface for the Signal messaging app, which allows you to automate and integrate messaging functionalities into your systems. Using Docker simplifies the installation process and helps you manage the Signal CLI as a containerized application. Here's a step-by-step guide to setting it up with Docker.
Prerequisites
Before we start, ensure you have the following:
- Docker installed on your system (guide)
- Basic knowledge of Docker commands
Steps for Installation
Create Required Directories
First, create the necessary directories to store your data:
mkdir -p /home/mahesh/docker/signal-api/data
cd /home/mahesh/docker/signal-api
Create the docker-compose.yml File
Next, create and edit the docker-compose.yml file to configure your Signal CLI container. You can use the following configuration:
nano docker-compose.yml
Paste the following into the file:
services:
signal-api:
image: bbernhard/signal-cli-rest-api
container_name: signal-api
restart: always
ports:
- "8003:8080"
environment:
- MODE=native
volumes:
- ./data:/home/.local/share/signal-cli
This configuration uses the official bbernhard/signal-cli-rest-api Docker image and maps the data directory to persist Signal's data.
Start the Container
Now, start the Signal CLI container using Docker Compose:
sudo docker compose up -d
The -d flag runs the container in detached mode, allowing it to run in the background.
Register or Link your Signal Number
In this case we'll register our container as secondary device, assuming that you already have your primary number running / assigned to your mobile.
Therefore open http://localhost:8003/v1/qrcodelink?device_name=signal-api in your browser, open Signal on your mobile phone, go to Settings > Linked devices and scan the QR code using the + button.
Access the Signal API
Once the container is up and running, the Signal API will be available at http://localhost:8003. You can use this to send and receive messages via Signal programmatically.
Sending Messages Using REST API
Once your Signal API is running, you can send messages using a simple REST API call. For this, we'll use the curl command to send a POST request to the Signal API.
Here’s an example of how to send a message:
curl -X POST -H "Content-Type: application/json" \
'http://localhost:8003/v2/send' \
-d '{"message": "Test via Signal API!", "number": "+919567XXXXXX", "recipients": [ "+919846XXXXXX" ]}'
- message: The message to be sent.
- number: Your Signal-registered phone number.
- recipients: The list of recipient phone numbers to which you want to send the message.