added voice_note parameter to send endpoint

This commit is contained in:
DorskFR 2026-09-07 09:14:44 +09:00 committed by NanachiBot
parent 1fface6074
commit 93b366cad6
No known key found for this signature in database
GPG Key ID: B0C27D990208C793
5 changed files with 27 additions and 5 deletions

View File

@ -142,6 +142,7 @@ type SendMessageV2 struct {
NotifySelf *bool `json:"notify_self,omitempty"`
LinkPreview *ds.LinkPreviewType `json:"link_preview,omitempty"`
ViewOnce *bool `json:"view_once,omitempty"`
VoiceNote *bool `json:"voice_note,omitempty"`
}
type TypingIndicatorRequest struct {
@ -546,10 +547,15 @@ func (a *Api) SendV2(c *gin.Context) {
return
}
if req.VoiceNote != nil && *req.VoiceNote && (len(req.Base64Attachments) == 0) {
c.JSON(400, Error{Msg: "'voice_note' can only be set for audio attachments!"})
return
}
data, err := a.signalClient.SendV2(
req.Number, req.Message, req.Recipients, req.Base64Attachments, req.Sticker,
req.Mentions, req.QuoteTimestamp, req.QuoteAuthor, req.QuoteMessage, req.QuoteMentions,
textMode, req.EditTimestamp, req.NotifySelf, req.LinkPreview, req.ViewOnce)
textMode, req.EditTimestamp, req.NotifySelf, req.LinkPreview, req.ViewOnce, req.VoiceNote)
if err != nil {
switch err.(type) {
case *client.RateLimitErrorType:

View File

@ -550,6 +550,7 @@ func (s *SignalClient) send(signalCliSendRequest ds.SignalCliSendRequest) (*ds.S
PreviewImage *string `json:"preview-image,omitempty"`
PreviewDescription *string `json:"preview-description,omitempty"`
ViewOnce bool `json:"view-once,omitempty"`
VoiceNote bool `json:"voice-note,omitempty"`
}
request := Request{Message: signalCliSendRequest.Message}
@ -573,6 +574,10 @@ func (s *SignalClient) send(signalCliSendRequest ds.SignalCliSendRequest) (*ds.S
request.ViewOnce = true
}
if signalCliSendRequest.VoiceNote != nil && *signalCliSendRequest.VoiceNote {
request.VoiceNote = true
}
request.Sticker = signalCliSendRequest.Sticker
if signalCliSendRequest.Mentions != nil {
request.Mentions = make([]string, len(signalCliSendRequest.Mentions))
@ -709,6 +714,10 @@ func (s *SignalClient) send(signalCliSendRequest ds.SignalCliSendRequest) (*ds.S
cmd = append(cmd, "--view-once")
}
if signalCliSendRequest.VoiceNote != nil && *signalCliSendRequest.VoiceNote {
cmd = append(cmd, "--voice-note")
}
rawData, err = s.cliClient.Execute(true, cmd, signalCliSendRequest.Message)
if err != nil {
cleanupAttachmentEntries(attachmentEntries, linkPreviewAttachmentEntry)
@ -946,7 +955,7 @@ func (s *SignalClient) getJsonRpc2Clients() []*JsonRpc2Client {
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, notifySelf *bool,
linkPreview *ds.LinkPreviewType, viewOnce *bool) (*[]ds.SendMessageResponse, error) {
linkPreview *ds.LinkPreviewType, viewOnce *bool, voiceNote *bool) (*[]ds.SendMessageResponse, error) {
if len(recps) == 0 {
return nil, errors.New("Please provide at least one recipient")
}
@ -997,7 +1006,7 @@ func (s *SignalClient) SendV2(number string, message string, recps []string, bas
signalCliSendRequest := ds.SignalCliSendRequest{Number: number, Message: message, Recipients: []string{group}, Base64Attachments: base64Attachments,
RecipientType: ds.Group, Sticker: sticker, Mentions: mentions, QuoteTimestamp: quoteTimestamp,
QuoteAuthor: quoteAuthor, QuoteMessage: quoteMessage, QuoteMentions: quoteMentions,
TextMode: textMode, EditTimestamp: editTimestamp, NotifySelf: notifySelf, LinkPreview: linkPreview, ViewOnce: viewOnce}
TextMode: textMode, EditTimestamp: editTimestamp, NotifySelf: notifySelf, LinkPreview: linkPreview, ViewOnce: viewOnce, VoiceNote: voiceNote}
resp, err := s.send(signalCliSendRequest)
if err != nil {
return nil, err
@ -1009,7 +1018,7 @@ func (s *SignalClient) SendV2(number string, message string, recps []string, bas
signalCliSendRequest := ds.SignalCliSendRequest{Number: number, Message: message, Recipients: numbers, Base64Attachments: base64Attachments,
RecipientType: ds.Number, Sticker: sticker, Mentions: mentions, QuoteTimestamp: quoteTimestamp,
QuoteAuthor: quoteAuthor, QuoteMessage: quoteMessage, QuoteMentions: quoteMentions,
TextMode: textMode, EditTimestamp: editTimestamp, NotifySelf: notifySelf, LinkPreview: linkPreview, ViewOnce: viewOnce}
TextMode: textMode, EditTimestamp: editTimestamp, NotifySelf: notifySelf, LinkPreview: linkPreview, ViewOnce: viewOnce, VoiceNote: voiceNote}
resp, err := s.send(signalCliSendRequest)
if err != nil {
return nil, err
@ -1021,7 +1030,7 @@ func (s *SignalClient) SendV2(number string, message string, recps []string, bas
signalCliSendRequest := ds.SignalCliSendRequest{Number: number, Message: message, Recipients: usernames, Base64Attachments: base64Attachments,
RecipientType: ds.Username, Sticker: sticker, Mentions: mentions, QuoteTimestamp: quoteTimestamp,
QuoteAuthor: quoteAuthor, QuoteMessage: quoteMessage, QuoteMentions: quoteMentions,
TextMode: textMode, EditTimestamp: editTimestamp, NotifySelf: notifySelf, LinkPreview: linkPreview, ViewOnce: viewOnce}
TextMode: textMode, EditTimestamp: editTimestamp, NotifySelf: notifySelf, LinkPreview: linkPreview, ViewOnce: viewOnce, VoiceNote: voiceNote}
resp, err := s.send(signalCliSendRequest)
if err != nil {
return nil, err

View File

@ -51,6 +51,7 @@ type SignalCliSendRequest struct {
NotifySelf *bool
LinkPreview *LinkPreviewType
ViewOnce *bool
VoiceNote *bool
}
type GroupPermissions struct {

View File

@ -468,6 +468,9 @@ const docTemplate = `{
},
"view_once": {
"type": "boolean"
},
"voice_note": {
"type": "boolean"
}
},
"required": [

View File

@ -463,6 +463,9 @@
},
"view_once": {
"type": "boolean"
},
"voice_note": {
"type": "boolean"
}
},
"required": [