mirror of
https://github.com/aljazceru/signal-cli-rest-api.git
synced 2025-12-19 15:44:28 +01:00
Added support for missing send arguments:
- Mentions - Quote timestamp - Quote author - Quote message - Quote mentions
This commit is contained in:
@@ -97,6 +97,11 @@ type SendMessageV2 struct {
|
|||||||
Recipients []string `json:"recipients"`
|
Recipients []string `json:"recipients"`
|
||||||
Message string `json:"message"`
|
Message string `json:"message"`
|
||||||
Base64Attachments []string `json:"base64_attachments" example:"<BASE64 ENCODED DATA>,data:<MIME-TYPE>;base64<comma><BASE64 ENCODED DATA>,data:<MIME-TYPE>;filename=<FILENAME>;base64<comma><BASE64 ENCODED DATA>"`
|
Base64Attachments []string `json:"base64_attachments" example:"<BASE64 ENCODED DATA>,data:<MIME-TYPE>;base64<comma><BASE64 ENCODED DATA>,data:<MIME-TYPE>;filename=<FILENAME>;base64<comma><BASE64 ENCODED DATA>"`
|
||||||
|
Mentions []string `json:"mentions"`
|
||||||
|
QuoteTimestamp *int64 `json:"quote_timestamp"`
|
||||||
|
QuoteAuthor *string `json:"quote_author"`
|
||||||
|
QuoteMessage *string `json:"quote_message"`
|
||||||
|
QuoteMentions []string `json:"quote_mentions"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type TypingIndicatorRequest struct {
|
type TypingIndicatorRequest struct {
|
||||||
@@ -354,7 +359,8 @@ func (a *Api) SendV2(c *gin.Context) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
timestamps, err := a.signalClient.SendV2(req.Number, req.Message, req.Recipients, req.Base64Attachments)
|
timestamps, err := a.signalClient.SendV2(req.Number, req.Message, req.Recipients, req.Base64Attachments,
|
||||||
|
req.Mentions, req.QuoteTimestamp, req.QuoteAuthor, req.QuoteMessage, req.QuoteMentions)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.JSON(400, Error{Msg: err.Error()})
|
c.JSON(400, Error{Msg: err.Error()})
|
||||||
return
|
return
|
||||||
|
|||||||
@@ -120,6 +120,7 @@ type About struct {
|
|||||||
BuildNr int `json:"build"`
|
BuildNr int `json:"build"`
|
||||||
Mode string `json:"mode"`
|
Mode string `json:"mode"`
|
||||||
Version string `json:"version"`
|
Version string `json:"version"`
|
||||||
|
Capabilities map[string][]string `json:"capabilities"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type SearchResultEntry struct {
|
type SearchResultEntry struct {
|
||||||
@@ -283,7 +284,8 @@ func (s *SignalClient) Init() error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (s *SignalClient) send(number string, message string,
|
func (s *SignalClient) send(number string, message string,
|
||||||
recipients []string, base64Attachments []string, isGroup bool) (*SendResponse, error) {
|
recipients []string, base64Attachments []string, isGroup bool, mentions []string,
|
||||||
|
quote_timestamp *int64, quote_author *string, quote_message *string, quote_mentions []string) (*SendResponse, error) {
|
||||||
|
|
||||||
var resp SendResponse
|
var resp SendResponse
|
||||||
|
|
||||||
@@ -324,10 +326,15 @@ func (s *SignalClient) send(number string, message string,
|
|||||||
}
|
}
|
||||||
|
|
||||||
type Request struct {
|
type Request struct {
|
||||||
Recipients []string `json:"recipient,omitempty"`
|
Recipients []string `json:"recipient,omitempty"`
|
||||||
Message string `json:"message"`
|
Message string `json:"message"`
|
||||||
GroupId string `json:"group-id,omitempty"`
|
GroupId string `json:"group-id,omitempty"`
|
||||||
Attachments []string `json:"attachment,omitempty"`
|
Attachments []string `json:"attachment,omitempty"`
|
||||||
|
Mentions []string `json:"mentions,omitempty"`
|
||||||
|
QuoteTimestamp *int64 `json:"quote-timestamp,omitempty"`
|
||||||
|
QuoteAuthor *string `json:"quote-author,omitempty"`
|
||||||
|
QuoteMessage *string `json:"quote-message,omitempty"`
|
||||||
|
QuoteMentions []string `json:"quote-mentions,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
request := Request{Message: message}
|
request := Request{Message: message}
|
||||||
@@ -339,6 +346,11 @@ func (s *SignalClient) send(number string, message string,
|
|||||||
for _, attachmentEntry := range attachmentEntries {
|
for _, attachmentEntry := range attachmentEntries {
|
||||||
request.Attachments = append(request.Attachments, attachmentEntry.toDataForSignal())
|
request.Attachments = append(request.Attachments, attachmentEntry.toDataForSignal())
|
||||||
}
|
}
|
||||||
|
request.Mentions = mentions
|
||||||
|
request.QuoteTimestamp = quote_timestamp
|
||||||
|
request.QuoteAuthor = quote_author
|
||||||
|
request.QuoteMessage = quote_message
|
||||||
|
request.QuoteMentions = quote_mentions
|
||||||
|
|
||||||
rawData, err := jsonRpc2Client.getRaw("send", request)
|
rawData, err := jsonRpc2Client.getRaw("send", request)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -368,6 +380,31 @@ func (s *SignalClient) send(number string, message string,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for _, mention := range mentions {
|
||||||
|
cmd = append(cmd, "--mention")
|
||||||
|
cmd = append(cmd, mention)
|
||||||
|
}
|
||||||
|
|
||||||
|
if quote_timestamp != nil {
|
||||||
|
cmd = append(cmd, "--quote-timestamp")
|
||||||
|
cmd = append(cmd, strconv.FormatInt(*quote_timestamp, 10))
|
||||||
|
}
|
||||||
|
|
||||||
|
if quote_author != nil {
|
||||||
|
cmd = append(cmd, "--quote-author")
|
||||||
|
cmd = append(cmd, *quote_author)
|
||||||
|
}
|
||||||
|
|
||||||
|
if quote_message != nil {
|
||||||
|
cmd = append(cmd, "--quote-message")
|
||||||
|
cmd = append(cmd, *quote_message)
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, mention := range quote_mentions {
|
||||||
|
cmd = append(cmd, "--quote-mention")
|
||||||
|
cmd = append(cmd, mention)
|
||||||
|
}
|
||||||
|
|
||||||
rawData, err := s.cliClient.Execute(true, cmd, message)
|
rawData, err := s.cliClient.Execute(true, cmd, message)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
cleanupAttachmentEntries(attachmentEntries)
|
cleanupAttachmentEntries(attachmentEntries)
|
||||||
@@ -389,8 +426,13 @@ func (s *SignalClient) send(number string, message string,
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (s *SignalClient) About() About {
|
func (s *SignalClient) About() About {
|
||||||
about := About{SupportedApiVersions: []string{"v1", "v2"}, BuildNr: 2, Mode: getSignalCliModeString(s.signalCliMode),
|
about := About{
|
||||||
Version: utils.GetEnv("BUILD_VERSION", "unset")}
|
SupportedApiVersions: []string{"v1", "v2"},
|
||||||
|
BuildNr: 2,
|
||||||
|
Mode: getSignalCliModeString(s.signalCliMode),
|
||||||
|
Version: utils.GetEnv("BUILD_VERSION", "unset"),
|
||||||
|
Capabilities: map[string][]string{"v2/send": []string{"quotes", "mentions"}},
|
||||||
|
}
|
||||||
return about
|
return about
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -453,7 +495,7 @@ func (s *SignalClient) VerifyRegisteredNumber(number string, token string, pin s
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (s *SignalClient) SendV1(number string, message string, recipients []string, base64Attachments []string, isGroup bool) (*SendResponse, error) {
|
func (s *SignalClient) SendV1(number string, message string, recipients []string, base64Attachments []string, isGroup bool) (*SendResponse, error) {
|
||||||
timestamp, err := s.send(number, message, recipients, base64Attachments, isGroup)
|
timestamp, err := s.send(number, message, recipients, base64Attachments, isGroup, []string{}, nil, nil, nil, []string{})
|
||||||
return timestamp, err
|
return timestamp, err
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -472,7 +514,8 @@ func (s *SignalClient) getJsonRpc2Clients() []*JsonRpc2Client {
|
|||||||
return jsonRpc2Clients
|
return jsonRpc2Clients
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *SignalClient) SendV2(number string, message string, recps []string, base64Attachments []string) (*[]SendResponse, error) {
|
func (s *SignalClient) SendV2(number string, message string, recps []string, base64Attachments []string, mentions []string,
|
||||||
|
quote_timestamp *int64, quote_author *string, quote_message *string, quote_mentions []string) (*[]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")
|
||||||
}
|
}
|
||||||
@@ -502,7 +545,7 @@ func (s *SignalClient) SendV2(number string, message string, recps []string, bas
|
|||||||
|
|
||||||
timestamps := []SendResponse{}
|
timestamps := []SendResponse{}
|
||||||
for _, group := range groups {
|
for _, group := range groups {
|
||||||
timestamp, err := s.send(number, message, []string{group}, base64Attachments, true)
|
timestamp, err := s.send(number, message, []string{group}, base64Attachments, true, mentions, quote_timestamp, quote_author, quote_message, quote_mentions)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@@ -510,7 +553,7 @@ func (s *SignalClient) SendV2(number string, message string, recps []string, bas
|
|||||||
}
|
}
|
||||||
|
|
||||||
if len(recipients) > 0 {
|
if len(recipients) > 0 {
|
||||||
timestamp, err := s.send(number, message, recipients, base64Attachments, false)
|
timestamp, err := s.send(number, message, recipients, base64Attachments, false, mentions, quote_timestamp, quote_author, quote_message, quote_mentions)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user