mirror of
https://github.com/aljazceru/signal-cli-rest-api.git
synced 2025-12-19 15:44:28 +01:00
@@ -28,6 +28,12 @@ const (
|
|||||||
pingPeriod = (pongWait * 9) / 10
|
pingPeriod = (pongWait * 9) / 10
|
||||||
)
|
)
|
||||||
|
|
||||||
|
type UpdateContactRequest struct {
|
||||||
|
Recipient string `json:"recipient"`
|
||||||
|
Name *string `json:"name"`
|
||||||
|
ExpirationInSeconds *int `json:"expiration_in_seconds"`
|
||||||
|
}
|
||||||
|
|
||||||
type GroupPermissions struct {
|
type GroupPermissions struct {
|
||||||
AddMembers string `json:"add_members" enums:"only-admins,every-member"`
|
AddMembers string `json:"add_members" enums:"only-admins,every-member"`
|
||||||
EditGroup string `json:"edit_group" enums:"only-admins,every-member"`
|
EditGroup string `json:"edit_group" enums:"only-admins,every-member"`
|
||||||
@@ -1156,3 +1162,41 @@ func (a *Api) SearchForNumbers(c *gin.Context) {
|
|||||||
|
|
||||||
c.JSON(200, searchResponse)
|
c.JSON(200, searchResponse)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// @Summary Updates the info associated to a number on the contact list. If the contact doesn’t exist yet, it will be added.
|
||||||
|
// @Tags Contacts
|
||||||
|
// @Description Updates the info associated to a number on the contact list.
|
||||||
|
// @Accept json
|
||||||
|
// @Produce json
|
||||||
|
// @Param number path string true "Registered Phone Number"
|
||||||
|
// @Success 204
|
||||||
|
// @Param data body UpdateContactRequest true "Contact"
|
||||||
|
// @Failure 400 {object} Error
|
||||||
|
// @Router /v1/contacts [put]
|
||||||
|
func (a *Api) UpdateContact(c *gin.Context) {
|
||||||
|
number := c.Param("number")
|
||||||
|
if number == "" {
|
||||||
|
c.JSON(400, Error{Msg: "Couldn't process request - number missing"})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
var req UpdateContactRequest
|
||||||
|
err := c.BindJSON(&req)
|
||||||
|
if err != nil {
|
||||||
|
c.JSON(400, Error{Msg: "Couldn't process request - invalid request"})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if req.Recipient == "" {
|
||||||
|
c.JSON(400, Error{Msg: "Couldn't process request - recipient missing"})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
err = a.signalClient.UpdateContact(number, req.Recipient, req.Name, req.ExpirationInSeconds)
|
||||||
|
if err != nil {
|
||||||
|
c.JSON(400, Error{Msg: err.Error()})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
c.Status(http.StatusNoContent)
|
||||||
|
}
|
||||||
|
|||||||
@@ -1236,3 +1236,36 @@ func (s *SignalClient) SearchForNumbers(numbers []string) ([]SearchResultEntry,
|
|||||||
|
|
||||||
return searchResultEntries, err
|
return searchResultEntries, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (s *SignalClient) UpdateContact(number string, recipient string, name *string, expirationInSeconds *int) error {
|
||||||
|
var err error
|
||||||
|
if s.signalCliMode == JsonRpc {
|
||||||
|
type Request struct {
|
||||||
|
Recipient string `json:"recipient"`
|
||||||
|
Name string `json:"name,omitempty"`
|
||||||
|
Expiration int `json:"expiration,omitempty"`
|
||||||
|
}
|
||||||
|
request := Request{Recipient: recipient}
|
||||||
|
if name != nil {
|
||||||
|
request.Name = *name
|
||||||
|
}
|
||||||
|
if expirationInSeconds != nil {
|
||||||
|
request.Expiration = *expirationInSeconds
|
||||||
|
}
|
||||||
|
jsonRpc2Client, err := s.getJsonRpc2Client(number)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
_, err = jsonRpc2Client.getRaw("updateContact", request)
|
||||||
|
} else {
|
||||||
|
cmd := []string{"--config", s.signalCliConfig, "-a", number, "updateContact", recipient}
|
||||||
|
if name != nil {
|
||||||
|
cmd = append(cmd, []string{"-n", *name}...)
|
||||||
|
}
|
||||||
|
if expirationInSeconds != nil {
|
||||||
|
cmd = append(cmd, []string{"-e", strconv.Itoa(*expirationInSeconds)}...)
|
||||||
|
}
|
||||||
|
_, err = runSignalCli(true, cmd, "", s.signalCliMode)
|
||||||
|
}
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|||||||
@@ -227,6 +227,11 @@ func main() {
|
|||||||
{
|
{
|
||||||
search.GET("", api.SearchForNumbers)
|
search.GET("", api.SearchForNumbers)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
contacts := v1.Group("/contacts")
|
||||||
|
{
|
||||||
|
contacts.PUT(":number", api.UpdateContact)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
v2 := router.Group("/v2")
|
v2 := router.Group("/v2")
|
||||||
|
|||||||
Reference in New Issue
Block a user