mirror of
https://github.com/aljazceru/signal-cli-rest-api.git
synced 2025-12-19 15:44:28 +01:00
Accept max_messages param
This commit is contained in:
@@ -473,6 +473,7 @@ func StringToBool(input string) bool {
|
|||||||
// @Param timeout query string false "Receive timeout in seconds (default: 1)"
|
// @Param timeout query string false "Receive timeout in seconds (default: 1)"
|
||||||
// @Param ignore_attachments query string false "Specify whether the attachments of the received message should be ignored" (default: false)"
|
// @Param ignore_attachments query string false "Specify whether the attachments of the received message should be ignored" (default: false)"
|
||||||
// @Param ignore_stories query string false "Specify whether stories should be ignored when receiving messages" (default: false)"
|
// @Param ignore_stories query string false "Specify whether stories should be ignored when receiving messages" (default: false)"
|
||||||
|
// @Param max_messages query string false "Specify the maximum number of messages to receive (default: unlimited)". Not available in json-rpc mode.
|
||||||
// @Router /v1/receive/{number} [get]
|
// @Router /v1/receive/{number} [get]
|
||||||
func (a *Api) Receive(c *gin.Context) {
|
func (a *Api) Receive(c *gin.Context) {
|
||||||
number := c.Param("number")
|
number := c.Param("number")
|
||||||
@@ -496,19 +497,26 @@ func (a *Api) Receive(c *gin.Context) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
maxMessages := c.DefaultQuery("max_messages", "0")
|
||||||
|
maxMessagesInt, err := strconv.ParseInt(maxMessages, 10, 32)
|
||||||
|
if err != nil {
|
||||||
|
c.JSON(400, Error{Msg: "Couldn't process request - max_messages needs to be numeric!"})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
ignoreAttachments := c.DefaultQuery("ignore_attachments", "false")
|
ignoreAttachments := c.DefaultQuery("ignore_attachments", "false")
|
||||||
if ignoreAttachments != "true" && ignoreAttachments != "false" {
|
if ignoreAttachments != "true" && ignoreAttachments != "false" {
|
||||||
c.JSON(400, Error {Msg: "Couldn't process request - ignore_attachments parameter needs to be either 'true' or 'false'"})
|
c.JSON(400, Error{Msg: "Couldn't process request - ignore_attachments parameter needs to be either 'true' or 'false'"})
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
ignoreStories := c.DefaultQuery("ignore_stories", "false")
|
ignoreStories := c.DefaultQuery("ignore_stories", "false")
|
||||||
if ignoreStories != "true" && ignoreStories != "false" {
|
if ignoreStories != "true" && ignoreStories != "false" {
|
||||||
c.JSON(400, Error {Msg: "Couldn't process request - ignore_stories parameter needs to be either 'true' or 'false'"})
|
c.JSON(400, Error{Msg: "Couldn't process request - ignore_stories parameter needs to be either 'true' or 'false'"})
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
jsonStr, err := a.signalClient.Receive(number, timeoutInt, StringToBool(ignoreAttachments), StringToBool(ignoreStories))
|
jsonStr, err := a.signalClient.Receive(number, timeoutInt, StringToBool(ignoreAttachments), StringToBool(ignoreStories), maxMessagesInt)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.JSON(400, Error{Msg: err.Error()})
|
c.JSON(400, Error{Msg: err.Error()})
|
||||||
return
|
return
|
||||||
|
|||||||
@@ -474,12 +474,12 @@ func (s *SignalClient) send(number string, message string,
|
|||||||
|
|
||||||
func (s *SignalClient) About() About {
|
func (s *SignalClient) About() About {
|
||||||
about := About{
|
about := About{
|
||||||
SupportedApiVersions: []string{"v1", "v2"},
|
SupportedApiVersions: []string{"v1", "v2"},
|
||||||
BuildNr: 2,
|
BuildNr: 2,
|
||||||
Mode: getSignalCliModeString(s.signalCliMode),
|
Mode: getSignalCliModeString(s.signalCliMode),
|
||||||
Version: utils.GetEnv("BUILD_VERSION", "unset"),
|
Version: utils.GetEnv("BUILD_VERSION", "unset"),
|
||||||
Capabilities: map[string][]string{"v2/send": []string{"quotes", "mentions"}},
|
Capabilities: map[string][]string{"v2/send": []string{"quotes", "mentions"}},
|
||||||
}
|
}
|
||||||
return about
|
return about
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -610,7 +610,7 @@ func (s *SignalClient) SendV2(number string, message string, recps []string, bas
|
|||||||
return ×tamps, nil
|
return ×tamps, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *SignalClient) Receive(number string, timeout int64, ignoreAttachments bool, ignoreStories bool) (string, error) {
|
func (s *SignalClient) Receive(number string, timeout int64, ignoreAttachments bool, ignoreStories bool, maxMessages int64) (string, error) {
|
||||||
if s.signalCliMode == JsonRpc {
|
if s.signalCliMode == JsonRpc {
|
||||||
return "", errors.New("Not implemented")
|
return "", errors.New("Not implemented")
|
||||||
} else {
|
} else {
|
||||||
@@ -624,6 +624,11 @@ func (s *SignalClient) Receive(number string, timeout int64, ignoreAttachments b
|
|||||||
command = append(command, "--ignore-stories")
|
command = append(command, "--ignore-stories")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if maxMessages > 0 {
|
||||||
|
command = append(command, "--max-messages")
|
||||||
|
command = append(command, strconv.FormatInt(maxMessages, 10))
|
||||||
|
}
|
||||||
|
|
||||||
out, err := s.cliClient.Execute(true, command, "")
|
out, err := s.cliClient.Execute(true, command, "")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
|
|||||||
Reference in New Issue
Block a user