mirror of
https://github.com/aljazceru/signal-cli-rest-api.git
synced 2025-12-20 08:04:28 +01:00
activate endpoint and write swagger documentation
This commit is contained in:
@@ -1,9 +1,11 @@
|
||||
version: "3"
|
||||
services:
|
||||
signal-cli-rest-api:
|
||||
image: bbernhard/signal-cli-rest-api:latest
|
||||
#image: bbernhard/signal-cli-rest-api:latest
|
||||
build: .
|
||||
environment:
|
||||
- MODE=normal #supported modes: json-rpc, native, normal
|
||||
# - MODE=normal #supported modes: json-rpc, native, normal
|
||||
- MODE=json-rpc #supported modes: json-rpc, native, normal
|
||||
#- AUTO_RECEIVE_SCHEDULE=0 22 * * * #enable this parameter on demand (see description below)
|
||||
ports:
|
||||
- "8080:8080" #map docker port 8080 to host port 8080.
|
||||
|
||||
@@ -902,7 +902,7 @@ func (a *Api) QuitGroup(c *gin.Context) {
|
||||
// @Success 204 {string} OK
|
||||
// @Failure 400 {object} Error
|
||||
// @Param data body Reaction true "Reaction"
|
||||
// @Router /v1/reaction/{number} [post]
|
||||
// @Router /v1/reactions/{number} [post]
|
||||
func (a *Api) SendReaction(c *gin.Context) {
|
||||
var req Reaction
|
||||
err := c.BindJSON(&req)
|
||||
@@ -950,7 +950,7 @@ func (a *Api) SendReaction(c *gin.Context) {
|
||||
// @Success 204 {string} OK
|
||||
// @Failure 400 {object} Error
|
||||
// @Param data body Reaction true "Reaction"
|
||||
// @Router /v1/reaction/{number} [delete]
|
||||
// @Router /v1/reactions/{number} [delete]
|
||||
func (a *Api) RemoveReaction(c *gin.Context) {
|
||||
var req Reaction
|
||||
err := c.BindJSON(&req)
|
||||
@@ -967,11 +967,6 @@ func (a *Api) RemoveReaction(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
if req.Reaction == "" {
|
||||
c.JSON(400, Error{Msg: "Couldn't process request - reaction missing"})
|
||||
return
|
||||
}
|
||||
|
||||
if req.TargetAuthor == "" {
|
||||
c.JSON(400, Error{Msg: "Couldn't process request - target_author missing"})
|
||||
return
|
||||
|
||||
@@ -1008,6 +1008,9 @@ func (s *SignalClient) SendReaction(number string, recipient string, emoji strin
|
||||
return errors.New("Invalid group id")
|
||||
}
|
||||
}
|
||||
if remove && emoji == "" {
|
||||
emoji = "👍" // emoji must not be empty to remove a reaction
|
||||
}
|
||||
|
||||
if s.signalCliMode == JsonRpc {
|
||||
type Request struct {
|
||||
@@ -1027,7 +1030,7 @@ func (s *SignalClient) SendReaction(number string, recipient string, emoji strin
|
||||
request.Emoji = emoji
|
||||
request.TargetAuthor = target_author
|
||||
request.Timestamp = timestamp
|
||||
if remove == true {
|
||||
if remove {
|
||||
request.Remove = remove
|
||||
}
|
||||
jsonRpc2Client, err := s.getJsonRpc2Client(number)
|
||||
|
||||
@@ -679,6 +679,101 @@
|
||||
}
|
||||
}
|
||||
},
|
||||
"/v1/reaction/{number}": {
|
||||
"post": {
|
||||
"description": "React to a message.",
|
||||
"consumes": [
|
||||
"application/json"
|
||||
],
|
||||
"produces": [
|
||||
"application/json"
|
||||
],
|
||||
"tags": [
|
||||
"Reaction"
|
||||
],
|
||||
"summary": "Send a reaction.",
|
||||
"parameters": [
|
||||
{
|
||||
"description": "Reaction",
|
||||
"name": "data",
|
||||
"in": "body",
|
||||
"required": true,
|
||||
"schema": {
|
||||
"$ref": "#/definitions/api.Reaction"
|
||||
}
|
||||
}
|
||||
],
|
||||
"responses": {
|
||||
"204": {
|
||||
"description": "No Content",
|
||||
"schema": {
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"400": {
|
||||
"description": "Bad Request",
|
||||
"schema": {
|
||||
"$ref": "#/definitions/api.Error"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"delete": {
|
||||
"description": "Delete a reaction.",
|
||||
"consumes": [
|
||||
"application/json"
|
||||
],
|
||||
"produces": [
|
||||
"application/json"
|
||||
],
|
||||
"tags": [
|
||||
"Reaction"
|
||||
],
|
||||
"summary": "Delete a reaction.",
|
||||
"parameters": [
|
||||
{
|
||||
"description": "Reaction",
|
||||
"name": "data",
|
||||
"in": "body",
|
||||
"required": true,
|
||||
"schema": {
|
||||
"$ref": "#/definitions/api.Reaction"
|
||||
}
|
||||
}
|
||||
],
|
||||
"responses": {
|
||||
"204": {
|
||||
"description": "No Content",
|
||||
"schema": {
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"400": {
|
||||
"description": "Bad Request",
|
||||
"schema": {
|
||||
"$ref": "#/definitions/api.Error"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"api.Reaction": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"recipient": {
|
||||
"type": "string"
|
||||
},
|
||||
"reaction": {
|
||||
"type": "string"
|
||||
},
|
||||
"target_author": {
|
||||
"type": "string"
|
||||
},
|
||||
"timestamp": {
|
||||
"type": "integer"
|
||||
}
|
||||
}
|
||||
},
|
||||
"/v1/receive/{number}": {
|
||||
"get": {
|
||||
"description": "Receives Signal Messages from the Signal Network. If you are running the docker container in normal/native mode, this is a GET endpoint. In json-rpc mode this is a websocket endpoint.",
|
||||
@@ -1280,6 +1375,10 @@
|
||||
{
|
||||
"description": "List and Trust Identities.",
|
||||
"name": "Identities"
|
||||
},
|
||||
{
|
||||
"description": "React to messages.",
|
||||
"name": "Reaction"
|
||||
}
|
||||
]
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
17
src/main.go
17
src/main.go
@@ -46,6 +46,9 @@ import (
|
||||
// @tag.name Identities
|
||||
// @tag.description List and Trust Identities.
|
||||
|
||||
// @tag.name Reaction
|
||||
// @tag.description React to messages.
|
||||
|
||||
// @host 127.0.0.1:8080
|
||||
// @BasePath /
|
||||
func main() {
|
||||
@@ -114,7 +117,6 @@ func main() {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
jsonRpc2ClientConfigPathPath := *signalCliConfig + "/jsonrpc2.yml"
|
||||
signalClient := client.NewSignalClient(*signalCliConfig, *attachmentTmpDir, *avatarTmpDir, signalCliMode, jsonRpc2ClientConfigPathPath)
|
||||
err = signalClient.Init()
|
||||
@@ -196,6 +198,12 @@ func main() {
|
||||
typingIndicator.PUT(":number", api.SendStartTyping)
|
||||
typingIndicator.DELETE(":number", api.SendStopTyping)
|
||||
}
|
||||
|
||||
reaction := v1.Group("/reaction")
|
||||
{
|
||||
reaction.POST(":number", api.SendReaction)
|
||||
reaction.DELETE(":number", api.RemoveReaction)
|
||||
}
|
||||
}
|
||||
|
||||
v2 := router.Group("/v2")
|
||||
@@ -228,7 +236,7 @@ func main() {
|
||||
filename := filepath.Base(path)
|
||||
if strings.HasPrefix(filename, "+") && info.Mode().IsRegular() {
|
||||
log.Debug("AUTO_RECEIVE_SCHEDULE: Calling receive for number ", filename)
|
||||
resp, err := http.Get("http://127.0.0.1:" + port + "/v1/receive/"+filename)
|
||||
resp, err := http.Get("http://127.0.0.1:" + port + "/v1/receive/" + filename)
|
||||
if err != nil {
|
||||
log.Error("AUTO_RECEIVE_SCHEDULE: Couldn't call receive for number ", filename, ": ", err.Error())
|
||||
}
|
||||
@@ -241,7 +249,7 @@ func main() {
|
||||
}
|
||||
|
||||
type ReceiveResponse struct {
|
||||
Error string `json:"error"`
|
||||
Error string `json:"error"`
|
||||
}
|
||||
var receiveResponse ReceiveResponse
|
||||
err = json.Unmarshal(jsonResp, &receiveResponse)
|
||||
@@ -264,8 +272,5 @@ func main() {
|
||||
c.Start()
|
||||
}
|
||||
|
||||
|
||||
router.Run()
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user