mirror of
https://github.com/aljazceru/signal-cli-rest-api.git
synced 2025-12-19 15:44:28 +01:00
@@ -1439,6 +1439,16 @@ func (a *Api) AddDevice(c *gin.Context) {
|
||||
c.Status(http.StatusNoContent)
|
||||
}
|
||||
|
||||
// @Summary Set account specific settings.
|
||||
// @Tags General
|
||||
// @Description Set account specific settings.
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Param number path string true "Registered Phone Number"
|
||||
// @Success 204
|
||||
// @Param data body TrustModeRequest true "Request"
|
||||
// @Failure 400 {object} Error
|
||||
// @Router /v1/configuration/{number}/settings [post]
|
||||
func (a *Api) SetTrustMode(c *gin.Context) {
|
||||
number := c.Param("number")
|
||||
if number == "" {
|
||||
@@ -1468,6 +1478,16 @@ func (a *Api) SetTrustMode(c *gin.Context) {
|
||||
c.Status(http.StatusNoContent)
|
||||
}
|
||||
|
||||
// @Summary List account specific settings.
|
||||
// @Tags General
|
||||
// @Description List account specific settings.
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Param number path string true "Registered Phone Number"
|
||||
// @Success 200
|
||||
// @Param data body TrustModeResponse true "Request"
|
||||
// @Failure 400 {object} Error
|
||||
// @Router /v1/configuration/{number}/settings [get]
|
||||
func (a *Api) GetTrustMode(c *gin.Context) {
|
||||
number := c.Param("number")
|
||||
if number == "" {
|
||||
|
||||
@@ -262,7 +262,7 @@ func (s *SignalClient) Init() error {
|
||||
|
||||
tcpPortsNumberMapping := s.jsonRpc2ClientConfig.GetTcpPortsForNumbers()
|
||||
for number, tcpPort := range tcpPortsNumberMapping {
|
||||
s.jsonRpc2Clients[number] = NewJsonRpc2Client(s.signalCliApiConfig)
|
||||
s.jsonRpc2Clients[number] = NewJsonRpc2Client(s.signalCliApiConfig, number)
|
||||
err := s.jsonRpc2Clients[number].Dial("127.0.0.1:" + strconv.FormatInt(tcpPort, 10))
|
||||
if err != nil {
|
||||
return err
|
||||
|
||||
@@ -10,6 +10,7 @@ import (
|
||||
"github.com/bbernhard/signal-cli-rest-api/utils"
|
||||
uuid "github.com/gofrs/uuid"
|
||||
log "github.com/sirupsen/logrus"
|
||||
"github.com/tidwall/sjson"
|
||||
)
|
||||
|
||||
type Error struct {
|
||||
@@ -35,11 +36,13 @@ type JsonRpc2Client struct {
|
||||
receivedMessages chan JsonRpc2ReceivedMessage
|
||||
lastTimeErrorMessageSent time.Time
|
||||
signalCliApiConfig *utils.SignalCliApiConfig
|
||||
number string
|
||||
}
|
||||
|
||||
func NewJsonRpc2Client(signalCliApiConfig *utils.SignalCliApiConfig) *JsonRpc2Client {
|
||||
func NewJsonRpc2Client(signalCliApiConfig *utils.SignalCliApiConfig, number string) *JsonRpc2Client {
|
||||
return &JsonRpc2Client{
|
||||
signalCliApiConfig: signalCliApiConfig,
|
||||
number: number,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -64,6 +67,16 @@ func (r *JsonRpc2Client) getRaw(command string, args interface{}) (string, error
|
||||
Params interface{} `json:"params,omitempty"`
|
||||
}
|
||||
|
||||
trustModeStr := ""
|
||||
trustMode, err := r.signalCliApiConfig.GetTrustModeForNumber(r.number)
|
||||
if err == nil {
|
||||
trustModeStr, err = utils.TrustModeToString(trustMode)
|
||||
if err != nil {
|
||||
trustModeStr = ""
|
||||
log.Error("Invalid trust mode: ", trustModeStr)
|
||||
}
|
||||
}
|
||||
|
||||
u, err := uuid.NewV4()
|
||||
if err != nil {
|
||||
return "", err
|
||||
@@ -79,6 +92,13 @@ func (r *JsonRpc2Client) getRaw(command string, args interface{}) (string, error
|
||||
return "", err
|
||||
}
|
||||
|
||||
if trustModeStr != "" {
|
||||
fullCommandBytes, err = sjson.SetBytes(fullCommandBytes, "params.trustNewIdentities", trustModeStr)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
}
|
||||
|
||||
log.Debug("full command: ", string(fullCommandBytes))
|
||||
|
||||
_, err = r.conn.Write([]byte(string(fullCommandBytes) + "\n"))
|
||||
|
||||
@@ -209,6 +209,88 @@ var doc = `{
|
||||
}
|
||||
}
|
||||
},
|
||||
"/v1/configuration/{number}/settings": {
|
||||
"get": {
|
||||
"description": "List account specific settings.",
|
||||
"consumes": [
|
||||
"application/json"
|
||||
],
|
||||
"produces": [
|
||||
"application/json"
|
||||
],
|
||||
"tags": [
|
||||
"General"
|
||||
],
|
||||
"summary": "List account specific settings.",
|
||||
"parameters": [
|
||||
{
|
||||
"type": "string",
|
||||
"description": "Registered Phone Number",
|
||||
"name": "number",
|
||||
"in": "path",
|
||||
"required": true
|
||||
},
|
||||
{
|
||||
"description": "Request",
|
||||
"name": "data",
|
||||
"in": "body",
|
||||
"required": true,
|
||||
"schema": {
|
||||
"$ref": "#/definitions/api.TrustModeResponse"
|
||||
}
|
||||
}
|
||||
],
|
||||
"responses": {
|
||||
"200": {},
|
||||
"400": {
|
||||
"description": "Bad Request",
|
||||
"schema": {
|
||||
"$ref": "#/definitions/api.Error"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"post": {
|
||||
"description": "Set account specific settings.",
|
||||
"consumes": [
|
||||
"application/json"
|
||||
],
|
||||
"produces": [
|
||||
"application/json"
|
||||
],
|
||||
"tags": [
|
||||
"General"
|
||||
],
|
||||
"summary": "Set account specific settings.",
|
||||
"parameters": [
|
||||
{
|
||||
"type": "string",
|
||||
"description": "Registered Phone Number",
|
||||
"name": "number",
|
||||
"in": "path",
|
||||
"required": true
|
||||
},
|
||||
{
|
||||
"description": "Request",
|
||||
"name": "data",
|
||||
"in": "body",
|
||||
"required": true,
|
||||
"schema": {
|
||||
"$ref": "#/definitions/api.TrustModeRequest"
|
||||
}
|
||||
}
|
||||
],
|
||||
"responses": {
|
||||
"204": {},
|
||||
"400": {
|
||||
"description": "Bad Request",
|
||||
"schema": {
|
||||
"$ref": "#/definitions/api.Error"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"/v1/contacts{number}": {
|
||||
"put": {
|
||||
"description": "Updates the info associated to a number on the contact list.",
|
||||
@@ -1658,6 +1740,22 @@ var doc = `{
|
||||
}
|
||||
}
|
||||
},
|
||||
"api.TrustModeRequest": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"trust_mode": {
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
},
|
||||
"api.TrustModeResponse": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"trust_mode": {
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
},
|
||||
"api.TypingIndicatorRequest": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
|
||||
@@ -193,6 +193,88 @@
|
||||
}
|
||||
}
|
||||
},
|
||||
"/v1/configuration/{number}/settings": {
|
||||
"get": {
|
||||
"description": "List account specific settings.",
|
||||
"consumes": [
|
||||
"application/json"
|
||||
],
|
||||
"produces": [
|
||||
"application/json"
|
||||
],
|
||||
"tags": [
|
||||
"General"
|
||||
],
|
||||
"summary": "List account specific settings.",
|
||||
"parameters": [
|
||||
{
|
||||
"type": "string",
|
||||
"description": "Registered Phone Number",
|
||||
"name": "number",
|
||||
"in": "path",
|
||||
"required": true
|
||||
},
|
||||
{
|
||||
"description": "Request",
|
||||
"name": "data",
|
||||
"in": "body",
|
||||
"required": true,
|
||||
"schema": {
|
||||
"$ref": "#/definitions/api.TrustModeResponse"
|
||||
}
|
||||
}
|
||||
],
|
||||
"responses": {
|
||||
"200": {},
|
||||
"400": {
|
||||
"description": "Bad Request",
|
||||
"schema": {
|
||||
"$ref": "#/definitions/api.Error"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"post": {
|
||||
"description": "Set account specific settings.",
|
||||
"consumes": [
|
||||
"application/json"
|
||||
],
|
||||
"produces": [
|
||||
"application/json"
|
||||
],
|
||||
"tags": [
|
||||
"General"
|
||||
],
|
||||
"summary": "Set account specific settings.",
|
||||
"parameters": [
|
||||
{
|
||||
"type": "string",
|
||||
"description": "Registered Phone Number",
|
||||
"name": "number",
|
||||
"in": "path",
|
||||
"required": true
|
||||
},
|
||||
{
|
||||
"description": "Request",
|
||||
"name": "data",
|
||||
"in": "body",
|
||||
"required": true,
|
||||
"schema": {
|
||||
"$ref": "#/definitions/api.TrustModeRequest"
|
||||
}
|
||||
}
|
||||
],
|
||||
"responses": {
|
||||
"204": {},
|
||||
"400": {
|
||||
"description": "Bad Request",
|
||||
"schema": {
|
||||
"$ref": "#/definitions/api.Error"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"/v1/contacts{number}": {
|
||||
"put": {
|
||||
"description": "Updates the info associated to a number on the contact list.",
|
||||
@@ -1642,6 +1724,22 @@
|
||||
}
|
||||
}
|
||||
},
|
||||
"api.TrustModeRequest": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"trust_mode": {
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
},
|
||||
"api.TrustModeResponse": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"trust_mode": {
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
},
|
||||
"api.TypingIndicatorRequest": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
|
||||
@@ -141,6 +141,16 @@ definitions:
|
||||
verified_safety_number:
|
||||
type: string
|
||||
type: object
|
||||
api.TrustModeRequest:
|
||||
properties:
|
||||
trust_mode:
|
||||
type: string
|
||||
type: object
|
||||
api.TrustModeResponse:
|
||||
properties:
|
||||
trust_mode:
|
||||
type: string
|
||||
type: object
|
||||
api.TypingIndicatorRequest:
|
||||
properties:
|
||||
recipient:
|
||||
@@ -356,6 +366,61 @@ paths:
|
||||
summary: Set the REST API configuration.
|
||||
tags:
|
||||
- General
|
||||
/v1/configuration/{number}/settings:
|
||||
get:
|
||||
consumes:
|
||||
- application/json
|
||||
description: List account specific settings.
|
||||
parameters:
|
||||
- description: Registered Phone Number
|
||||
in: path
|
||||
name: number
|
||||
required: true
|
||||
type: string
|
||||
- description: Request
|
||||
in: body
|
||||
name: data
|
||||
required: true
|
||||
schema:
|
||||
$ref: '#/definitions/api.TrustModeResponse'
|
||||
produces:
|
||||
- application/json
|
||||
responses:
|
||||
"200": {}
|
||||
"400":
|
||||
description: Bad Request
|
||||
schema:
|
||||
$ref: '#/definitions/api.Error'
|
||||
summary: List account specific settings.
|
||||
tags:
|
||||
- General
|
||||
post:
|
||||
consumes:
|
||||
- application/json
|
||||
description: Set account specific settings.
|
||||
parameters:
|
||||
- description: Registered Phone Number
|
||||
in: path
|
||||
name: number
|
||||
required: true
|
||||
type: string
|
||||
- description: Request
|
||||
in: body
|
||||
name: data
|
||||
required: true
|
||||
schema:
|
||||
$ref: '#/definitions/api.TrustModeRequest'
|
||||
produces:
|
||||
- application/json
|
||||
responses:
|
||||
"204": {}
|
||||
"400":
|
||||
description: Bad Request
|
||||
schema:
|
||||
$ref: '#/definitions/api.Error'
|
||||
summary: Set account specific settings.
|
||||
tags:
|
||||
- General
|
||||
/v1/contacts{number}:
|
||||
put:
|
||||
consumes:
|
||||
|
||||
@@ -20,6 +20,7 @@ require (
|
||||
github.com/swaggo/files v0.0.0-20190704085106-630677cd5c14
|
||||
github.com/swaggo/gin-swagger v1.2.0
|
||||
github.com/swaggo/swag v1.6.7
|
||||
github.com/tidwall/sjson v1.2.4 // indirect
|
||||
github.com/urfave/cli/v2 v2.2.0 // indirect
|
||||
golang.org/x/net v0.0.0-20200625001655-4c5254603344 // indirect
|
||||
golang.org/x/text v0.3.3 // indirect
|
||||
|
||||
@@ -128,6 +128,14 @@ github.com/swaggo/gin-swagger v1.2.0/go.mod h1:qlH2+W7zXGZkczuL+r2nEBR2JTT+/lX05
|
||||
github.com/swaggo/swag v1.5.1/go.mod h1:1Bl9F/ZBpVWh22nY0zmYyASPO1lI/zIwRDrpZU+tv8Y=
|
||||
github.com/swaggo/swag v1.6.7 h1:e8GC2xDllJZr3omJkm9YfmK0Y56+rMO3cg0JBKNz09s=
|
||||
github.com/swaggo/swag v1.6.7/go.mod h1:xDhTyuFIujYiN3DKWC/H/83xcfHp+UE/IzWWampG7Zc=
|
||||
github.com/tidwall/gjson v1.12.1 h1:ikuZsLdhr8Ws0IdROXUS1Gi4v9Z4pGqpX/CvJkxvfpo=
|
||||
github.com/tidwall/gjson v1.12.1/go.mod h1:/wbyibRr2FHMks5tjHJ5F8dMZh3AcwJEMf5vlfC0lxk=
|
||||
github.com/tidwall/match v1.1.1 h1:+Ho715JplO36QYgwN9PGYNhgZvoUSc9X2c80KVTi+GA=
|
||||
github.com/tidwall/match v1.1.1/go.mod h1:eRSPERbgtNPcGhD8UCthc6PmLEQXEWd3PRB5JTxsfmM=
|
||||
github.com/tidwall/pretty v1.2.0 h1:RWIZEg2iJ8/g6fDDYzMpobmaoGh5OLl4AXtGUGPcqCs=
|
||||
github.com/tidwall/pretty v1.2.0/go.mod h1:ITEVvHYasfjBbM0u2Pg8T2nJnzm8xPwvNhhsoaGGjNU=
|
||||
github.com/tidwall/sjson v1.2.4 h1:cuiLzLnaMeBhRmEv00Lpk3tkYrcxpmbU81tAY4Dw0tc=
|
||||
github.com/tidwall/sjson v1.2.4/go.mod h1:098SZ494YoMWPmMO6ct4dcFnqxwj9r/gF0Etp19pSNM=
|
||||
github.com/ugorji/go v1.1.4/go.mod h1:uQMGLiO92mf5W77hV/PUCpI3pbzQx3CRekS0kk+RGrc=
|
||||
github.com/ugorji/go v1.1.5-pre/go.mod h1:FwP/aQVg39TXzItUBMwnWp9T9gPQnXw4Poh4/oBQZ/0=
|
||||
github.com/ugorji/go v1.1.7 h1:/68gy2h+1mWMrwZFeD1kQialdSzAb432dtpeJ42ovdo=
|
||||
|
||||
@@ -150,8 +150,8 @@ func main() {
|
||||
{
|
||||
configuration.GET("", api.GetConfiguration)
|
||||
configuration.POST("", api.SetConfiguration)
|
||||
configuration.POST(":number/trustmode", api.SetTrustMode)
|
||||
configuration.GET(":number/trustmode", api.GetTrustMode)
|
||||
configuration.POST(":number/settings", api.SetTrustMode)
|
||||
configuration.GET(":number/settings", api.GetTrustMode)
|
||||
}
|
||||
|
||||
health := v1.Group("/health")
|
||||
|
||||
Reference in New Issue
Block a user