mirror of
https://github.com/bbernhard/signal-cli-rest-api.git
synced 2026-05-25 14:34:22 +00:00
Compare commits
9 Commits
5cccafeb1e
...
1dfed2b987
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
1dfed2b987 | ||
|
|
184231020c | ||
|
|
52e058eb06 | ||
|
|
e8a80ef896 | ||
|
|
97197f1fbe | ||
|
|
e19dc961fd | ||
|
|
246ebfd4e6 | ||
|
|
8ea7456812 | ||
|
|
95c14a5f2b |
35
Dockerfile
35
Dockerfile
@ -1,6 +1,6 @@
|
||||
ARG SIGNAL_CLI_VERSION=0.14.2
|
||||
ARG LIBSIGNAL_CLIENT_VERSION=0.90.0
|
||||
ARG SIGNAL_CLI_NATIVE_PACKAGE_VERSION=0.14.2+morph027+2
|
||||
ARG SIGNAL_CLI_VERSION=0.14.3
|
||||
ARG LIBSIGNAL_CLIENT_VERSION=0.92.1
|
||||
ARG SIGNAL_CLI_NATIVE_PACKAGE_VERSION=0.14.3+morph027+1
|
||||
|
||||
ARG SWAG_VERSION=1.16.4
|
||||
ARG GRAALVM_VERSION=25.0.2
|
||||
@ -16,9 +16,19 @@ ARG GRAALVM_VERSION
|
||||
ARG BUILD_VERSION_ARG
|
||||
ARG SIGNAL_CLI_NATIVE_PACKAGE_VERSION
|
||||
|
||||
COPY ext/libraries/libsignal-client/v${LIBSIGNAL_CLIENT_VERSION} /tmp/libsignal-client-libraries
|
||||
RUN dpkg-reconfigure debconf --frontend=noninteractive \
|
||||
&& apt-get update \
|
||||
&& apt-get -y install --no-install-recommends \
|
||||
wget git locales zip unzip \
|
||||
file build-essential libz-dev zlib1g-dev binutils \
|
||||
&& rm -rf /var/lib/apt/lists/*
|
||||
|
||||
COPY ext/libraries/libsignal-client/signal-cli-native.patch /tmp/signal-cli-native.patch
|
||||
|
||||
#COPY ext/libraries/libsignal-client/v${LIBSIGNAL_CLIENT_VERSION} /tmp/libsignal-client-libraries
|
||||
RUN wget https://github.com/bbernhard/libsignal-client-builds/releases/download/v${LIBSIGNAL_CLIENT_VERSION}/libsignal-client-build-v${LIBSIGNAL_CLIENT_VERSION}.tar.gz -O /tmp/libsignal-client.tar.gz
|
||||
RUN cd /tmp && mkdir -p /tmp/libsignal-client-libraries && tar xf libsignal-client.tar.gz && mv x86-64 armv7 arm64 -t libsignal-client-libraries
|
||||
|
||||
# use architecture specific libsignal_jni.so
|
||||
RUN arch="$(uname -m)"; \
|
||||
case "$arch" in \
|
||||
@ -28,13 +38,6 @@ RUN arch="$(uname -m)"; \
|
||||
*) echo "Unknown architecture" && exit 1 ;; \
|
||||
esac;
|
||||
|
||||
RUN dpkg-reconfigure debconf --frontend=noninteractive \
|
||||
&& apt-get update \
|
||||
&& apt-get -y install --no-install-recommends \
|
||||
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 && \
|
||||
dpkg-reconfigure --frontend=noninteractive locales && \
|
||||
update-locale LANG=en_US.UTF-8
|
||||
@ -94,11 +97,11 @@ RUN if [ "$(uname -m)" = "x86_64" ]; then \
|
||||
&& 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 \
|
||||
#&& unzip archive.zip \
|
||||
#&& mv signal-cli-native-arm64/*deb . \
|
||||
&& apt-get update \
|
||||
&& apt-get download signal-cli-native=${SIGNAL_CLI_NATIVE_PACKAGE_VERSION} \
|
||||
&& wget https://gitlab.com/packaging/signal-cli/-/jobs/14049119045/artifacts/download?file_type=archive -O /tmp/signal-cli-native/archive.zip \
|
||||
&& unzip archive.zip \
|
||||
&& mv signal-cli-native-arm64-trigger/*deb . \
|
||||
#&& apt-get update \
|
||||
#&& apt-get download signal-cli-native=${SIGNAL_CLI_NATIVE_PACKAGE_VERSION} \
|
||||
&& ar x *.deb \
|
||||
&& tar xf data.tar.gz \
|
||||
&& mkdir -p /tmp/signal-cli-${SIGNAL_CLI_VERSION}-source/build/native/nativeCompile \
|
||||
|
||||
@ -1,16 +1,16 @@
|
||||
diff --git a/build.gradle.kts b/build.gradle.kts
|
||||
index 5d127e4c..7ca155f9 100644
|
||||
index 64e29294..5d0e53cc 100644
|
||||
--- a/build.gradle.kts
|
||||
+++ b/build.gradle.kts
|
||||
@@ -91,6 +91,7 @@ dependencies {
|
||||
implementation(libs.logback)
|
||||
implementation(libs.zxing)
|
||||
@@ -104,6 +104,7 @@ dependencies {
|
||||
implementation(libs.micronaut.json.schema.generator)
|
||||
}
|
||||
implementation(project(":libsignal-cli"))
|
||||
+ implementation(files("/tmp/libsignal-client.jar"))
|
||||
+ implementation(files("/tmp/libsignal-client.jar"))
|
||||
|
||||
testImplementation(libs.junit.jupiter)
|
||||
testImplementation(platform(libs.junit.jupiter.bom))
|
||||
@@ -107,6 +108,10 @@ configurations {
|
||||
@@ -120,6 +121,10 @@ configurations {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
BIN
ext/libraries/libsignal-client/v0.92.1/arm64/libsignal_jni.so
Normal file
BIN
ext/libraries/libsignal-client/v0.92.1/arm64/libsignal_jni.so
Normal file
Binary file not shown.
BIN
ext/libraries/libsignal-client/v0.92.1/armv7/libsignal_jni.so
Normal file
BIN
ext/libraries/libsignal-client/v0.92.1/armv7/libsignal_jni.so
Normal file
Binary file not shown.
BIN
ext/libraries/libsignal-client/v0.92.1/x86-64/libsignal_jni.so
Normal file
BIN
ext/libraries/libsignal-client/v0.92.1/x86-64/libsignal_jni.so
Normal file
Binary file not shown.
211
src/api/graylogapi.go
Normal file
211
src/api/graylogapi.go
Normal file
@ -0,0 +1,211 @@
|
||||
package api
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"strconv"
|
||||
"strings"
|
||||
"fmt"
|
||||
|
||||
_ "runtime/debug"
|
||||
_ "github.com/yassinebenaid/godump"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
log "github.com/sirupsen/logrus"
|
||||
|
||||
"github.com/bbernhard/signal-cli-rest-api/client"
|
||||
)
|
||||
|
||||
type AlertManagerNotification struct {
|
||||
Receiver string `json:"receiver"`
|
||||
Status string `json:"status"`
|
||||
Alerts []Alert `json:"alerts"`
|
||||
GroupLabels Labels `json:"groupLabels"`
|
||||
CommonLabels Labels `json:"commonLabels"`
|
||||
CommonAnnotations Annotations `json:"commonAnnotations"`
|
||||
ExternalURL string `json:"externalURL"`
|
||||
Version string `json:"version"`
|
||||
GroupKey string `json:"groupKey"`
|
||||
TruncatedAlerts int64 `json:"truncatedAlerts"`
|
||||
OrgID int64 `json:"orgId"`
|
||||
Title string `json:"title"`
|
||||
State string `json:"state"`
|
||||
Message string `json:"message"`
|
||||
}
|
||||
|
||||
type Alert struct {
|
||||
Status string `json:"status"`
|
||||
Labels Labels `json:"labels"`
|
||||
Annotations Annotations `json:"annotations"`
|
||||
StartsAt string `json:"startsAt"`
|
||||
EndsAt string `json:"endsAt"`
|
||||
GeneratorURL string `json:"generatorURL"`
|
||||
Fingerprint string `json:"fingerprint"`
|
||||
SilenceURL string `json:"silenceURL"`
|
||||
DashboardURL string `json:"dashboardURL"`
|
||||
PanelURL string `json:"panelURL"`
|
||||
Values interface{} `json:"values"`
|
||||
ValueString string `json:"valueString"`
|
||||
}
|
||||
|
||||
type Annotations struct {
|
||||
Summary string `json:"summary"`
|
||||
}
|
||||
|
||||
type Labels struct {
|
||||
Alertname string `json:"alertname"`
|
||||
Instance string `json:"instance"`
|
||||
}
|
||||
|
||||
type GrafanaMessage struct {
|
||||
Number string `json:"number"`
|
||||
Recipients string `json:"recipients"`
|
||||
Message string `json:"message"`
|
||||
}
|
||||
|
||||
type GraylogNotification struct {
|
||||
EventDefinitionID string `json:"event_definition_id"`
|
||||
EventDefinitionType string `json:"event_definition_type"`
|
||||
EventDefinitionTitle string `json:"event_definition_title"`
|
||||
EventDefinitionDescription string `json:"event_definition_description"`
|
||||
JobDefinitionID string `json:"job_definition_id"`
|
||||
JobTriggerID string `json:"job_trigger_id"`
|
||||
Event GraylogEvent `json:"event"`
|
||||
Backlog []interface{} `json:"backlog"`
|
||||
}
|
||||
|
||||
type GraylogEvent struct {
|
||||
ID string `json:"id"`
|
||||
EventDefinitionType string `json:"event_definition_type"`
|
||||
EventDefinitionID string `json:"event_definition_id"`
|
||||
OriginContext string `json:"origin_context"`
|
||||
Timestamp string `json:"timestamp"`
|
||||
TimestampProcessing string `json:"timestamp_processing"`
|
||||
TimerangeStart interface{} `json:"timerange_start"`
|
||||
TimerangeEnd interface{} `json:"timerange_end"`
|
||||
Streams []string `json:"streams"`
|
||||
SourceStreams []interface{} `json:"source_streams"`
|
||||
Message string `json:"message"`
|
||||
Source string `json:"source"`
|
||||
KeyTuple []string `json:"key_tuple"`
|
||||
Key string `json:"key"`
|
||||
Priority int64 `json:"priority"`
|
||||
Alert bool `json:"alert"`
|
||||
Fields Fields `json:"fields"`
|
||||
}
|
||||
|
||||
type Fields struct {
|
||||
Recipients string `json:"recipients"`
|
||||
FromNumber string `json:"fromnumber"`
|
||||
Message string `json:"message"`
|
||||
}
|
||||
|
||||
// @Summary Send a signal message.
|
||||
// @Tags Messages
|
||||
// @Description Send a signal message. Set the text_mode to 'styled' in case you want to add formatting to your text message. Styling Options: *italic text*, **bold text**, ~strikethrough text~.
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Success 201 {object} SendMessageResponse
|
||||
// @Failure 400 {object} SendMessageError
|
||||
// @Param data body SendMessageV2 true "Input Data"
|
||||
// @Router /v2/send [post]
|
||||
func (a *Api) SendAlertManagerV2(c *gin.Context) {
|
||||
var req AlertManagerNotification
|
||||
var msg GrafanaMessage
|
||||
base64Attachments := []string{}
|
||||
|
||||
err := c.BindJSON(&req)
|
||||
if err != nil {
|
||||
c.JSON(400, gin.H{"error": "Couldn't process request - invalid request"})
|
||||
log.Error(err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
//fmt.Printf(">>>%s\n",[]byte(req.Message))
|
||||
|
||||
// Unmarshal or Decode the JSON to the interface.
|
||||
json.Unmarshal([]byte(req.Message), &msg)
|
||||
|
||||
// timestamp, err := a.signalClient.SendV1(msg.Number, msg.Message, msg.Recipients, base64Attachments, msg.IsGroup)
|
||||
// if err != nil {
|
||||
// c.JSON(400, Error{Msg: err.Error()})
|
||||
// return
|
||||
// }
|
||||
// c.JSON(201, SendMessageResponse{Timestamp: strconv.FormatInt(timestamp.Timestamp, 10)})
|
||||
|
||||
data, err := a.signalClient.SendV2(msg.Number, msg.Message, strings.Split(msg.Recipients,","), base64Attachments, "", nil, nil, nil, nil, nil, nil, nil, nil)
|
||||
|
||||
if err != nil {
|
||||
switch err.(type) {
|
||||
case *client.RateLimitErrorType:
|
||||
if rateLimitError, ok := err.(*client.RateLimitErrorType); ok {
|
||||
extendedError := errors.New(err.Error() + ". Use the attached challenge tokens to lift the rate limit restrictions via the '/v1/accounts/{number}/rate-limit-challenge' endpoint.")
|
||||
c.JSON(429, SendMessageError{Msg: extendedError.Error(), ChallengeTokens: rateLimitError.ChallengeTokens, Account: msg.Number})
|
||||
return
|
||||
} else {
|
||||
c.JSON(400, Error{Msg: err.Error()})
|
||||
return
|
||||
}
|
||||
default:
|
||||
c.JSON(400, Error{Msg: err.Error()})
|
||||
return
|
||||
}
|
||||
c.JSON(400, Error{Msg: err.Error()})
|
||||
return
|
||||
}
|
||||
|
||||
c.JSON(201, SendMessageResponse{Timestamp: strconv.FormatInt((*data)[0].Timestamp, 10)})
|
||||
|
||||
}
|
||||
|
||||
// @Summary Send a signal message.
|
||||
// @Tags Messages
|
||||
// @Description Send a signal message. Set the text_mode to 'styled' in case you want to add formatting to your text message. Styling Options: *italic text*, **bold text**, ~strikethrough text~.
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Success 201 {object} SendMessageResponse
|
||||
// @Failure 400 {object} SendMessageError
|
||||
// @Param data body SendMessageV2 true "Input Data"
|
||||
// @Router /v2/send [post]
|
||||
func (a *Api) SendGraylogNotificationV2(c *gin.Context) {
|
||||
var req GraylogNotification
|
||||
base64Attachments := []string{}
|
||||
// jsonData,err2 := io.ReadAll(c.Request.Body)
|
||||
//if err2 != nil {
|
||||
// log.Error(err2.Error())
|
||||
//}
|
||||
//fmt.Printf("<<<%s\n",jsonData)
|
||||
|
||||
err := c.BindJSON(&req)
|
||||
if err != nil {
|
||||
c.JSON(400, gin.H{"error": "Couldn't process request - invalid requestttttt"})
|
||||
log.Error(err.Error())
|
||||
fmt.Printf("<<<%s\n",c.Request.Body)
|
||||
return
|
||||
}
|
||||
|
||||
data, err := a.signalClient.SendV2(req.Event.Fields.FromNumber, req.Event.Fields.Message, strings.Split(req.Event.Fields.Recipients,","), base64Attachments, "", nil, nil, nil, nil, nil, nil, nil, nil)
|
||||
|
||||
if err != nil {
|
||||
switch err.(type) {
|
||||
case *client.RateLimitErrorType:
|
||||
if rateLimitError, ok := err.(*client.RateLimitErrorType); ok {
|
||||
extendedError := errors.New(err.Error() + ". Use the attached challenge tokens to lift the rate limit restrictions via the '/v1/accounts/{number}/rate-limit-challenge' endpoint.")
|
||||
c.JSON(429, SendMessageError{Msg: extendedError.Error(), ChallengeTokens: rateLimitError.ChallengeTokens, Account: req.Event.Fields.FromNumber})
|
||||
return
|
||||
} else {
|
||||
c.JSON(400, Error{Msg: err.Error()})
|
||||
return
|
||||
}
|
||||
default:
|
||||
c.JSON(400, Error{Msg: err.Error()})
|
||||
return
|
||||
}
|
||||
c.JSON(400, Error{Msg: err.Error()})
|
||||
return
|
||||
}
|
||||
|
||||
c.JSON(201, SendMessageResponse{Timestamp: strconv.FormatInt((*data)[0].Timestamp, 10)})
|
||||
}
|
||||
|
||||
|
||||
@ -369,6 +369,14 @@ func main() {
|
||||
{
|
||||
sendV2.POST("", api.SendV2)
|
||||
}
|
||||
sendalertmanagerV2 := v2.Group("/sendalertmanager")
|
||||
{
|
||||
sendalertmanagerV2.POST("", api.SendAlertManagerV2)
|
||||
}
|
||||
sendgraylognotificationV2 := v2.Group("/sendgraylognotification")
|
||||
{
|
||||
sendgraylognotificationV2.POST("", api.SendGraylogNotificationV2)
|
||||
}
|
||||
}
|
||||
|
||||
protocol := "http"
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user