mirror of
https://github.com/aljazceru/signal-cli-rest-api.git
synced 2025-12-19 15:44:28 +01:00
Merge branch 'bbernhard:master' into patch-1
This commit is contained in:
@@ -540,6 +540,7 @@ func StringToBool(input string) bool {
|
|||||||
// @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.
|
// @Param max_messages query string false "Specify the maximum number of messages to receive (default: unlimited)". Not available in json-rpc mode.
|
||||||
|
// @Param send_read_receipts query string false "Specify whether read receipts should be sent when receiving messages" (default: false)"
|
||||||
// @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")
|
||||||
@@ -582,7 +583,13 @@ func (a *Api) Receive(c *gin.Context) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
jsonStr, err := a.signalClient.Receive(number, timeoutInt, StringToBool(ignoreAttachments), StringToBool(ignoreStories), maxMessagesInt)
|
sendReadReceipts := c.DefaultQuery("send_read_receipts", "false")
|
||||||
|
if sendReadReceipts != "true" && sendReadReceipts != "false" {
|
||||||
|
c.JSON(400, Error{Msg: "Couldn't process request - send_read_receipts parameter needs to be either 'true' or 'false'"})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
jsonStr, err := a.signalClient.Receive(number, timeoutInt, StringToBool(ignoreAttachments), StringToBool(ignoreStories), maxMessagesInt, StringToBool(sendReadReceipts))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.JSON(400, Error{Msg: err.Error()})
|
c.JSON(400, Error{Msg: err.Error()})
|
||||||
return
|
return
|
||||||
|
|||||||
@@ -720,7 +720,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, maxMessages int64) (string, error) {
|
func (s *SignalClient) Receive(number string, timeout int64, ignoreAttachments bool, ignoreStories bool, maxMessages int64, sendReadReceipts bool) (string, error) {
|
||||||
if s.signalCliMode == JsonRpc {
|
if s.signalCliMode == JsonRpc {
|
||||||
return "", errors.New("Not implemented")
|
return "", errors.New("Not implemented")
|
||||||
} else {
|
} else {
|
||||||
@@ -739,6 +739,10 @@ func (s *SignalClient) Receive(number string, timeout int64, ignoreAttachments b
|
|||||||
command = append(command, strconv.FormatInt(maxMessages, 10))
|
command = append(command, strconv.FormatInt(maxMessages, 10))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if sendReadReceipts {
|
||||||
|
command = append(command, "--send-read-receipts")
|
||||||
|
}
|
||||||
|
|
||||||
out, err := s.cliClient.Execute(true, command, "")
|
out, err := s.cliClient.Execute(true, command, "")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
|
|||||||
@@ -1449,6 +1449,12 @@ var doc = `{
|
|||||||
"description": "Specify the maximum number of messages to receive (default: unlimited)",
|
"description": "Specify the maximum number of messages to receive (default: unlimited)",
|
||||||
"name": "max_messages",
|
"name": "max_messages",
|
||||||
"in": "query"
|
"in": "query"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "string",
|
||||||
|
"description": "Specify whether read receipts should be sent when receiving messages",
|
||||||
|
"name": "send_read_receipts",
|
||||||
|
"in": "query"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"responses": {
|
"responses": {
|
||||||
|
|||||||
@@ -1433,6 +1433,12 @@
|
|||||||
"description": "Specify the maximum number of messages to receive (default: unlimited)",
|
"description": "Specify the maximum number of messages to receive (default: unlimited)",
|
||||||
"name": "max_messages",
|
"name": "max_messages",
|
||||||
"in": "query"
|
"in": "query"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "string",
|
||||||
|
"description": "Specify whether read receipts should be sent when receiving messages",
|
||||||
|
"name": "send_read_receipts",
|
||||||
|
"in": "query"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"responses": {
|
"responses": {
|
||||||
|
|||||||
@@ -1303,6 +1303,10 @@ paths:
|
|||||||
in: query
|
in: query
|
||||||
name: max_messages
|
name: max_messages
|
||||||
type: string
|
type: string
|
||||||
|
- description: Specify whether read receipts should be sent when receiving messages
|
||||||
|
in: query
|
||||||
|
name: send_read_receipts
|
||||||
|
type: string
|
||||||
produces:
|
produces:
|
||||||
- application/json
|
- application/json
|
||||||
responses:
|
responses:
|
||||||
|
|||||||
@@ -297,6 +297,7 @@ func main() {
|
|||||||
autoReceiveScheduleReceiveTimeout := utils.GetEnv("AUTO_RECEIVE_SCHEDULE_RECEIVE_TIMEOUT", "10")
|
autoReceiveScheduleReceiveTimeout := utils.GetEnv("AUTO_RECEIVE_SCHEDULE_RECEIVE_TIMEOUT", "10")
|
||||||
autoReceiveScheduleIgnoreAttachments := utils.GetEnv("AUTO_RECEIVE_SCHEDULE_IGNORE_ATTACHMENTS", "false")
|
autoReceiveScheduleIgnoreAttachments := utils.GetEnv("AUTO_RECEIVE_SCHEDULE_IGNORE_ATTACHMENTS", "false")
|
||||||
autoReceiveScheduleIgnoreStories := utils.GetEnv("AUTO_RECEIVE_SCHEDULE_IGNORE_STORIES", "false")
|
autoReceiveScheduleIgnoreStories := utils.GetEnv("AUTO_RECEIVE_SCHEDULE_IGNORE_STORIES", "false")
|
||||||
|
autoReceiveScheduleSendReadReceipts := utils.GetEnv("AUTO_RECEIVE_SCHEDULE_SEND_READ_RECEIPTS", "false")
|
||||||
|
|
||||||
c := cron.New()
|
c := cron.New()
|
||||||
c.Schedule(schedule, cron.FuncJob(func() {
|
c.Schedule(schedule, cron.FuncJob(func() {
|
||||||
@@ -325,6 +326,7 @@ func main() {
|
|||||||
q.Add("timeout", autoReceiveScheduleReceiveTimeout)
|
q.Add("timeout", autoReceiveScheduleReceiveTimeout)
|
||||||
q.Add("ignore_attachments", autoReceiveScheduleIgnoreAttachments)
|
q.Add("ignore_attachments", autoReceiveScheduleIgnoreAttachments)
|
||||||
q.Add("ignore_stories", autoReceiveScheduleIgnoreStories)
|
q.Add("ignore_stories", autoReceiveScheduleIgnoreStories)
|
||||||
|
q.Add("send_read_receipts", autoReceiveScheduleSendReadReceipts)
|
||||||
req.URL.RawQuery = q.Encode()
|
req.URL.RawQuery = q.Encode()
|
||||||
|
|
||||||
resp, err := client.Do(req)
|
resp, err := client.Do(req)
|
||||||
|
|||||||
Reference in New Issue
Block a user