added possibility to register number with voice

see #7
This commit is contained in:
Bernhard B
2020-01-19 18:20:33 +01:00
parent 8e449c5d68
commit 2c3f3a1c3d
2 changed files with 36 additions and 3 deletions

View File

@@ -37,7 +37,15 @@ Sample REST API calls:
```curl -X POST -H "Content-Type: application/json" 'http://127.0.0.1:8080/v1/register/+431212131491291'```
* Verify the number using the code received via SMS
* Register a number (with voice verification)
```curl -X POST -H "Content-Type: application/json" --data '{"use_voice": true}' 'http://127.0.0.1:8080/v1/register/<number>'```
e.g:
```curl -X POST -H "Content-Type: application/json" --data '{"use_voice": true}' 'http://127.0.0.1:8080/v1/register/+431212131491291'```
* Verify the number using the code received via SMS/voice
```curl -X POST -H "Content-Type: application/json" 'http://127.0.0.1:8080/v1/register/<number>/verify/<verification code>'```

View File

@@ -12,7 +12,7 @@ import (
"bytes"
"os"
"encoding/base64"
//"strings"
"encoding/json"
)
func runSignalCli(args []string) error {
@@ -55,12 +55,37 @@ func main() {
router.POST("/v1/register/:number", func(c *gin.Context) {
number := c.Param("number")
type Request struct{
UseVoice bool `json:"use_voice"`
}
var req Request
buf := new(bytes.Buffer)
buf.ReadFrom(c.Request.Body)
if buf.String() != "" {
err := json.Unmarshal(buf.Bytes(), &req)
if err != nil {
log.Error("Couldn't register number: ", err.Error())
c.JSON(400, "Couldn't process request - invalid request.")
return
}
} else {
req.UseVoice = false
}
if number == "" {
c.JSON(400, "Please provide a number")
return
}
err := runSignalCli([]string{"--config", *signalCliConfig, "-u", number, "register"})
command := []string{"--config", *signalCliConfig, "-u", number, "register"}
if req.UseVoice == true {
command = append(command, "--voice")
}
err := runSignalCli(command)
if err != nil {
c.JSON(400, err.Error())
return