mirror of
https://github.com/aljazceru/signal-cli-rest-api.git
synced 2025-12-19 15:44:28 +01:00
Add endpoint support for read receipts.
This commit is contained in:
@@ -91,6 +91,12 @@ type Reaction struct {
|
|||||||
Timestamp int64 `json:"timestamp"`
|
Timestamp int64 `json:"timestamp"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type Receipt struct {
|
||||||
|
Recipient string `json:"recipient"`
|
||||||
|
ReceiptType string `json:"receipt_type" enums:"read,viewed"`
|
||||||
|
Timestamp int64 `json:"timestamp"`
|
||||||
|
}
|
||||||
|
|
||||||
type SendMessageV1 struct {
|
type SendMessageV1 struct {
|
||||||
Number string `json:"number"`
|
Number string `json:"number"`
|
||||||
Recipients []string `json:"recipients"`
|
Recipients []string `json:"recipients"`
|
||||||
@@ -1472,6 +1478,51 @@ func (a *Api) RemoveReaction(c *gin.Context) {
|
|||||||
c.Status(http.StatusNoContent)
|
c.Status(http.StatusNoContent)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// @Summary Send a receipt.
|
||||||
|
// @Tags Receipts
|
||||||
|
// @Description Send a read or viewed receipt
|
||||||
|
// @Accept json
|
||||||
|
// @Produce json
|
||||||
|
// @Success 204 {string} OK
|
||||||
|
// @Failure 400 {object} Error
|
||||||
|
// @Param data body Receipt true "Receipt"
|
||||||
|
// @Router /v1/receipts/{number} [post]
|
||||||
|
func (a *Api) SendReceipt(c *gin.Context) {
|
||||||
|
var req Receipt
|
||||||
|
err := c.BindJSON(&req)
|
||||||
|
if err != nil {
|
||||||
|
c.JSON(400, Error{Msg: "Couldn't process request - invalid request"})
|
||||||
|
log.Error(err.Error())
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
number := c.Param("number")
|
||||||
|
|
||||||
|
if req.Recipient == "" {
|
||||||
|
c.JSON(400, Error{Msg: "Couldn't process request - recipient missing"})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// if req.ReceiptType != "viewed" && req.ReceiptType != "read" {
|
||||||
|
if !utils.StringInSlice(req.ReceiptType, []string{"read", "viewed"}) {
|
||||||
|
c.JSON(400, Error{Msg: "Couldn't process request - receipt type must be read or viewed"})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if req.Timestamp == 0 {
|
||||||
|
c.JSON(400, Error{Msg: "Couldn't process request - timestamp missing"})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
err = a.signalClient.SendReceipt(number, req.Recipient, req.ReceiptType, req.Timestamp)
|
||||||
|
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.
|
||||||
@@ -1883,7 +1934,7 @@ func (a *Api) ListInstalledStickerPacks(c *gin.Context) {
|
|||||||
|
|
||||||
// @Summary Add Sticker Pack.
|
// @Summary Add Sticker Pack.
|
||||||
// @Tags Sticker Packs
|
// @Tags Sticker Packs
|
||||||
// @Description In order to add a sticker pack, browse to https://signalstickers.org/ and select the sticker pack you want to add. Then, press the "Add to Signal" button. If you look at the address bar in your browser you should see an URL in this format: https://signal.art/addstickers/#pack_id=XXX&pack_key=YYY, where XXX is the pack_id and YYY is the pack_key.
|
// @Description In order to add a sticker pack, browse to https://signalstickers.org/ and select the sticker pack you want to add. Then, press the "Add to Signal" button. If you look at the address bar in your browser you should see an URL in this format: https://signal.art/addstickers/#pack_id=XXX&pack_key=YYY, where XXX is the pack_id and YYY is the pack_key.
|
||||||
// @Accept json
|
// @Accept json
|
||||||
// @Produce json
|
// @Produce json
|
||||||
// @Param number path string true "Registered Phone Number"
|
// @Param number path string true "Registered Phone Number"
|
||||||
|
|||||||
@@ -1637,6 +1637,44 @@ func (s *SignalClient) SendReaction(number string, recipient string, emoji strin
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
func (s *SignalClient) SendReceipt(number string, recipient string, receipt_type string, timestamp int64) error {
|
||||||
|
// see https://github.com/AsamK/signal-cli/blob/master/man/signal-cli.1.adoc#sendreceipt
|
||||||
|
var err error
|
||||||
|
recp := recipient
|
||||||
|
|
||||||
|
if s.signalCliMode == JsonRpc {
|
||||||
|
type Request struct {
|
||||||
|
Recipient string `json:"recipient,omitempty"`
|
||||||
|
ReceiptType string `json:"receipt-type"`
|
||||||
|
Timestamp int64 `json:"target-timestamp"`
|
||||||
|
}
|
||||||
|
request := Request{}
|
||||||
|
request.Recipient = recp
|
||||||
|
request.ReceiptType = receipt_type
|
||||||
|
request.Timestamp = timestamp
|
||||||
|
|
||||||
|
jsonRpc2Client, err := s.getJsonRpc2Client()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
_, err = jsonRpc2Client.getRaw("sendReceipt", &number, request)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
cmd := []string{
|
||||||
|
"--config", s.signalCliConfig,
|
||||||
|
"-a", number,
|
||||||
|
"sendReceipt",
|
||||||
|
recp,
|
||||||
|
}
|
||||||
|
|
||||||
|
cmd = append(cmd, []string{"-t", strconv.FormatInt(timestamp, 10)}...)
|
||||||
|
|
||||||
|
_, err = s.cliClient.Execute(true, cmd, "")
|
||||||
|
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
|
||||||
|
|||||||
@@ -49,6 +49,9 @@ import (
|
|||||||
// @tag.name Reactions
|
// @tag.name Reactions
|
||||||
// @tag.description React to messages.
|
// @tag.description React to messages.
|
||||||
|
|
||||||
|
// @tag.name Receipts
|
||||||
|
// @tag.description Send receipts for messages.
|
||||||
|
|
||||||
// @tag.name Search
|
// @tag.name Search
|
||||||
// @tag.description Search the Signal Service.
|
// @tag.description Search the Signal Service.
|
||||||
|
|
||||||
@@ -254,6 +257,11 @@ func main() {
|
|||||||
reactions.DELETE(":number", api.RemoveReaction)
|
reactions.DELETE(":number", api.RemoveReaction)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
receipts := v1.Group("/receipts")
|
||||||
|
{
|
||||||
|
receipts.POST(":number", api.SendReceipt)
|
||||||
|
}
|
||||||
|
|
||||||
search := v1.Group("/search")
|
search := v1.Group("/search")
|
||||||
{
|
{
|
||||||
search.GET("", api.SearchForNumbers)
|
search.GET("", api.SearchForNumbers)
|
||||||
|
|||||||
Reference in New Issue
Block a user