mirror of
https://github.com/bbernhard/signal-cli-rest-api.git
synced 2026-05-29 15:14:28 +00:00
Compare commits
3 Commits
c2a4c6967a
...
a4c854fd06
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
a4c854fd06 | ||
|
|
40232de0d0 | ||
|
|
252389efbe |
6
.github/workflows/ci.yml
vendored
6
.github/workflows/ci.yml
vendored
@ -13,9 +13,9 @@ jobs:
|
|||||||
runs-on: ubuntu-24.04
|
runs-on: ubuntu-24.04
|
||||||
steps:
|
steps:
|
||||||
- name: Set up QEMU
|
- name: Set up QEMU
|
||||||
uses: docker/setup-qemu-action@v3
|
uses: docker/setup-qemu-action@ce360397dd3f832beb865e1373c09c0e9f86d70a # v4.0.0
|
||||||
- name: Set up Docker Buildx
|
- name: Set up Docker Buildx
|
||||||
uses: docker/setup-buildx-action@v3
|
uses: docker/setup-buildx-action@4d04d5d9486b7bd6fa91e7baf45bbb4f8b9deedd # v4.0.0
|
||||||
- name: Available platforms
|
- name: Available platforms
|
||||||
run: echo ${{ steps.buildx.outputs.platforms }}
|
run: echo ${{ steps.buildx.outputs.platforms }}
|
||||||
- name: Install Podman
|
- name: Install Podman
|
||||||
@ -29,7 +29,7 @@ jobs:
|
|||||||
with:
|
with:
|
||||||
ref: ${{ github.ref }}
|
ref: ${{ github.ref }}
|
||||||
- name: Login to Docker Hub
|
- name: Login to Docker Hub
|
||||||
uses: docker/login-action@v1
|
uses: docker/login-action@4907a6ddec9925e35a0a9e82d7399ccc52663121 # v4.1.0
|
||||||
with:
|
with:
|
||||||
username: ${{ secrets.DOCKERHUB_USERNAME }}
|
username: ${{ secrets.DOCKERHUB_USERNAME }}
|
||||||
password: ${{ secrets.DOCKERHUB_TOKEN }}
|
password: ${{ secrets.DOCKERHUB_TOKEN }}
|
||||||
|
|||||||
6
.github/workflows/release-dev-version.yml
vendored
6
.github/workflows/release-dev-version.yml
vendored
@ -13,9 +13,9 @@ jobs:
|
|||||||
runs-on: ubuntu-24.04
|
runs-on: ubuntu-24.04
|
||||||
steps:
|
steps:
|
||||||
- name: Set up QEMU
|
- name: Set up QEMU
|
||||||
uses: docker/setup-qemu-action@v3
|
uses: docker/setup-qemu-action@ce360397dd3f832beb865e1373c09c0e9f86d70a # v4.0.0
|
||||||
- name: Set up Docker Buildx
|
- name: Set up Docker Buildx
|
||||||
uses: docker/setup-buildx-action@v3
|
uses: docker/setup-buildx-action@4d04d5d9486b7bd6fa91e7baf45bbb4f8b9deedd # v4.0.0
|
||||||
- name: Available platforms
|
- name: Available platforms
|
||||||
run: echo ${{ steps.buildx.outputs.platforms }}
|
run: echo ${{ steps.buildx.outputs.platforms }}
|
||||||
- name: Install Podman
|
- name: Install Podman
|
||||||
@ -28,7 +28,7 @@ jobs:
|
|||||||
with:
|
with:
|
||||||
ref: ${{ github.ref }}
|
ref: ${{ github.ref }}
|
||||||
- name: Login to Docker Hub
|
- name: Login to Docker Hub
|
||||||
uses: docker/login-action@v1
|
uses: docker/login-action@4907a6ddec9925e35a0a9e82d7399ccc52663121 # v4.1.0
|
||||||
with:
|
with:
|
||||||
username: ${{ secrets.DOCKERHUB_USERNAME }}
|
username: ${{ secrets.DOCKERHUB_USERNAME }}
|
||||||
password: ${{ secrets.DOCKERHUB_TOKEN }}
|
password: ${{ secrets.DOCKERHUB_TOKEN }}
|
||||||
|
|||||||
@ -13,9 +13,9 @@ jobs:
|
|||||||
runs-on: ubuntu-24.04
|
runs-on: ubuntu-24.04
|
||||||
steps:
|
steps:
|
||||||
- name: Set up QEMU
|
- name: Set up QEMU
|
||||||
uses: docker/setup-qemu-action@v3
|
uses: docker/setup-qemu-action@ce360397dd3f832beb865e1373c09c0e9f86d70a # v4.0.0
|
||||||
- name: Set up Docker Buildx
|
- name: Set up Docker Buildx
|
||||||
uses: docker/setup-buildx-action@v3
|
uses: docker/setup-buildx-action@4d04d5d9486b7bd6fa91e7baf45bbb4f8b9deedd # v4.0.0
|
||||||
- name: Available platforms
|
- name: Available platforms
|
||||||
run: echo ${{ steps.buildx.outputs.platforms }}
|
run: echo ${{ steps.buildx.outputs.platforms }}
|
||||||
- name: Install Podman
|
- name: Install Podman
|
||||||
@ -28,7 +28,7 @@ jobs:
|
|||||||
with:
|
with:
|
||||||
ref: ${{ github.ref }}
|
ref: ${{ github.ref }}
|
||||||
- name: Login to Docker Hub
|
- name: Login to Docker Hub
|
||||||
uses: docker/login-action@v1
|
uses: docker/login-action@4907a6ddec9925e35a0a9e82d7399ccc52663121 # v4.1.0
|
||||||
with:
|
with:
|
||||||
username: ${{ secrets.DOCKERHUB_USERNAME }}
|
username: ${{ secrets.DOCKERHUB_USERNAME }}
|
||||||
password: ${{ secrets.DOCKERHUB_TOKEN }}
|
password: ${{ secrets.DOCKERHUB_TOKEN }}
|
||||||
|
|||||||
@ -324,8 +324,14 @@ func (a *Api) RegisterNumber(c *gin.Context) {
|
|||||||
|
|
||||||
err = a.signalClient.RegisterNumber(number, req.UseVoice, req.Captcha)
|
err = a.signalClient.RegisterNumber(number, req.UseVoice, req.Captcha)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.JSON(400, gin.H{"error": err.Error()})
|
switch err.(type) {
|
||||||
|
case *client.InvalidTransportError:
|
||||||
|
c.JSON(400, Error{Msg: "Couldn't use SMS verification to register the specified number. Wait 60 seconds and try again with {\"use_voice\": true}"})
|
||||||
return
|
return
|
||||||
|
default:
|
||||||
|
c.JSON(400, Error{Msg: err.Error()})
|
||||||
|
return
|
||||||
|
}
|
||||||
}
|
}
|
||||||
c.Writer.WriteHeader(201)
|
c.Writer.WriteHeader(201)
|
||||||
}
|
}
|
||||||
|
|||||||
@ -749,6 +749,8 @@ func (s *SignalClient) About() About {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (s *SignalClient) RegisterNumber(number string, useVoice bool, captcha string) error {
|
func (s *SignalClient) RegisterNumber(number string, useVoice bool, captcha string) error {
|
||||||
|
var err error
|
||||||
|
var jsonRpc2Client *JsonRpc2Client
|
||||||
if s.signalCliMode == JsonRpc {
|
if s.signalCliMode == JsonRpc {
|
||||||
type Request struct {
|
type Request struct {
|
||||||
UseVoice bool `json:"voice,omitempty"`
|
UseVoice bool `json:"voice,omitempty"`
|
||||||
@ -765,12 +767,11 @@ func (s *SignalClient) RegisterNumber(number string, useVoice bool, captcha stri
|
|||||||
request.Captcha = captcha
|
request.Captcha = captcha
|
||||||
}
|
}
|
||||||
|
|
||||||
jsonRpc2Client, err := s.getJsonRpc2Client()
|
jsonRpc2Client, err = s.getJsonRpc2Client()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
_, err = jsonRpc2Client.getRaw("register", nil, request)
|
_, err = jsonRpc2Client.getRaw("register", nil, request)
|
||||||
return err
|
|
||||||
} else {
|
} else {
|
||||||
command := []string{"--config", s.signalCliConfig, "-a", number, "register"}
|
command := []string{"--config", s.signalCliConfig, "-a", number, "register"}
|
||||||
|
|
||||||
@ -782,9 +783,16 @@ func (s *SignalClient) RegisterNumber(number string, useVoice bool, captcha stri
|
|||||||
command = append(command, []string{"--captcha", captcha}...)
|
command = append(command, []string{"--captcha", captcha}...)
|
||||||
}
|
}
|
||||||
|
|
||||||
_, err := s.cliClient.Execute(true, command, "")
|
_, err = s.cliClient.Execute(true, command, "")
|
||||||
return err
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
if !useVoice && strings.Contains(err.Error(), "StatusCode: 400 (InvalidTransportModeException)") {
|
||||||
|
return &InvalidTransportError{Description: "Couldn't use SMS verification to register number."}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *SignalClient) UnregisterNumber(number string, deleteAccount bool, deleteLocalData bool) error {
|
func (s *SignalClient) UnregisterNumber(number string, deleteAccount bool, deleteLocalData bool) error {
|
||||||
|
|||||||
@ -23,3 +23,11 @@ type InternalError struct {
|
|||||||
func (e *InternalError) Error() string {
|
func (e *InternalError) Error() string {
|
||||||
return e.Description
|
return e.Description
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type InvalidTransportError struct {
|
||||||
|
Description string
|
||||||
|
}
|
||||||
|
|
||||||
|
func (e *InvalidTransportError) Error() string {
|
||||||
|
return e.Description
|
||||||
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user