mirror of
https://github.com/bbernhard/signal-cli-rest-api.git
synced 2026-05-19 13:34:19 +00:00
Compare commits
1 Commits
fa17535a90
...
25bd1c0d51
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
25bd1c0d51 |
@ -1,6 +1,6 @@
|
|||||||
ARG SIGNAL_CLI_VERSION=0.14.0
|
ARG SIGNAL_CLI_VERSION=0.14.0
|
||||||
ARG LIBSIGNAL_CLIENT_VERSION=0.87.4
|
ARG LIBSIGNAL_CLIENT_VERSION=0.87.4
|
||||||
ARG SIGNAL_CLI_NATIVE_PACKAGE_VERSION=0.14.0+morph027+5
|
ARG SIGNAL_CLI_NATIVE_PACKAGE_VERSION=0.14.0+morph027+3
|
||||||
|
|
||||||
ARG SWAG_VERSION=1.16.4
|
ARG SWAG_VERSION=1.16.4
|
||||||
ARG GRAALVM_VERSION=25.0.2
|
ARG GRAALVM_VERSION=25.0.2
|
||||||
@ -185,7 +185,7 @@ ENV SIGNAL_CLI_REST_API_PLUGIN_SHARED_OBJ_DIR=/usr/bin/
|
|||||||
|
|
||||||
RUN dpkg-reconfigure debconf --frontend=noninteractive \
|
RUN dpkg-reconfigure debconf --frontend=noninteractive \
|
||||||
&& apt-get update \
|
&& apt-get update \
|
||||||
&& apt-get install -y --no-install-recommends util-linux supervisor openjdk-25-jre curl locales \
|
&& apt-get install -y --no-install-recommends util-linux supervisor netcat-openbsd openjdk-25-jre curl locales \
|
||||||
&& rm -rf /var/lib/apt/lists/*
|
&& 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
|
COPY --from=buildcontainer /tmp/signal-cli-rest-api-src/signal-cli-rest-api /usr/bin/signal-cli-rest-api
|
||||||
|
|||||||
@ -4,8 +4,6 @@ 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'```
|
```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.
|
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
|
e.g Let's assume we are experiencing some problems with sending messages. So, let's send a Signal message with
|
||||||
|
|||||||
@ -410,7 +410,7 @@ func (s *SignalClient) GetSignalCliMode() SignalCliMode {
|
|||||||
return s.signalCliMode
|
return s.signalCliMode
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *SignalClient) Init(maxRetries int) error {
|
func (s *SignalClient) Init() error {
|
||||||
s.signalCliApiConfig = utils.NewSignalCliApiConfig()
|
s.signalCliApiConfig = utils.NewSignalCliApiConfig()
|
||||||
err := s.signalCliApiConfig.Load(s.signalCliApiConfigPath)
|
err := s.signalCliApiConfig.Load(s.signalCliApiConfigPath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -427,7 +427,7 @@ func (s *SignalClient) Init(maxRetries int) error {
|
|||||||
tcpPortsNumberMapping := s.jsonRpc2ClientConfig.GetTcpPortsForNumbers()
|
tcpPortsNumberMapping := s.jsonRpc2ClientConfig.GetTcpPortsForNumbers()
|
||||||
for number, tcpPort := range tcpPortsNumberMapping {
|
for number, tcpPort := range tcpPortsNumberMapping {
|
||||||
s.jsonRpc2Clients[number] = NewJsonRpc2Client(s.signalCliApiConfig, number)
|
s.jsonRpc2Clients[number] = NewJsonRpc2Client(s.signalCliApiConfig, number)
|
||||||
err := s.jsonRpc2Clients[number].Dial("127.0.0.1:"+strconv.FormatInt(tcpPort, 10), maxRetries)
|
err := s.jsonRpc2Clients[number].Dial("127.0.0.1:" + strconv.FormatInt(tcpPort, 10))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|||||||
@ -2,14 +2,14 @@ package client
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"bufio"
|
"bufio"
|
||||||
"bytes"
|
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"errors"
|
"errors"
|
||||||
"net"
|
"net"
|
||||||
"net/http"
|
|
||||||
"strconv"
|
|
||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
"net/http"
|
||||||
|
"bytes"
|
||||||
|
"strconv"
|
||||||
|
|
||||||
"github.com/bbernhard/signal-cli-rest-api/utils"
|
"github.com/bbernhard/signal-cli-rest-api/utils"
|
||||||
uuid "github.com/gofrs/uuid"
|
uuid "github.com/gofrs/uuid"
|
||||||
@ -60,11 +60,11 @@ type JsonRpc2Client struct {
|
|||||||
conn net.Conn
|
conn net.Conn
|
||||||
receivedResponsesById map[string]chan JsonRpc2MessageResponse
|
receivedResponsesById map[string]chan JsonRpc2MessageResponse
|
||||||
receivedMessagesChannels map[string]chan JsonRpc2ReceivedMessage
|
receivedMessagesChannels map[string]chan JsonRpc2ReceivedMessage
|
||||||
|
lastTimeErrorMessageSent time.Time
|
||||||
signalCliApiConfig *utils.SignalCliApiConfig
|
signalCliApiConfig *utils.SignalCliApiConfig
|
||||||
number string
|
number string
|
||||||
receivedMessagesMutex sync.Mutex
|
receivedMessagesMutex sync.Mutex
|
||||||
receivedResponsesMutex sync.Mutex
|
receivedResponsesMutex sync.Mutex
|
||||||
address string
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewJsonRpc2Client(signalCliApiConfig *utils.SignalCliApiConfig, number string) *JsonRpc2Client {
|
func NewJsonRpc2Client(signalCliApiConfig *utils.SignalCliApiConfig, number string) *JsonRpc2Client {
|
||||||
@ -76,24 +76,10 @@ func NewJsonRpc2Client(signalCliApiConfig *utils.SignalCliApiConfig, number stri
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *JsonRpc2Client) Dial(address string, maxRetries int) error {
|
func (r *JsonRpc2Client) Dial(address string) error {
|
||||||
var err error
|
var err error
|
||||||
r.address = address
|
r.conn, err = net.Dial("tcp", address)
|
||||||
connected := false
|
if err != nil {
|
||||||
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
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -221,14 +207,11 @@ func (r *JsonRpc2Client) ReceiveData(number string, receiveWebhookUrl string) {
|
|||||||
for {
|
for {
|
||||||
str, err := connbuf.ReadString('\n')
|
str, err := connbuf.ReadString('\n')
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error("Lost connection to signal-cli...attempting to reconnect (", err.Error(), ")")
|
elapsed := time.Since(r.lastTimeErrorMessageSent)
|
||||||
r.conn.Close()
|
if (elapsed) > time.Duration(5*time.Minute) { //avoid spamming the log file and only log the message at max every 5 minutes
|
||||||
err = r.Dial(r.address, 15)
|
log.Error("Couldn't read data for number ", number, ": ", err.Error(), ". Is the number properly registered?")
|
||||||
if err != nil {
|
r.lastTimeErrorMessageSent = time.Now()
|
||||||
log.Fatal("Unable to reconnect to signal-cli: ", err.Error(), "...aborting")
|
|
||||||
}
|
}
|
||||||
connbuf = bufio.NewReader(r.conn)
|
|
||||||
log.Info("Successfully reconnected to signal-cli")
|
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
log.Debug("json-rpc received data: ", str)
|
log.Debug("json-rpc received data: ", str)
|
||||||
@ -265,7 +248,7 @@ func (r *JsonRpc2Client) ReceiveData(number string, receiveWebhookUrl string) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
log.Warn("Received unparsable message: ", str)
|
log.Error("Received unparsable message: ", str)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -163,7 +163,7 @@ func main() {
|
|||||||
jsonRpc2ClientConfigPathPath := *signalCliConfig + "/jsonrpc2.yml"
|
jsonRpc2ClientConfigPathPath := *signalCliConfig + "/jsonrpc2.yml"
|
||||||
signalCliApiConfigPath := *signalCliConfig + "/api-config.yml"
|
signalCliApiConfigPath := *signalCliConfig + "/api-config.yml"
|
||||||
signalClient := client.NewSignalClient(*signalCliConfig, *attachmentTmpDir, *avatarTmpDir, signalCliMode, jsonRpc2ClientConfigPathPath, signalCliApiConfigPath, webhookUrl)
|
signalClient := client.NewSignalClient(*signalCliConfig, *attachmentTmpDir, *avatarTmpDir, signalCliMode, jsonRpc2ClientConfigPathPath, signalCliApiConfigPath, webhookUrl)
|
||||||
err = signalClient.Init(15)
|
err = signalClient.Init()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal("Couldn't init Signal Client: ", err.Error())
|
log.Fatal("Couldn't init Signal Client: ", err.Error())
|
||||||
}
|
}
|
||||||
|
|||||||
@ -14,7 +14,7 @@ import (
|
|||||||
const supervisorctlConfigTemplate = `
|
const supervisorctlConfigTemplate = `
|
||||||
[program:%s]
|
[program:%s]
|
||||||
process_name=%s
|
process_name=%s
|
||||||
command=signal-cli --output=json --config %s%s daemon %s%s --tcp 127.0.0.1:%d
|
command=bash -c "nc -l -p %d <%s | signal-cli --output=json --config %s%s jsonRpc%s%s >%s"
|
||||||
autostart=true
|
autostart=true
|
||||||
autorestart=true
|
autorestart=true
|
||||||
startretries=10
|
startretries=10
|
||||||
@ -96,7 +96,7 @@ func main() {
|
|||||||
supervisorctlConfigFilename := "/etc/supervisor/conf.d/" + "signal-cli-json-rpc-1.conf"
|
supervisorctlConfigFilename := "/etc/supervisor/conf.d/" + "signal-cli-json-rpc-1.conf"
|
||||||
|
|
||||||
supervisorctlConfig := fmt.Sprintf(supervisorctlConfigTemplate, supervisorctlProgramName, supervisorctlProgramName,
|
supervisorctlConfig := fmt.Sprintf(supervisorctlConfigTemplate, supervisorctlProgramName, supervisorctlProgramName,
|
||||||
signalCliConfigDir, trustNewIdentities, signalCliIgnoreAttachments, signalCliIgnoreStories, tcpPort,
|
tcpPort, fifoPathname, signalCliConfigDir, trustNewIdentities, signalCliIgnoreAttachments, signalCliIgnoreStories, fifoPathname,
|
||||||
supervisorctlProgramName, supervisorctlProgramName)
|
supervisorctlProgramName, supervisorctlProgramName)
|
||||||
|
|
||||||
err = ioutil.WriteFile(supervisorctlConfigFilename, []byte(supervisorctlConfig), 0644)
|
err = ioutil.WriteFile(supervisorctlConfigFilename, []byte(supervisorctlConfig), 0644)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user