return challenge tokens in send endpoint as explicit key

This commit is contained in:
Bernhard B
2024-03-25 15:59:41 +01:00
parent 8811842b91
commit de631edfb0
6 changed files with 77 additions and 10 deletions

View File

@@ -161,7 +161,8 @@ type SignalCliIdentityEntry struct {
}
type SendResponse struct {
Timestamp int64 `json:"timestamp"`
Timestamp int64 `json:"timestamp"`
ChallengeTokens []string `json:"challenge_tokens"`
}
type About struct {
@@ -459,6 +460,15 @@ func (s *SignalClient) send(number string, message string,
if strings.Contains(err.Error(), signalCliV2GroupError) {
return nil, errors.New("Cannot send message to group - please first update your profile.")
}
switch errorType := err.(type) {
case *RateLimitErrorType:
rateLimitError := errors.New(err.Error() + ". Use the attached challenge tokens to lift the rate limit restrictions via the '/v1/accounts/{number}/rate-limit-challenge' endpoint.")
resp.ChallengeTokens = errorType.ChallengeTokens
return &resp, rateLimitError
default:
return nil, err
}
return nil, err
}
} else {

View File

@@ -7,7 +7,6 @@ import (
"net"
"time"
"sync"
"strings"
"github.com/bbernhard/signal-cli-rest-api/utils"
uuid "github.com/gofrs/uuid"
@@ -45,6 +44,15 @@ type RateLimitResult struct {
Token string `json:"token"`
}
type RateLimitErrorType struct {
ChallengeTokens []string
Err error
}
func (r *RateLimitErrorType) Error() string {
return r.Err.Error()
}
type JsonRpc2Client struct {
conn net.Conn
receivedResponsesById map[string]chan JsonRpc2MessageResponse
@@ -151,7 +159,10 @@ func (r *JsonRpc2Client) getRaw(command string, account *string, args interface{
challengeTokens = append(challengeTokens, rateLimitResult.Token)
}
return "", errors.New(resp.Err.Message + " Challenge Tokens: " + strings.Join(challengeTokens, ","))
return "", &RateLimitErrorType{
ChallengeTokens: challengeTokens,
Err : errors.New(resp.Err.Message),
}
}
return "", errors.New(resp.Err.Message)
}