mirror of
https://github.com/aljazceru/signal-cli-rest-api.git
synced 2025-12-19 15:44:28 +01:00
Added nested object for mentions (direct and quote)
This commit is contained in:
@@ -93,15 +93,15 @@ type SendMessageV1 struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type SendMessageV2 struct {
|
type SendMessageV2 struct {
|
||||||
Number string `json:"number"`
|
Number string `json:"number"`
|
||||||
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"`
|
Mentions []client.MessageMention `json:"mentions"`
|
||||||
QuoteTimestamp *int64 `json:"quote_timestamp"`
|
QuoteTimestamp *int64 `json:"quote_timestamp"`
|
||||||
QuoteAuthor *string `json:"quote_author"`
|
QuoteAuthor *string `json:"quote_author"`
|
||||||
QuoteMessage *string `json:"quote_message"`
|
QuoteMessage *string `json:"quote_message"`
|
||||||
QuoteMentions []string `json:"quote_mentions"`
|
QuoteMentions []client.MessageMention `json:"quote_mentions"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type TypingIndicatorRequest struct {
|
type TypingIndicatorRequest struct {
|
||||||
|
|||||||
@@ -59,6 +59,12 @@ func (g GroupLinkState) String() string {
|
|||||||
return []string{"", "enabled", "enabled-with-approval", "disabled"}[g]
|
return []string{"", "enabled", "enabled-with-approval", "disabled"}[g]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type MessageMention struct {
|
||||||
|
Start int64 `json:"start"`
|
||||||
|
Length int64 `json:"length"`
|
||||||
|
Author string `json:"author"`
|
||||||
|
}
|
||||||
|
|
||||||
type GroupEntry struct {
|
type GroupEntry struct {
|
||||||
Name string `json:"name"`
|
Name string `json:"name"`
|
||||||
Id string `json:"id"`
|
Id string `json:"id"`
|
||||||
@@ -283,9 +289,13 @@ func (s *SignalClient) Init() error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (s *MessageMention) toString() string {
|
||||||
|
return fmt.Sprintf("%d:%d:%s", s.Start, s.Length, s.Author)
|
||||||
|
}
|
||||||
|
|
||||||
func (s *SignalClient) send(number string, message string,
|
func (s *SignalClient) send(number string, message string,
|
||||||
recipients []string, base64Attachments []string, isGroup bool, mentions []string,
|
recipients []string, base64Attachments []string, isGroup bool, mentions []MessageMention,
|
||||||
quote_timestamp *int64, quote_author *string, quote_message *string, quote_mentions []string) (*SendResponse, error) {
|
quote_timestamp *int64, quote_author *string, quote_message *string, quote_mentions []MessageMention) (*SendResponse, error) {
|
||||||
|
|
||||||
var resp SendResponse
|
var resp SendResponse
|
||||||
|
|
||||||
@@ -346,11 +356,25 @@ 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
|
if mentions != nil {
|
||||||
|
request.Mentions = make([]string, len(mentions))
|
||||||
|
for i, mention := range mentions {
|
||||||
|
request.Mentions[i] = mention.toString()
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
request.Mentions = nil
|
||||||
|
}
|
||||||
request.QuoteTimestamp = quote_timestamp
|
request.QuoteTimestamp = quote_timestamp
|
||||||
request.QuoteAuthor = quote_author
|
request.QuoteAuthor = quote_author
|
||||||
request.QuoteMessage = quote_message
|
request.QuoteMessage = quote_message
|
||||||
request.QuoteMentions = quote_mentions
|
if quote_mentions != nil {
|
||||||
|
request.QuoteMentions = make([]string, len(quote_mentions))
|
||||||
|
for i, mention := range quote_mentions {
|
||||||
|
request.QuoteMentions[i] = mention.toString()
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
request.QuoteMentions = nil
|
||||||
|
}
|
||||||
|
|
||||||
rawData, err := jsonRpc2Client.getRaw("send", request)
|
rawData, err := jsonRpc2Client.getRaw("send", request)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -382,7 +406,7 @@ func (s *SignalClient) send(number string, message string,
|
|||||||
|
|
||||||
for _, mention := range mentions {
|
for _, mention := range mentions {
|
||||||
cmd = append(cmd, "--mention")
|
cmd = append(cmd, "--mention")
|
||||||
cmd = append(cmd, mention)
|
cmd = append(cmd, mention.toString())
|
||||||
}
|
}
|
||||||
|
|
||||||
if quote_timestamp != nil {
|
if quote_timestamp != nil {
|
||||||
@@ -402,7 +426,7 @@ func (s *SignalClient) send(number string, message string,
|
|||||||
|
|
||||||
for _, mention := range quote_mentions {
|
for _, mention := range quote_mentions {
|
||||||
cmd = append(cmd, "--quote-mention")
|
cmd = append(cmd, "--quote-mention")
|
||||||
cmd = append(cmd, mention)
|
cmd = append(cmd, mention.toString())
|
||||||
}
|
}
|
||||||
|
|
||||||
rawData, err := s.cliClient.Execute(true, cmd, message)
|
rawData, err := s.cliClient.Execute(true, cmd, message)
|
||||||
@@ -495,7 +519,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, []string{}, nil, nil, nil, []string{})
|
timestamp, err := s.send(number, message, recipients, base64Attachments, isGroup, nil, nil, nil, nil, nil)
|
||||||
return timestamp, err
|
return timestamp, err
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -514,8 +538,8 @@ func (s *SignalClient) getJsonRpc2Clients() []*JsonRpc2Client {
|
|||||||
return jsonRpc2Clients
|
return jsonRpc2Clients
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *SignalClient) SendV2(number string, message string, recps []string, base64Attachments []string, mentions []string,
|
func (s *SignalClient) SendV2(number string, message string, recps []string, base64Attachments []string, mentions []MessageMention,
|
||||||
quote_timestamp *int64, quote_author *string, quote_message *string, quote_mentions []string) (*[]SendResponse, error) {
|
quote_timestamp *int64, quote_author *string, quote_message *string, quote_mentions []MessageMention) (*[]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")
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user