diff --git a/README.md b/README.md index e1c030d..7e6d749 100644 --- a/README.md +++ b/README.md @@ -2,17 +2,15 @@ This project creates a small dockerized REST API around [signal-cli](https://github.com/AsamK/signal-cli). +At the moment, the following functionality is exposed via REST: -At the moment, the following functionality is exposed via REST: +- Register a number +- Verify the number using the code received via SMS +- Send message (+ attachment) to multiple recipients -* Register a number -* Verify the number using the code received via SMS -* Send message (+ attachment) to multiple recipients +## Examples - -## Examples - -Sample `docker-compose.yml`file: +Sample `docker-compose.yml`file: ``` version: "3" @@ -29,115 +27,104 @@ services: Sample REST API calls: -* Register a number (with SMS verification) +- Register a number (with SMS verification) -```curl -X POST -H "Content-Type: application/json" 'http://127.0.0.1:8080/v1/register/'``` +`curl -X POST -H "Content-Type: application/json" 'http://127.0.0.1:8080/v1/register/'` - e.g: - - ```curl -X POST -H "Content-Type: application/json" 'http://127.0.0.1:8080/v1/register/+431212131491291'``` +e.g: -* Register a number (with voice verification) +`curl -X POST -H "Content-Type: application/json" 'http://127.0.0.1:8080/v1/register/+431212131491291'` -```curl -X POST -H "Content-Type: application/json" --data '{"use_voice": true}' 'http://127.0.0.1:8080/v1/register/'``` +- Register a number (with voice verification) - e.g: - - ```curl -X POST -H "Content-Type: application/json" --data '{"use_voice": true}' 'http://127.0.0.1:8080/v1/register/+431212131491291'``` +`curl -X POST -H "Content-Type: application/json" --data '{"use_voice": true}' 'http://127.0.0.1:8080/v1/register/'` -* Verify the number using the code received via SMS/voice +e.g: - ```curl -X POST -H "Content-Type: application/json" 'http://127.0.0.1:8080/v1/register//verify/'``` +`curl -X POST -H "Content-Type: application/json" --data '{"use_voice": true}' 'http://127.0.0.1:8080/v1/register/+431212131491291'` - e.g: - - ```curl -X POST -H "Content-Type: application/json" 'http://127.0.0.1:8080/v1/register/+431212131491291/verify/123-456'``` +- Verify the number using the code received via SMS/voice -* Send a message to multiple recipients + `curl -X POST -H "Content-Type: application/json" 'http://127.0.0.1:8080/v1/register//verify/'` - ```curl -X POST -H "Content-Type: application/json" -d '{"message": "", "number": "", "recipients": ["", ""]}' 'http://127.0.0.1:8080/v2/send'``` + e.g: - e.g: + `curl -X POST -H "Content-Type: application/json" 'http://127.0.0.1:8080/v1/register/+431212131491291/verify/123-456'` - ```curl -X POST -H "Content-Type: application/json" -d '{"message": "Hello World!", "number": "+431212131491291", "recipients": ["+4354546464654", "+4912812812121"]}' 'http://127.0.0.1:8080/v2/send'``` +- Send a message to multiple recipients -* Send a message (+ base64 encoded attachment) to multiple recipients + `curl -X POST -H "Content-Type: application/json" -d '{"message": "", "number": "", "recipients": ["", ""]}' 'http://127.0.0.1:8080/v2/send'` - ```curl -X POST -H "Content-Type: application/json" -d '{"message": "", "base64_attachments": [""], "number": "", "recipients": ["", ""]}' 'http://127.0.0.1:8080/v2/send'``` + e.g: -* Send a message to a group + `curl -X POST -H "Content-Type: application/json" -d '{"message": "Hello World!", "number": "+431212131491291", "recipients": ["+4354546464654", "+4912812812121"]}' 'http://127.0.0.1:8080/v2/send'` -The group id can be obtained via the "List groups" REST call. +- Send a message (+ base64 encoded attachment) to multiple recipients - ```curl -X POST -H "Content-Type: application/json" -d '{"message": "", "number": "", "recipients": [""]}' 'http://127.0.0.1:8080/v2/send'``` + `curl -X POST -H "Content-Type: application/json" -d '{"message": "", "base64_attachments": [""], "number": "", "recipients": ["", ""]}' 'http://127.0.0.1:8080/v2/send'` - e.g: +- Send a message to a group - ```curl -X POST -H "Content-Type: application/json" -d '{"message": "Hello World!", "number": "+431212131491291", "recipients": ["group.ckRzaEd4VmRzNnJaASAEsasa", "+4912812812121"]}' 'http://127.0.0.1:8080/v2/send'``` + The group id can be obtained via the "List groups" REST call. -* Receive messages + `curl -X POST -H "Content-Type: application/json" -d '{"message": "", "number": "", "recipients": [""]}' 'http://127.0.0.1:8080/v2/send'` + + e.g: + + `curl -X POST -H "Content-Type: application/json" -d '{"message": "Hello World!", "number": "+431212131491291", "recipients": ["group.ckRzaEd4VmRzNnJaASAEsasa", "+4912812812121"]}' 'http://127.0.0.1:8080/v2/send'` + +- Receive messages Fetch all new messages in the inbox of the specified number. - ```curl -X GET -H "Content-Type: application/json" 'http://127.0.0.1:8080/v1/receive/'``` - - e.g: - - ```curl -X GET -H "Content-Type: application/json" 'http://127.0.0.1:8080/v1/receive/+431212131491291'``` - -* Create a new group - - Create a new group with the specified name and members. - - ```curl -X POST -H "Content-Type: application/json" -d '{"name": "", "members": ["", ""]}' 'http://127.0.0.1:8080/v1/groups/'``` + `curl -X GET -H "Content-Type: application/json" 'http://127.0.0.1:8080/v1/receive/'` e.g: - ```curl -X POST -H "Content-Type: application/json" -d '{"name": "my group", "members": ["+4354546464654", "+4912812812121"]}' 'http://127.0.0.1:8080/v1/groups/+431212131491291'``` + `curl -X GET -H "Content-Type: application/json" 'http://127.0.0.1:8080/v1/receive/+431212131491291'` -* List groups +- Create a new group - ```curl -X GET -H "Content-Type: application/json" 'http://127.0.0.1:8080/v1/groups/'``` + Create a new group with the specified name and members. + + `curl -X POST -H "Content-Type: application/json" -d '{"name": "", "members": ["", ""]}' 'http://127.0.0.1:8080/v1/groups/'` e.g: - ```curl -X GET -H "Content-Type: application/json" 'http://127.0.0.1:8080/v1/groups/+431212131491291'``` + `curl -X POST -H "Content-Type: application/json" -d '{"name": "my group", "members": ["+4354546464654", "+4912812812121"]}' 'http://127.0.0.1:8080/v1/groups/+431212131491291'` -* Delete a group +- List groups - Delete the group with the given group id. The group id can be obtained via the "List groups" REST call. - - ```curl -X DELETE -H "Content-Type: application/json" 'http://127.0.0.1:8080/v1/groups//'``` - - e.g: - - ```curl -X DELETE -H "Content-Type: application/json" 'http://127.0.0.1:8080/v1/groups/+431212131491291/ckRzaEd4VmRzNnJaASAEsasa'``` - - -* Link a device - - ```curl -X POST -H "Content-Type: application/json" 'http://127.0.0.1:8080/v1/link/'``` + `curl -X GET -H "Content-Type: application/json" 'http://127.0.0.1:8080/v1/groups/'` e.g: - - ```curl -X POST -H "Content-Type: application/json" 'http://127.0.0.1:8080/v1/link/HomeAssistant'``` - This provides a tsdevice link which have to be converted to a QR-Code. For this the endpoint /v1/qrcode/ ca be used. + `curl -X GET -H "Content-Type: application/json" 'http://127.0.0.1:8080/v1/groups/+431212131491291'` +- Delete a group -* Get QR Code + Delete the group with the given group id. The group id can be obtained via the "List groups" REST call. - ```curl -X POST -H "Content-Type: application/json" 'http://127.0.0.1:8080/v1/qrcode/'``` + `curl -X DELETE -H "Content-Type: application/json" 'http://127.0.0.1:8080/v1/groups//'` e.g: - - ```curl -X POST -H "Content-Type: application/json" 'http://127.0.0.1:8080/v1/qrcode/tsdevice:?uuid=ZiVIV..'``` + + `curl -X DELETE -H "Content-Type: application/json" 'http://127.0.0.1:8080/v1/groups/+431212131491291/ckRzaEd4VmRzNnJaASAEsasa'` + +- Link a device + + `curl -X POST -H "Content-Type: application/json" 'http://127.0.0.1:8080/v1/qrcodelink?'` + + e.g: + + `curl -X POST -H "Content-Type: application/json" 'http://127.0.0.1:8080/v1/qrcodelink?HomeAssistant'` This provides a QR-Code image. In case of an error a JSON object will be returned. + Due to security reason of Signal, the provided QR-Code will change with each request. The following REST API endpoints are **deprecated and no longer maintained!** -```/v1/send``` +`/v1/send` In case you need more functionality, please **file a ticket** or **create a PR** diff --git a/src/main.go b/src/main.go index 0c8c19a..9ddd4b9 100644 --- a/src/main.go +++ b/src/main.go @@ -257,23 +257,6 @@ func main() { c.JSON(200, about) }) - router.POST("/v1/link/:device_name", func(c *gin.Context) { - deviceName := c.Param("device_name") - if deviceName == "" { - c.JSON(400, gin.H{"error": "Please provide a name for the device"}) - return - } - - command := []string{"--config", *signalCliConfig, "link", "-n", deviceName} - - out, err := runSignalCli(false, command) - if err != nil { - c.JSON(400, gin.H{"error": err.Error()}) - return - } - c.JSON(200, gin.H{"uri": string(out)}) - }) - router.POST("/v1/register/:number", func(c *gin.Context) { number := c.Param("number") @@ -498,10 +481,23 @@ func main() { } }) - router.GET("/v1/qrcode/:tsdevice_link", func(c *gin.Context) { - deviceLink := c.Param("tsdevice_link") + router.GET("/v1/qrcodelink", func(c *gin.Context) { + deviceName := c.Query("device_name") - q, err := qrcode.New(deviceLink, qrcode.Medium) + if deviceName == "" { + c.JSON(400, gin.H{"error": "Please provide a name for the device"}) + return + } + + command := []string{"--config", *signalCliConfig, "link", "-n", deviceName} + + tsdeviceLink, err := runSignalCli(false, command) + if err != nil { + c.JSON(400, gin.H{"error": err.Error()}) + return + } + + q, err := qrcode.New(string(tsdeviceLink), qrcode.Medium) if err != nil { c.JSON(400, gin.H{"error": err.Error()}) }