mirror of
https://github.com/aljazceru/signal-cli-rest-api.git
synced 2025-12-19 15:44:28 +01:00
add stickers support in API and client
This commit is contained in:
@@ -6,6 +6,7 @@ import (
|
||||
"errors"
|
||||
"net/http"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/gabriel-vasile/mimetype"
|
||||
@@ -97,6 +98,7 @@ type SendMessageV2 struct {
|
||||
Recipients []string `json:"recipients"`
|
||||
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>"`
|
||||
Sticker string `json:"sticker"`
|
||||
Mentions []client.MessageMention `json:"mentions"`
|
||||
QuoteTimestamp *int64 `json:"quote_timestamp"`
|
||||
QuoteAuthor *string `json:"quote_author"`
|
||||
@@ -359,7 +361,13 @@ func (a *Api) SendV2(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
timestamps, err := a.signalClient.SendV2(req.Number, req.Message, req.Recipients, req.Base64Attachments,
|
||||
if req.Sticker != "" && !strings.Contains(req.Sticker, ":") {
|
||||
c.JSON(400, gin.H{"error": "Couldn't process request - please provide valid sticker delimiter"})
|
||||
return
|
||||
}
|
||||
|
||||
timestamps, err := a.signalClient.SendV2(
|
||||
req.Number, req.Message, req.Recipients, req.Base64Attachments, req.Sticker,
|
||||
req.Mentions, req.QuoteTimestamp, req.QuoteAuthor, req.QuoteMessage, req.QuoteMentions)
|
||||
if err != nil {
|
||||
c.JSON(400, Error{Msg: err.Error()})
|
||||
|
||||
@@ -294,7 +294,7 @@ func (s *MessageMention) toString() string {
|
||||
}
|
||||
|
||||
func (s *SignalClient) send(number string, message string,
|
||||
recipients []string, base64Attachments []string, isGroup bool, mentions []MessageMention,
|
||||
recipients []string, base64Attachments []string, isGroup bool, sticker string, mentions []MessageMention,
|
||||
quoteTimestamp *int64, quoteAuthor *string, quoteMessage *string, quoteMentions []MessageMention) (*SendResponse, error) {
|
||||
|
||||
var resp SendResponse
|
||||
@@ -340,6 +340,7 @@ func (s *SignalClient) send(number string, message string,
|
||||
Message string `json:"message"`
|
||||
GroupId string `json:"group-id,omitempty"`
|
||||
Attachments []string `json:"attachment,omitempty"`
|
||||
Sticker string `json:"sticker,omitempty"`
|
||||
Mentions []string `json:"mentions,omitempty"`
|
||||
QuoteTimestamp *int64 `json:"quote-timestamp,omitempty"`
|
||||
QuoteAuthor *string `json:"quote-author,omitempty"`
|
||||
@@ -356,6 +357,8 @@ func (s *SignalClient) send(number string, message string,
|
||||
for _, attachmentEntry := range attachmentEntries {
|
||||
request.Attachments = append(request.Attachments, attachmentEntry.toDataForSignal())
|
||||
}
|
||||
|
||||
request.Sticker = sticker
|
||||
if mentions != nil {
|
||||
request.Mentions = make([]string, len(mentions))
|
||||
for i, mention := range mentions {
|
||||
@@ -409,6 +412,11 @@ func (s *SignalClient) send(number string, message string,
|
||||
cmd = append(cmd, mention.toString())
|
||||
}
|
||||
|
||||
if sticker != "" {
|
||||
cmd = append(cmd, "--sticker")
|
||||
cmd = append(cmd, sticker)
|
||||
}
|
||||
|
||||
if quoteTimestamp != nil {
|
||||
cmd = append(cmd, "--quote-timestamp")
|
||||
cmd = append(cmd, strconv.FormatInt(*quoteTimestamp, 10))
|
||||
@@ -519,7 +527,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) {
|
||||
timestamp, err := s.send(number, message, recipients, base64Attachments, isGroup, nil, nil, nil, nil, nil)
|
||||
timestamp, err := s.send(number, message, recipients, base64Attachments, isGroup, "", nil, nil, nil, nil, nil)
|
||||
return timestamp, err
|
||||
}
|
||||
|
||||
@@ -538,7 +546,7 @@ func (s *SignalClient) getJsonRpc2Clients() []*JsonRpc2Client {
|
||||
return jsonRpc2Clients
|
||||
}
|
||||
|
||||
func (s *SignalClient) SendV2(number string, message string, recps []string, base64Attachments []string, mentions []MessageMention,
|
||||
func (s *SignalClient) SendV2(number string, message string, recps []string, base64Attachments []string, sticker string, mentions []MessageMention,
|
||||
quoteTimestamp *int64, quoteAuthor *string, quoteMessage *string, quoteMentions []MessageMention) (*[]SendResponse, error) {
|
||||
if len(recps) == 0 {
|
||||
return nil, errors.New("Please provide at least one recipient")
|
||||
@@ -569,7 +577,7 @@ func (s *SignalClient) SendV2(number string, message string, recps []string, bas
|
||||
|
||||
timestamps := []SendResponse{}
|
||||
for _, group := range groups {
|
||||
timestamp, err := s.send(number, message, []string{group}, base64Attachments, true, mentions, quoteTimestamp, quoteAuthor, quoteMessage, quoteMentions)
|
||||
timestamp, err := s.send(number, message, []string{group}, base64Attachments, true, sticker, mentions, quoteTimestamp, quoteAuthor, quoteMessage, quoteMentions)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -577,7 +585,7 @@ func (s *SignalClient) SendV2(number string, message string, recps []string, bas
|
||||
}
|
||||
|
||||
if len(recipients) > 0 {
|
||||
timestamp, err := s.send(number, message, recipients, base64Attachments, false, mentions, quoteTimestamp, quoteAuthor, quoteMessage, quoteMentions)
|
||||
timestamp, err := s.send(number, message, recipients, base64Attachments, false, sticker, mentions, quoteTimestamp, quoteAuthor, quoteMessage, quoteMentions)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user