Compare commits

...

19 Commits

Author SHA1 Message Date
Lukas f. Paluch
368bf31a64
Merge f27a3c5206fead40d77aebac4424397b58be7f94 into ddc5aa55df34229f7cc2c452275ef3014b820361 2026-03-07 14:59:41 +01:00
Bernhard B
ddc5aa55df remove netcat-openbsd
* not needed anymore
2026-03-07 14:08:09 +01:00
Bernhard B
00bbfca878 updated signal-cli-native to 0.14.0+5 2026-03-07 14:08:09 +01:00
Bernhard B.
884582a71e
Merge pull request #807 from EvanHahn/debug-log-level-env-variable-docs
Mention `LOG_LEVEL` environment variable in debug docs
2026-03-06 17:38:45 +01:00
Evan Hahn
e3d503c746 Mention LOG_LEVEL environment variable in debug docs
This updates the debug docs to mention the `LOG_LEVEL` environment
variable.
2026-03-06 08:13:13 -06:00
Bernhard B
af34a0881c fixed small bug in json-rpc reconnect mechanism
* after we successfully reconnected, wait for new data
2026-03-05 20:50:42 +01:00
Bernhard B
c7cb9ab13e improved json-rpc reconnection logic
* when the connection the signal-cli daemon is lost in json-rpc mode,
  the open connection will be closed and a new connection attempt will
  be made. If after 15 connection attempts we are unable to connect to
  the signal-cli daemon, we give up and abort.
2026-03-05 20:43:22 +01:00
Bernhard B
af18c7aea8 switched to signal-cli daemon mode
* this gets rid off the ugly netcat workaround and should improve
  the general stability of the connection to the signal-cli binary
  in json-rpc mode.
2026-03-05 20:41:17 +01:00
Bernhard B
ed3626fa77 removed "apt-key add"
* "apt-key add" was removed from Debian, since it was insecure.
2026-03-04 21:36:34 +01:00
Bernhard B
6257fa754d updated buildcontainer to golang:1.26-trixie 2026-03-04 20:15:18 +01:00
Bernhard B
dd6d763618 switch back to old buildcontainer image 2026-03-04 17:55:31 +01:00
Bernhard B
1ea89705d5 updated signal-cli-native to v0.14.0 2026-03-04 16:33:45 +01:00
Bernhard B
9e5d73b5c0 temporarily switch back to signal-cli-native v0.13.24 2026-03-03 22:08:00 +01:00
Bernhard B.
d080e8d478
Merge pull request #793 from revilo951/master
Swap PendingRequests and PendingInvites assignments
2026-03-03 21:25:24 +01:00
Bernhard B
a9c367a5b1 updated golang buildcontainer 2026-03-03 21:16:20 +01:00
Bernhard B
8d13f5f383 updated signal-cli-native version 2026-03-02 17:38:47 +01:00
revilo951
3a36a04b09
Swap PendingRequests and PendingInvites assignments
Fix for https://github.com/bbernhard/signal-cli-rest-api/issues/792
2026-02-23 11:00:15 +11:00
Lukas Paluch
f27a3c5206
fix rootless entrypoint - clarify and append jsonrpc
- rework statemant to be more clear
    - append check of json-rpc mode to rootless part
2024-02-27 08:54:33 +01:00
Lukas f. Paluch
1be5684ae3
enable rootless start
fixes bbernhard/signal-cli-rest-api#490
2024-02-23 15:10:57 +01:00
9 changed files with 115 additions and 66 deletions

View File

