mirror of
https://github.com/aljazceru/signal-cli-rest-api.git
synced 2025-12-20 16:14:29 +01:00
Merge pull request #573 from ahatius/master
Add support to disable notify-self flag on /v2/send endpoint
This commit is contained in:
@@ -7,8 +7,8 @@ import (
|
|||||||
"net/http"
|
"net/http"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
|
||||||
"sync"
|
"sync"
|
||||||
|
"time"
|
||||||
|
|
||||||
"github.com/gabriel-vasile/mimetype"
|
"github.com/gabriel-vasile/mimetype"
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
@@ -121,6 +121,7 @@ type SendMessageV2 struct {
|
|||||||
QuoteMentions []ds.MessageMention `json:"quote_mentions"`
|
QuoteMentions []ds.MessageMention `json:"quote_mentions"`
|
||||||
TextMode *string `json:"text_mode" enums:"normal,styled"`
|
TextMode *string `json:"text_mode" enums:"normal,styled"`
|
||||||
EditTimestamp *int64 `json:"edit_timestamp"`
|
EditTimestamp *int64 `json:"edit_timestamp"`
|
||||||
|
NotifySelf *bool `json:"notify_self"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type TypingIndicatorRequest struct {
|
type TypingIndicatorRequest struct {
|
||||||
@@ -199,7 +200,7 @@ type AddStickerPackRequest struct {
|
|||||||
|
|
||||||
type Api struct {
|
type Api struct {
|
||||||
signalClient *client.SignalClient
|
signalClient *client.SignalClient
|
||||||
wsMutex sync.Mutex
|
wsMutex sync.Mutex
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewApi(signalClient *client.SignalClient) *Api {
|
func NewApi(signalClient *client.SignalClient) *Api {
|
||||||
@@ -418,7 +419,8 @@ func (a *Api) SendV2(c *gin.Context) {
|
|||||||
|
|
||||||
data, err := a.signalClient.SendV2(
|
data, err := a.signalClient.SendV2(
|
||||||
req.Number, req.Message, req.Recipients, req.Base64Attachments, req.Sticker,
|
req.Number, req.Message, req.Recipients, req.Base64Attachments, req.Sticker,
|
||||||
req.Mentions, req.QuoteTimestamp, req.QuoteAuthor, req.QuoteMessage, req.QuoteMentions, req.TextMode, req.EditTimestamp)
|
req.Mentions, req.QuoteTimestamp, req.QuoteAuthor, req.QuoteMessage, req.QuoteMentions,
|
||||||
|
req.TextMode, req.EditTimestamp, req.NotifySelf)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
switch err.(type) {
|
switch err.(type) {
|
||||||
case *client.RateLimitErrorType:
|
case *client.RateLimitErrorType:
|
||||||
|
|||||||
@@ -562,7 +562,10 @@ func (s *SignalClient) send(signalCliSendRequest ds.SignalCliSendRequest) (*Send
|
|||||||
cmd = append(cmd, strconv.FormatInt(*signalCliSendRequest.EditTimestamp, 10))
|
cmd = append(cmd, strconv.FormatInt(*signalCliSendRequest.EditTimestamp, 10))
|
||||||
}
|
}
|
||||||
|
|
||||||
cmd = append(cmd, "--notify-self")
|
// for backwards compatibility, if nothing is set, use the notify-self flag
|
||||||
|
if signalCliSendRequest.NotifySelf == nil || *signalCliSendRequest.NotifySelf {
|
||||||
|
cmd = append(cmd, "--notify-self")
|
||||||
|
}
|
||||||
|
|
||||||
rawData, err := s.cliClient.Execute(true, cmd, signalCliSendRequest.Message)
|
rawData, err := s.cliClient.Execute(true, cmd, signalCliSendRequest.Message)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -719,7 +722,7 @@ func (s *SignalClient) getJsonRpc2Clients() []*JsonRpc2Client {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (s *SignalClient) SendV2(number string, message string, recps []string, base64Attachments []string, sticker string, mentions []ds.MessageMention,
|
func (s *SignalClient) SendV2(number string, message string, recps []string, base64Attachments []string, sticker string, mentions []ds.MessageMention,
|
||||||
quoteTimestamp *int64, quoteAuthor *string, quoteMessage *string, quoteMentions []ds.MessageMention, textMode *string, editTimestamp *int64) (*[]SendResponse, error) {
|
quoteTimestamp *int64, quoteAuthor *string, quoteMessage *string, quoteMentions []ds.MessageMention, textMode *string, editTimestamp *int64, notifySelf *bool) (*[]SendResponse, error) {
|
||||||
if len(recps) == 0 {
|
if len(recps) == 0 {
|
||||||
return nil, errors.New("Please provide at least one recipient")
|
return nil, errors.New("Please provide at least one recipient")
|
||||||
}
|
}
|
||||||
@@ -770,7 +773,7 @@ func (s *SignalClient) SendV2(number string, message string, recps []string, bas
|
|||||||
signalCliSendRequest := ds.SignalCliSendRequest{Number: number, Message: message, Recipients: []string{group}, Base64Attachments: base64Attachments,
|
signalCliSendRequest := ds.SignalCliSendRequest{Number: number, Message: message, Recipients: []string{group}, Base64Attachments: base64Attachments,
|
||||||
RecipientType: ds.Group, Sticker: sticker, Mentions: mentions, QuoteTimestamp: quoteTimestamp,
|
RecipientType: ds.Group, Sticker: sticker, Mentions: mentions, QuoteTimestamp: quoteTimestamp,
|
||||||
QuoteAuthor: quoteAuthor, QuoteMessage: quoteMessage, QuoteMentions: quoteMentions,
|
QuoteAuthor: quoteAuthor, QuoteMessage: quoteMessage, QuoteMentions: quoteMentions,
|
||||||
TextMode: textMode, EditTimestamp: editTimestamp}
|
TextMode: textMode, EditTimestamp: editTimestamp, NotifySelf: notifySelf}
|
||||||
timestamp, err := s.send(signalCliSendRequest)
|
timestamp, err := s.send(signalCliSendRequest)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
|||||||
@@ -41,4 +41,5 @@ type SignalCliSendRequest struct {
|
|||||||
QuoteMentions []MessageMention
|
QuoteMentions []MessageMention
|
||||||
TextMode *string
|
TextMode *string
|
||||||
EditTimestamp *int64
|
EditTimestamp *int64
|
||||||
|
NotifySelf *bool
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2282,6 +2282,9 @@ var doc = `{
|
|||||||
"normal",
|
"normal",
|
||||||
"styled"
|
"styled"
|
||||||
]
|
]
|
||||||
|
},
|
||||||
|
"notify_self": {
|
||||||
|
"type": "boolean"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -2266,6 +2266,9 @@
|
|||||||
"normal",
|
"normal",
|
||||||
"styled"
|
"styled"
|
||||||
]
|
]
|
||||||
|
},
|
||||||
|
"notify_self": {
|
||||||
|
"type": "boolean"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -195,6 +195,8 @@ definitions:
|
|||||||
- normal
|
- normal
|
||||||
- styled
|
- styled
|
||||||
type: string
|
type: string
|
||||||
|
notify_self:
|
||||||
|
type: boolean
|
||||||
type: object
|
type: object
|
||||||
api.SetUsernameRequest:
|
api.SetUsernameRequest:
|
||||||
properties:
|
properties:
|
||||||
|
|||||||
Reference in New Issue
Block a user