diff --git a/src/api/api.go b/src/api/api.go index fd999f4..4cb083c 100644 --- a/src/api/api.go +++ b/src/api/api.go @@ -162,6 +162,11 @@ type AddDeviceRequest struct { Uri string `json:"uri"` } +type RateLimitChallengeRequest struct { + ChallengeToken string `json:"challenge_token" example:""` + Captcha string `json:"captcha" example:"signalcaptcha://{captcha value}"` +} + type Api struct { signalClient *client.SignalClient } @@ -1677,3 +1682,35 @@ func (a *Api) SendContacts(c *gin.Context) { } c.Status(http.StatusNoContent) } + +// @Summary Lift rate limit restrictions by solving a captcha. +// @Tags Accounts +// @Description When running into rate limits, sometimes the limit can be lifted, by solving a CAPTCHA. To get the captcha token, go to https://signalcaptchas.org/challenge/generate.html For the staging environment, use: https://signalcaptchas.org/staging/registration/generate.html. The "challenge_token" is the token from the failed send attempt. The "captcha" is the captcha result, starting with signalcaptcha:// +// @Accept json +// @Produce json +// @Param number path string true "Registered Phone Number" +// @Param data body RateLimitChallengeRequest true "Request" +// @Success 204 +// @Failure 400 {object} Error +// @Router /v1/accounts/{number}/rate-limit-challenge [post] +func (a *Api) SubmitRateLimitChallenge(c *gin.Context) { + number := c.Param("number") + if number == "" { + c.JSON(400, Error{Msg: "Couldn't process request - number missing"}) + return + } + + var req RateLimitChallengeRequest + err := c.BindJSON(&req) + if err != nil { + c.JSON(400, Error{Msg: "Couldn't process request - invalid request"}) + return + } + + err = a.signalClient.SubmitRateLimitChallenge(number, req.ChallengeToken, req.Captcha) + if err != nil { + c.JSON(400, Error{Msg: err.Error()}) + return + } + c.Status(http.StatusNoContent) +} diff --git a/src/client/client.go b/src/client/client.go index 93b97be..e1879f2 100644 --- a/src/client/client.go +++ b/src/client/client.go @@ -1797,3 +1797,23 @@ func (s *SignalClient) GetTrustMode(number string) utils.SignalCliTrustMode { } return trustMode } + +func (s *SignalClient) SubmitRateLimitChallenge(number string, challengeToken string, captcha string) error { + if s.signalCliMode == JsonRpc { + type Request struct { + Challenge string `json:"challenge"` + Captcha string `json:"captcha"` + } + request := Request{Challenge: challengeToken, Captcha: captcha} + jsonRpc2Client, err := s.getJsonRpc2Client() + if err != nil { + return err + } + _, err = jsonRpc2Client.getRaw("submitRateLimitChallenge", &number, request) + return err + } else { + cmd := []string{"--config", s.signalCliConfig, "-a", number, "submitRateLimitChallenge", "--challenge", challengeToken, "--captcha", captcha} + _, err := s.cliClient.Execute(true, cmd, "") + return err + } +} diff --git a/src/docs/docs.go b/src/docs/docs.go index 5e4ad07..be34931 100644 --- a/src/docs/docs.go +++ b/src/docs/docs.go @@ -47,7 +47,7 @@ var doc = `{ }, "/v1/accounts": { "get": { - "description": "Lists all of the devices linked or registered", + "description": "Lists all of the accounts linked or registered", "produces": [ "application/json" ], @@ -74,6 +74,48 @@ var doc = `{ } } }, + "/v1/accounts/{number}/rate-limit-challenge": { + "post": { + "description": "When running into rate limits, sometimes the limit can be lifted, by solving a CAPTCHA. To get the captcha token, go to https://signalcaptchas.org/challenge/generate.html For the staging environment, use: https://signalcaptchas.org/staging/registration/generate.html. The \"challenge_token\" is the token from the failed send attempt. The \"captcha\" is the captcha result, starting with signalcaptcha://", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "Accounts" + ], + "summary": "Lift rate limit restrictions by solving a captcha.", + "parameters": [ + { + "type": "string", + "description": "Registered Phone Number", + "name": "number", + "in": "path", + "required": true + }, + { + "description": "Request", + "name": "data", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/api.RateLimitChallengeRequest" + } + } + ], + "responses": { + "204": {}, + "400": { + "description": "Bad Request", + "schema": { + "$ref": "#/definitions/api.Error" + } + } + } + } + }, "/v1/attachments": { "get": { "description": "List all downloaded attachments", @@ -1779,6 +1821,19 @@ var doc = `{ } } }, + "api.RateLimitChallengeRequest": { + "type": "object", + "properties": { + "captcha": { + "type": "string", + "example": "signalcaptcha://{captcha value}" + }, + "challenge_token": { + "type": "string", + "example": "\u003cchallenge token\u003e" + } + } + }, "api.Reaction": { "type": "object", "properties": { diff --git a/src/docs/swagger.json b/src/docs/swagger.json index 1ddaa32..ef70bea 100644 --- a/src/docs/swagger.json +++ b/src/docs/swagger.json @@ -31,7 +31,7 @@ }, "/v1/accounts": { "get": { - "description": "Lists all of the devices linked or registered", + "description": "Lists all of the accounts linked or registered", "produces": [ "application/json" ], @@ -58,6 +58,48 @@ } } }, + "/v1/accounts/{number}/rate-limit-challenge": { + "post": { + "description": "When running into rate limits, sometimes the limit can be lifted, by solving a CAPTCHA. To get the captcha token, go to https://signalcaptchas.org/challenge/generate.html For the staging environment, use: https://signalcaptchas.org/staging/registration/generate.html. The \"challenge_token\" is the token from the failed send attempt. The \"captcha\" is the captcha result, starting with signalcaptcha://", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "Accounts" + ], + "summary": "Lift rate limit restrictions by solving a captcha.", + "parameters": [ + { + "type": "string", + "description": "Registered Phone Number", + "name": "number", + "in": "path", + "required": true + }, + { + "description": "Request", + "name": "data", + "in": "body", + "required": true, + "schema": { + "$ref": "#/definitions/api.RateLimitChallengeRequest" + } + } + ], + "responses": { + "204": {}, + "400": { + "description": "Bad Request", + "schema": { + "$ref": "#/definitions/api.Error" + } + } + } + } + }, "/v1/attachments": { "get": { "description": "List all downloaded attachments", @@ -1763,6 +1805,19 @@ } } }, + "api.RateLimitChallengeRequest": { + "type": "object", + "properties": { + "captcha": { + "type": "string", + "example": "signalcaptcha://{captcha value}" + }, + "challenge_token": { + "type": "string", + "example": "\u003cchallenge token\u003e" + } + } + }, "api.Reaction": { "type": "object", "properties": { diff --git a/src/docs/swagger.yaml b/src/docs/swagger.yaml index b3f233e..f07b55a 100644 --- a/src/docs/swagger.yaml +++ b/src/docs/swagger.yaml @@ -73,6 +73,15 @@ definitions: Level: type: string type: object + api.RateLimitChallengeRequest: + properties: + captcha: + example: signalcaptcha://{captcha value} + type: string + challenge_token: + example: + type: string + type: object api.Reaction: properties: reaction: @@ -313,7 +322,7 @@ paths: - General /v1/accounts: get: - description: Lists all of the devices linked or registered + description: Lists all of the accounts linked or registered produces: - application/json responses: @@ -330,6 +339,34 @@ paths: summary: List all accounts tags: - Accounts + /v1/accounts/{number}/rate-limit-challenge: + post: + consumes: + - application/json + description: 'When running into rate limits, sometimes the limit can be lifted, by solving a CAPTCHA. To get the captcha token, go to https://signalcaptchas.org/challenge/generate.html For the staging environment, use: https://signalcaptchas.org/staging/registration/generate.html. The "challenge_token" is the token from the failed send attempt. The "captcha" is the captcha result, starting with signalcaptcha://' + parameters: + - description: Registered Phone Number + in: path + name: number + required: true + type: string + - description: Request + in: body + name: data + required: true + schema: + $ref: '#/definitions/api.RateLimitChallengeRequest' + produces: + - application/json + responses: + "204": {} + "400": + description: Bad Request + schema: + $ref: '#/definitions/api.Error' + summary: Lift rate limit restrictions by solving a captcha. + tags: + - Accounts /v1/attachments: get: description: List all downloaded attachments diff --git a/src/main.go b/src/main.go index 996fa85..6b05887 100644 --- a/src/main.go +++ b/src/main.go @@ -204,6 +204,7 @@ func main() { accounts := v1.Group("accounts") { accounts.GET("", api.GetAccounts) + accounts.POST(":number/rate-limit-challenge", api.SubmitRateLimitChallenge) } devices := v1.Group("devices")