From 2d58f22c95c86e22a988493daac15284b50183ce Mon Sep 17 00:00:00 2001 From: Bernhard B Date: Thu, 30 Jan 2025 21:31:04 +0100 Subject: [PATCH] added possibility to specify HTTP callback in qrcodelink endpoint * with the 'callback_url' parameter it is possible to specify a HTTP endpoint, which gets called after the linking was successful. In the payload, the number which was registered is returned. This only works in the json-rpc mode. --- src/api/api.go | 7 ++++++- src/client/client.go | 11 ++++++++++- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/src/api/api.go b/src/api/api.go index 6914c1e..6ee6648 100644 --- a/src/api/api.go +++ b/src/api/api.go @@ -1007,6 +1007,11 @@ func (a *Api) DeleteGroup(c *gin.Context) { func (a *Api) GetQrCodeLink(c *gin.Context) { deviceName := c.Query("device_name") qrCodeVersion := c.Query("qrcode_version") + callbackUrl, err := url.PathUnescape(c.Query("callback_url")) + if err != nil { + c.JSON(400, Error{Msg: "Couldn't process request - invalid callback"}) + return + } if deviceName == "" { c.JSON(400, Error{Msg: "Please provide a name for the device"}) @@ -1023,7 +1028,7 @@ func (a *Api) GetQrCodeLink(c *gin.Context) { } } - png, err := a.signalClient.GetQrCodeLink(deviceName, qrCodeVersionInt) + png, err := a.signalClient.GetQrCodeLink(deviceName, qrCodeVersionInt, callbackUrl) if err != nil { c.JSON(400, Error{Msg: err.Error()}) return diff --git a/src/client/client.go b/src/client/client.go index e8111b2..f58cbe0 100644 --- a/src/client/client.go +++ b/src/client/client.go @@ -11,6 +11,8 @@ import ( "path/filepath" "strconv" "strings" + "net/http" + "bytes" securejoin "github.com/cyphar/filepath-securejoin" "github.com/h2non/filetype" @@ -1212,7 +1214,7 @@ func (s *SignalClient) DeleteGroup(number string, groupId string) error { } } -func (s *SignalClient) GetQrCodeLink(deviceName string, qrCodeVersion int) ([]byte, error) { +func (s *SignalClient) GetQrCodeLink(deviceName string, qrCodeVersion int, callbackUrl string) ([]byte, error) { if s.signalCliMode == JsonRpc { jsonRpc2Client, err := s.getJsonRpc2Client() if err != nil { @@ -1264,6 +1266,13 @@ func (s *SignalClient) GetQrCodeLink(deviceName string, qrCodeVersion int) ([]by } log.Debug("Linking device result: ", result) s.signalCliApiConfig.Load(s.signalCliApiConfigPath) + + if callbackUrl != "" { + _, err = http.Post(callbackUrl, "application/json", bytes.NewBuffer([]byte(result))) + if err != nil { + log.Error(err) + } + } })() return png, nil