mirror of
https://github.com/aljazceru/signal-cli-rest-api.git
synced 2025-12-19 07:34:23 +01:00
@@ -1623,3 +1623,27 @@ func (a *Api) GetTrustMode(c *gin.Context) {
|
||||
|
||||
c.JSON(200, trustMode)
|
||||
}
|
||||
|
||||
// @Summary Send a synchronization message with the local contacts list to all linked devices.
|
||||
// @Tags Contacts
|
||||
// @Description Send a synchronization message with the local contacts list to all linked devices. This command should only be used if this is the primary device.
|
||||
// @Accept json
|
||||
// @Produce json
|
||||
// @Param number path string true "Registered Phone Number"
|
||||
// @Success 204
|
||||
// @Failure 400 {object} Error
|
||||
// @Router /v1/contacts{number}/sync [post]
|
||||
func (a *Api) SendContacts(c *gin.Context) {
|
||||
number := c.Param("number")
|
||||
if number == "" {
|
||||
c.JSON(400, Error{Msg: "Couldn't process request - number missing"})
|
||||
return
|
||||
}
|
||||
|
||||
err := a.signalClient.SendContacts(number)
|
||||
if err != nil {
|
||||
c.JSON(400, Error{Msg: err.Error()})
|
||||
return
|
||||
}
|
||||
c.Status(http.StatusNoContent)
|
||||
}
|
||||
|
||||
@@ -1582,6 +1582,21 @@ func (s *SignalClient) SearchForNumbers(number string, numbers []string) ([]Sear
|
||||
return searchResultEntries, err
|
||||
}
|
||||
|
||||
func (s* SignalClient) SendContacts(number string) error {
|
||||
var err error
|
||||
if s.signalCliMode == JsonRpc {
|
||||
jsonRpc2Client, err := s.getJsonRpc2Client(number)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
_, err = jsonRpc2Client.getRaw("sendContacts", nil)
|
||||
} else {
|
||||
cmd := []string{"--config", s.signalCliConfig, "-a", number, "sendContacts"}
|
||||
_, err = s.cliClient.Execute(true, cmd, "")
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
func (s *SignalClient) UpdateContact(number string, recipient string, name *string, expirationInSeconds *int) error {
|
||||
var err error
|
||||
if s.signalCliMode == JsonRpc {
|
||||
|
||||
@@ -242,6 +242,7 @@ func main() {
|
||||
contacts := v1.Group("/contacts")
|
||||
{
|
||||
contacts.PUT(":number", api.UpdateContact)
|
||||
contacts.POST(":number/sync", api.SendContacts)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user