mirror of
https://github.com/aljazceru/signal-cli-rest-api.git
synced 2026-01-17 22:04:33 +01:00
return challenge tokens in send endpoint as explicit key
This commit is contained in:
@@ -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 {
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user