mirror of
https://github.com/bbernhard/signal-cli-rest-api.git
synced 2026-05-20 13:44:17 +00:00
WIP, define new endpoints for send reaction
This commit is contained in:
parent
2d80ff91a2
commit
55d63c90b6
@ -9,8 +9,8 @@ import (
|
|||||||
|
|
||||||
"github.com/gabriel-vasile/mimetype"
|
"github.com/gabriel-vasile/mimetype"
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
log "github.com/sirupsen/logrus"
|
|
||||||
"github.com/gorilla/websocket"
|
"github.com/gorilla/websocket"
|
||||||
|
log "github.com/sirupsen/logrus"
|
||||||
|
|
||||||
"github.com/bbernhard/signal-cli-rest-api/client"
|
"github.com/bbernhard/signal-cli-rest-api/client"
|
||||||
utils "github.com/bbernhard/signal-cli-rest-api/utils"
|
utils "github.com/bbernhard/signal-cli-rest-api/utils"
|
||||||
@ -57,6 +57,13 @@ type VerifyNumberSettings struct {
|
|||||||
Pin string `json:"pin"`
|
Pin string `json:"pin"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type Reaction struct {
|
||||||
|
Number string `json:"number"`
|
||||||
|
Timestamp int64 `json:"timestamp"`
|
||||||
|
Recipient string `json:"recipient"`
|
||||||
|
Reaction string `json:"reaction"`
|
||||||
|
}
|
||||||
|
|
||||||
type SendMessageV1 struct {
|
type SendMessageV1 struct {
|
||||||
Number string `json:"number"`
|
Number string `json:"number"`
|
||||||
Recipients []string `json:"recipients"`
|
Recipients []string `json:"recipients"`
|
||||||
@ -80,8 +87,6 @@ type Error struct {
|
|||||||
Msg string `json:"error"`
|
Msg string `json:"error"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
type CreateGroupResponse struct {
|
type CreateGroupResponse struct {
|
||||||
Id string `json:"id"`
|
Id string `json:"id"`
|
||||||
}
|
}
|
||||||
@ -283,7 +288,6 @@ func (a *Api) SendV2(c *gin.Context) {
|
|||||||
c.JSON(201, SendMessageResponse{Timestamp: strconv.FormatInt((*timestamps)[0].Timestamp, 10)})
|
c.JSON(201, SendMessageResponse{Timestamp: strconv.FormatInt((*timestamps)[0].Timestamp, 10)})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
func (a *Api) handleSignalReceive(ws *websocket.Conn, number string) {
|
func (a *Api) handleSignalReceive(ws *websocket.Conn, number string) {
|
||||||
for {
|
for {
|
||||||
data, err := a.signalClient.Receive(number, 0)
|
data, err := a.signalClient.Receive(number, 0)
|
||||||
@ -890,6 +894,52 @@ func (a *Api) QuitGroup(c *gin.Context) {
|
|||||||
c.Status(http.StatusNoContent)
|
c.Status(http.StatusNoContent)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// @Summary Send a reaction.
|
||||||
|
// @Tags Reactions
|
||||||
|
// @Description React to a message.
|
||||||
|
// @Accept json
|
||||||
|
// @Produce json
|
||||||
|
// @Success 201 {string} OK
|
||||||
|
// @Failure 400 {object} Error
|
||||||
|
// @Param data body Reaction true "Reaction"
|
||||||
|
// @Router /v1/react/{number} [post]
|
||||||
|
func (a *Api) SendReaction(c *gin.Context) {
|
||||||
|
var req Reaction
|
||||||
|
err := c.BindJSON(&req)
|
||||||
|
if err != nil {
|
||||||
|
c.JSON(400, Error{Msg: "Couldn't process request - invalid request"})
|
||||||
|
log.Error(err.Error())
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if req.Recipient == "" {
|
||||||
|
c.JSON(400, Error{Msg: "Couldn't process request - recipient missing"})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if req.Timestamp == 0 {
|
||||||
|
c.JSON(400, Error{Msg: "Couldn't process request - timestamp missing"})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if req.Reaction == "" {
|
||||||
|
c.JSON(400, Error{Msg: "Couldn't process request - reaction missing"})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if req.Number == "" {
|
||||||
|
c.JSON(400, Error{Msg: "Couldn't process request - number missing"})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
err = a.signalClient.SendReaction(req.Number, req.Recipient, req.Timestamp, req.Reaction)
|
||||||
|
if err != nil {
|
||||||
|
c.JSON(400, Error{Msg: err.Error()})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
c.Status(http.StatusNoContent)
|
||||||
|
}
|
||||||
|
|
||||||
// @Summary Show Typing Indicator.
|
// @Summary Show Typing Indicator.
|
||||||
// @Tags Messages
|
// @Tags Messages
|
||||||
// @Description Show Typing Indicator.
|
// @Description Show Typing Indicator.
|
||||||
|
|||||||
@ -14,9 +14,10 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/cyphar/filepath-securejoin"
|
securejoin "github.com/cyphar/filepath-securejoin"
|
||||||
"github.com/gabriel-vasile/mimetype"
|
"github.com/gabriel-vasile/mimetype"
|
||||||
"github.com/h2non/filetype"
|
"github.com/h2non/filetype"
|
||||||
|
|
||||||
//"github.com/sourcegraph/jsonrpc2"//"net/rpc/jsonrpc"
|
//"github.com/sourcegraph/jsonrpc2"//"net/rpc/jsonrpc"
|
||||||
log "github.com/sirupsen/logrus"
|
log "github.com/sirupsen/logrus"
|
||||||
|
|
||||||
@ -995,6 +996,56 @@ func (s *SignalClient) QuitGroup(number string, groupId string) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (s *SignalClient) SendReaction(number string, recipient string, timestamp int64, reaction string) error {
|
||||||
|
var err error
|
||||||
|
recp := recipient
|
||||||
|
isGroup := false
|
||||||
|
if strings.HasPrefix(recipient, groupPrefix) {
|
||||||
|
isGroup = true
|
||||||
|
recp, err = ConvertGroupIdToInternalGroupId(recipient)
|
||||||
|
if err != nil {
|
||||||
|
return errors.New("Invalid group id")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if s.signalCliMode == JsonRpc {
|
||||||
|
type Request struct {
|
||||||
|
Recipient string `json:"recipient,omitempty"`
|
||||||
|
GroupId string `json:"group-id,omitempty"`
|
||||||
|
// TODO other fields
|
||||||
|
}
|
||||||
|
request := Request{}
|
||||||
|
if !isGroup {
|
||||||
|
request.Recipient = recp
|
||||||
|
} else {
|
||||||
|
request.GroupId = recp
|
||||||
|
}
|
||||||
|
|
||||||
|
jsonRpc2Client, err := s.getJsonRpc2Client(number)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
_, err = jsonRpc2Client.getRaw("sendReaction", request)
|
||||||
|
} else {
|
||||||
|
// TODO: check CLI command again
|
||||||
|
cmd := []string{
|
||||||
|
"--config", s.signalCliConfig,
|
||||||
|
"-u", number,
|
||||||
|
"sendTyping",
|
||||||
|
"-e", reaction,
|
||||||
|
"-t", strconv.FormatInt(timestamp, 10),
|
||||||
|
}
|
||||||
|
if !isGroup {
|
||||||
|
cmd = append(cmd, recp)
|
||||||
|
} else {
|
||||||
|
cmd = append(cmd, []string{"-g", recp}...)
|
||||||
|
}
|
||||||
|
_, err = runSignalCli(true, cmd, "", s.signalCliMode)
|
||||||
|
}
|
||||||
|
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
func (s *SignalClient) SendStartTyping(number string, recipient string) error {
|
func (s *SignalClient) SendStartTyping(number string, recipient string) error {
|
||||||
var err error
|
var err error
|
||||||
recp := recipient
|
recp := recipient
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user