@ -1,13 +1,13 @@
ARG SIGNAL_CLI_VERSION=0.14.0
ARG LIBSIGNAL_CLIENT_VERSION=0.87.4
ARG SIGNAL_CLI_NATIVE_PACKAGE_VERSION=0.14.0+morph027+1
ARG SIGNAL_CLI_NATIVE_PACKAGE_VERSION=0.14.0+morph027+5
ARG SWAG_VERSION=1.16.4
ARG GRAALVM_VERSION=25.0.2
ARG BUILD_VERSION_ARG=unset
FROM golang:1.24-bookworm AS buildcontainer
FROM golang:1.26-trixie AS buildcontainer
ARG SIGNAL_CLI_VERSION
ARG LIBSIGNAL_CLIENT_VERSION
@ -31,8 +31,8 @@ RUN arch="$(uname -m)"; \
RUN dpkg-reconfigure debconf --frontend=noninteractive \
&& apt-get update \
&& apt-get -y install --no-install-recommends \
wget software-properties-common git locales zip unzip \
file build-essential libz-dev zlib1g-dev \
wget git locales zip unzip \
file build-essential libz-dev zlib1g-dev binutils \
&& rm -rf /var/lib/apt/lists/*
RUN sed -i -e 's/# en_US.UTF-8 UTF-8/en_US.UTF-8 UTF-8/' /etc/locale.gen && \
@ -90,8 +90,8 @@ RUN if [ "$(uname -m)" = "x86_64" ]; then \
&& ./gradlew -q nativeCompile; \
elif [ "$(uname -m)" = "aarch64" ] ; then \
echo "Use native image from @morph027 (https://packaging.gitlab.io/signal-cli/) for arm64 - many thanks to @morph027" \
&& curl -fsSL https://packaging.gitlab.io/signal-cli/gpg.key | apt-key add - \
&& echo "deb https://packaging.gitlab.io/signal-cli focal main" > /etc/apt/sources.list.d/morph027-signal-cli.list \
&& curl -fsSL https://packaging.gitlab.io/signal-cli/gpg.key | gpg -o /usr/share/keyrings/signal-cli-native.pgp --dearmor \
&& echo "deb [signed-by=/usr/share/keyrings/signal-cli-native.pgp] https://packaging.gitlab.io/signal-cli signalcli main" > /etc/apt/sources.list.d/morph027-signal-cli.list \
&& mkdir -p /tmp/signal-cli-native \
&& cd /tmp/signal-cli-native \
#&& wget https://gitlab.com/packaging/signal-cli/-/jobs/3716873649/artifacts/download?file_type=archive -O /tmp/signal-cli-native/archive.zip \
@ -172,7 +172,7 @@ ENV SIGNAL_CLI_REST_API_PLUGIN_SHARED_OBJ_DIR=/usr/bin/
RUN dpkg-reconfigure debconf --frontend=noninteractive \
&& apt-get update \
&& apt-get install -y --no-install-recommends util-linux supervisor netcat-openbsd openjdk-25-jre curl locales \
&& apt-get install -y --no-install-recommends util-linux supervisor openjdk-25-jre curl locales \
&& rm -rf /var/lib/apt/lists/*
COPY --from=buildcontainer /tmp/signal-cli-rest-api-src/signal-cli-rest-api /usr/bin/signal-cli-rest-api

View File

@ -4,6 +4,8 @@ This can be done by putting the docker container into debug mode with the follow
```curl -X POST -H "Content-Type: application/json" -d '{"logging": {"level": "debug"}}' 'http://127.0.0.1:8080/v1/configuration'```
Alternatively, you can set the `LOG_LEVEL` environment variable.
Once the docker container is in debug mode, execute the REST API command you want to debug.
e.g Let's assume we are experiencing some problems with sending messages. So, let's send a Signal message with

View File

@ -1,11 +1,22 @@
version: "3"
services:
signal-cli-rest-api:
image: bbernhard/signal-cli-rest-api:latest
#image: bbernhard/signal-cli-rest-api:latest-dev
build: "."
environment:
- MODE=normal #supported modes: json-rpc, native, normal
- MODE=normal #supported modes: json-rpc, json-rpc-native, native, normal
- ENABLE_PLUGINS=true
- DEFAULT_SIGNAL_TEXT_MODE=styled
- SWAGGER_IP=127.0.0.1
- PODMAN_USERNS=keep-id
#- JSON_RPC_IGNORE_ATTACHMENTS=true
#- JSON_RPC_IGNORE_STORIES=true
#- RECEIVE_WEBHOOK_URL=http://127.0.0.1:8089/webhook
#- JSON_RPC_TRUST_NEW_IDENTITIES=always
#- RECEIVE_WEBHOOK_URL=http://127.0.0.1:8080/v1/plugins/abc
#- AUTO_RECEIVE_SCHEDULE=0 22 * * * #enable this parameter on demand (see description below)
#network_mode: host
ports:
- "8080:8080" #map docker port 8080 to host port 8080.
volumes:
- "./signal-cli-config:/home/.local/share/signal-cli" #map "signal-cli-config" folder on host system into docker container. the folder contains the password and cryptographic keys when a new number is registered
- "./plugins:/plugins"

View File

@ -3,8 +3,27 @@
set -x
set -e
[ -d /etc/docker ] && echo "$FILE is a directory."
[ -z "${SIGNAL_CLI_CONFIG_DIR}" ] && echo "SIGNAL_CLI_CONFIG_DIR environmental variable needs to be set! Aborting!" && exit 1;
if [ "$(id -u)" -eq "${SIGNAL_CLI_UID}" ] && [ "$(id -g)" -eq "${SIGNAL_CLI_GID}" ]]
then
echo "UID and GID are already correct. Trying to start Signal Api"
# TODO: check mode
if [ "$MODE" = "json-rpc" ]
then
/usr/bin/jsonrpc2-helper
if [ -n "$JAVA_OPTS" ] ; then
echo "export JAVA_OPTS='$JAVA_OPTS'" >> /etc/default/supervisor
fi
service supervisor start
supervisorctl start all
fi
signal-cli-rest-api -signal-cli-config=${SIGNAL_CLI_CONFIG_DIR};
fi
usermod -u ${SIGNAL_CLI_UID} signal-api
groupmod -o -g ${SIGNAL_CLI_GID} signal-api

View File

@ -215,7 +215,7 @@ type RemoteDeleteRequest struct {
}
type DeleteLocalAccountDataRequest struct {
IgnoreRegistered bool `json:"ignore_registered" example:"false"`
IgnoreRegistered bool `json:"ignore_registered" example:"false"`
}
type DeviceLinkUriResponse struct {
@ -364,30 +364,30 @@ func (a *Api) UnregisterNumber(c *gin.Context) {
// @Failure 400 {object} Error
// @Router /v1/devices/{number}/local-data [delete]
func (a *Api) DeleteLocalAccountData(c *gin.Context) {
number, err := url.PathUnescape(c.Param("number"))
if err != nil {
c.JSON(400, Error{Msg: "Couldn't process request - malformed number"})
return
}
if number == "" {
c.JSON(400, Error{Msg: "Couldn't process request - number missing"})
return
}
number, err := url.PathUnescape(c.Param("number"))
if err != nil {
c.JSON(400, Error{Msg: "Couldn't process request - malformed number"})
return
}
if number == "" {
c.JSON(400, Error{Msg: "Couldn't process request - number missing"})
return
}
req := DeleteLocalAccountDataRequest{}
if c.Request.Body != nil && c.Request.ContentLength != 0 {
if err := c.BindJSON(&req); err != nil {
c.JSON(400, Error{Msg: "Couldn't process request - invalid request"})
return
}
}
req := DeleteLocalAccountDataRequest{}
if c.Request.Body != nil && c.Request.ContentLength != 0 {
if err := c.BindJSON(&req); err != nil {
c.JSON(400, Error{Msg: "Couldn't process request - invalid request"})
return
}
}
if err := a.signalClient.DeleteLocalAccountData(number, req.IgnoreRegistered); err != nil {
c.JSON(400, Error{Msg: err.Error()})
return
}
if err := a.signalClient.DeleteLocalAccountData(number, req.IgnoreRegistered); err != nil {
c.JSON(400, Error{Msg: err.Error()})
return
}
c.Status(http.StatusNoContent)
c.Status(http.StatusNoContent)
}
// @Summary Verify a registered phone number.
@ -843,6 +843,7 @@ func (a *Api) AddMembersToGroup(c *gin.Context) {
err = a.signalClient.AddMembersToGroup(number, groupId, req.Members)
if err != nil {
log.Info("ERR NOT NULL")
switch err.(type) {
case *client.NotFoundError:
c.JSON(404, Error{Msg: err.Error()})
@ -1174,19 +1175,19 @@ func (a *Api) GetQrCodeLink(c *gin.Context) {
// @Failure 400 {object} Error
// @Router /v1/qrcodelink/raw [get]
func (a *Api) GetQrCodeLinkUri(c *gin.Context) {
deviceName := c.Query("device_name")
if deviceName == "" {
c.JSON(400, Error{Msg: "Please provide a name for the device"})
return
}
deviceName := c.Query("device_name")
if deviceName == "" {
c.JSON(400, Error{Msg: "Please provide a name for the device"})
return
}
deviceLinkUri, err := a.signalClient.GetDeviceLinkUri(deviceName)
if err != nil {
c.JSON(400, Error{Msg: err.Error()})
return
}
deviceLinkUri, err := a.signalClient.GetDeviceLinkUri(deviceName)
if err != nil {
c.JSON(400, Error{Msg: err.Error()})
return
}
c.JSON(200, DeviceLinkUriResponse{DeviceLinkUri: deviceLinkUri})
c.JSON(200, DeviceLinkUriResponse{DeviceLinkUri: deviceLinkUri})
}
// @Summary List all accounts
@ -2080,7 +2081,7 @@ func (a *Api) RemoveDevice(c *gin.Context) {
}
deviceIdStr := c.Param("deviceId")
deviceId, err := strconv.ParseInt(deviceIdStr, 10, 64)
deviceId, err := strconv.ParseInt(deviceIdStr, 10, 64)
if err != nil {
c.JSON(400, Error{Msg: "deviceId must be numeric"})
return

View File

@ -410,7 +410,7 @@ func (s *SignalClient) GetSignalCliMode() SignalCliMode {
return s.signalCliMode
}
func (s *SignalClient) Init() error {
func (s *SignalClient) Init(maxRetries int) error {
s.signalCliApiConfig = utils.NewSignalCliApiConfig()
err := s.signalCliApiConfig.Load(s.signalCliApiConfigPath)
if err != nil {
@ -427,7 +427,7 @@ func (s *SignalClient) Init() error {
tcpPortsNumberMapping := s.jsonRpc2ClientConfig.GetTcpPortsForNumbers()
for number, tcpPort := range tcpPortsNumberMapping {
s.jsonRpc2Clients[number] = NewJsonRpc2Client(s.signalCliApiConfig, number)
err := s.jsonRpc2Clients[number].Dial("127.0.0.1:" + strconv.FormatInt(tcpPort, 10))
err := s.jsonRpc2Clients[number].Dial("127.0.0.1:"+strconv.FormatInt(tcpPort, 10), maxRetries)
if err != nil {
return err
}
@ -1349,7 +1349,7 @@ func (s *SignalClient) GetGroups(number string) ([]GroupEntry, error) {
}
pendingMembers = append(pendingMembers, identifier)
}
groupEntry.PendingRequests = pendingMembers
groupEntry.PendingInvites = pendingMembers
requestingMembers := []string{}
for _, val := range signalCliGroupEntry.RequestingMembers {
@ -1359,7 +1359,7 @@ func (s *SignalClient) GetGroups(number string) ([]GroupEntry, error) {
}
requestingMembers = append(requestingMembers, identifier)
}
groupEntry.PendingInvites = requestingMembers
groupEntry.PendingRequests = requestingMembers
admins := []string{}
for _, val := range signalCliGroupEntry.Admins {
@ -2634,8 +2634,8 @@ func (s *SignalClient) ListContacts(number string, allRecipients bool, recipient
if s.signalCliMode == JsonRpc {
type Request struct {
AllRecipients bool `json:"allRecipients,omitempty"`
Recipient string `json:"recipient,omitempty"`
AllRecipients bool `json:"allRecipients,omitempty"`
Recipient string `json:"recipient,omitempty"`
}
req := Request{}
if allRecipients {
@ -2705,7 +2705,6 @@ func (s *SignalClient) ListContacts(number string, allRecipients bool, recipient
return resp, nil
}
func (s *SignalClient) SetPin(number string, registrationLockPin string) error {
if s.signalCliMode == JsonRpc {
type Request struct {

View File

@ -2,14 +2,14 @@ package client
import (
"bufio"
"bytes"
"encoding/json"
"errors"
"net"
"net/http"
"strconv"
"sync"
"time"
"net/http"
"bytes"
"strconv"
"github.com/bbernhard/signal-cli-rest-api/utils"
uuid "github.com/gofrs/uuid"
@ -60,11 +60,11 @@ type JsonRpc2Client struct {
conn net.Conn
receivedResponsesById map[string]chan JsonRpc2MessageResponse
receivedMessagesChannels map[string]chan JsonRpc2ReceivedMessage
lastTimeErrorMessageSent time.Time
signalCliApiConfig *utils.SignalCliApiConfig
number string
receivedMessagesMutex sync.Mutex
receivedResponsesMutex sync.Mutex
address string
}
func NewJsonRpc2Client(signalCliApiConfig *utils.SignalCliApiConfig, number string) *JsonRpc2Client {
@ -76,10 +76,24 @@ func NewJsonRpc2Client(signalCliApiConfig *utils.SignalCliApiConfig, number stri
}
}
func (r *JsonRpc2Client) Dial(address string) error {
func (r *JsonRpc2Client) Dial(address string, maxRetries int) error {
var err error
r.conn, err = net.Dial("tcp", address)
if err != nil {
r.address = address
connected := false
for i := 0; i < maxRetries; i++ {
r.conn, err = net.Dial("tcp", address)
if err != nil {
log.Info("Waiting for signal-cli to start up in daemon mode...")
time.Sleep(2 * time.Second)
continue
}
connected = true
log.Info("Successfully connected to signal-cli in daemon mode")
break
}
if !connected {
return err
}
@ -207,11 +221,14 @@ func (r *JsonRpc2Client) ReceiveData(number string, receiveWebhookUrl string) {
for {
str, err := connbuf.ReadString('\n')
if err != nil {
elapsed := time.Since(r.lastTimeErrorMessageSent)
if (elapsed) > time.Duration(5*time.Minute) { //avoid spamming the log file and only log the message at max every 5 minutes
log.Error("Couldn't read data for number ", number, ": ", err.Error(), ". Is the number properly registered?")
r.lastTimeErrorMessageSent = time.Now()
log.Error("Lost connection to signal-cli...attempting to reconnect (", err.Error(), ")")
r.conn.Close()
err = r.Dial(r.address, 15)
if err != nil {
log.Fatal("Unable to reconnect to signal-cli: ", err.Error(), "...aborting")
}
connbuf = bufio.NewReader(r.conn)
log.Info("Successfully reconnected to signal-cli")
continue
}
log.Debug("json-rpc received data: ", str)
@ -248,7 +265,7 @@ func (r *JsonRpc2Client) ReceiveData(number string, receiveWebhookUrl string) {
}
}
} else {
log.Error("Received unparsable message: ", str)
log.Warn("Received unparsable message: ", str)
}
}
}

View File

@ -163,7 +163,7 @@ func main() {
jsonRpc2ClientConfigPathPath := *signalCliConfig + "/jsonrpc2.yml"
signalCliApiConfigPath := *signalCliConfig + "/api-config.yml"
signalClient := client.NewSignalClient(*signalCliConfig, *attachmentTmpDir, *avatarTmpDir, signalCliMode, jsonRpc2ClientConfigPathPath, signalCliApiConfigPath, webhookUrl)
err = signalClient.Init()
err = signalClient.Init(15)
if err != nil {
log.Fatal("Couldn't init Signal Client: ", err.Error())
}

View File

@ -14,7 +14,7 @@ import (
const supervisorctlConfigTemplate = `
[program:%s]
process_name=%s
command=bash -c "nc -l -p %d <%s | signal-cli --output=json --config %s%s jsonRpc%s%s >%s"
command=signal-cli --output=json --config %s%s daemon %s%s --tcp 127.0.0.1:%d
autostart=true
autorestart=true
startretries=10
@ -96,7 +96,7 @@ func main() {
supervisorctlConfigFilename := "/etc/supervisor/conf.d/" + "signal-cli-json-rpc-1.conf"
supervisorctlConfig := fmt.Sprintf(supervisorctlConfigTemplate, supervisorctlProgramName, supervisorctlProgramName,
tcpPort, fifoPathname, signalCliConfigDir, trustNewIdentities, signalCliIgnoreAttachments, signalCliIgnoreStories, fifoPathname,
signalCliConfigDir, trustNewIdentities, signalCliIgnoreAttachments, signalCliIgnoreStories, tcpPort,
supervisorctlProgramName, supervisorctlProgramName)
err = ioutil.WriteFile(supervisorctlConfigFilename, []byte(supervisorctlConfig), 0644)