mirror of
https://github.com/aljazceru/signal-cli-rest-api.git
synced 2025-12-20 08:04:28 +01:00
added possibility to update the group description & the avatar
see #417
This commit is contained in:
@@ -48,6 +48,11 @@ type CreateGroupRequest struct {
|
|||||||
GroupLinkState string `json:"group_link" enums:"disabled,enabled,enabled-with-approval"`
|
GroupLinkState string `json:"group_link" enums:"disabled,enabled,enabled-with-approval"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type UpdateGroupRequest struct {
|
||||||
|
Base64Avatar *string `json:"base64_avatar"`
|
||||||
|
Description *string `json:"description"`
|
||||||
|
}
|
||||||
|
|
||||||
type ChangeGroupMembersRequest struct {
|
type ChangeGroupMembersRequest struct {
|
||||||
Members []string `json:"members"`
|
Members []string `json:"members"`
|
||||||
}
|
}
|
||||||
@@ -1259,6 +1264,7 @@ func (a *Api) QuitGroup(c *gin.Context) {
|
|||||||
// @Failure 400 {object} Error
|
// @Failure 400 {object} Error
|
||||||
// @Param number path string true "Registered Phone Number"
|
// @Param number path string true "Registered Phone Number"
|
||||||
// @Param groupid path string true "Group ID"
|
// @Param groupid path string true "Group ID"
|
||||||
|
// @Param data body UpdateGroupRequest true "Input Data"
|
||||||
// @Router /v1/groups/{number}/{groupid} [put]
|
// @Router /v1/groups/{number}/{groupid} [put]
|
||||||
func (a *Api) UpdateGroup(c *gin.Context) {
|
func (a *Api) UpdateGroup(c *gin.Context) {
|
||||||
number := c.Param("number")
|
number := c.Param("number")
|
||||||
@@ -1274,7 +1280,15 @@ func (a *Api) UpdateGroup(c *gin.Context) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
err = a.signalClient.UpdateGroup(number, internalGroupId)
|
var req UpdateGroupRequest
|
||||||
|
err = c.BindJSON(&req)
|
||||||
|
if err != nil {
|
||||||
|
c.JSON(400, Error{Msg: "Couldn't process request - invalid request"})
|
||||||
|
log.Error(err.Error())
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
err = a.signalClient.UpdateGroup(number, internalGroupId, req.Base64Avatar, req.Description)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.JSON(400, Error{Msg: err.Error()})
|
c.JSON(400, Error{Msg: err.Error()})
|
||||||
return
|
return
|
||||||
|
|||||||
@@ -1282,21 +1282,80 @@ func (s *SignalClient) QuitGroup(number string, groupId string) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *SignalClient) UpdateGroup(number string, groupId string) error {
|
func (s *SignalClient) UpdateGroup(number string, groupId string, base64Avatar *string, groupDescription *string) error {
|
||||||
var err error
|
var err error
|
||||||
|
var avatarTmpPath string = ""
|
||||||
|
if base64Avatar != nil {
|
||||||
|
u, err := uuid.NewV4()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
avatarBytes, err := base64.StdEncoding.DecodeString(*base64Avatar)
|
||||||
|
if err != nil {
|
||||||
|
return errors.New("Couldn't decode base64 encoded avatar: " + err.Error())
|
||||||
|
}
|
||||||
|
|
||||||
|
fType, err := filetype.Get(avatarBytes)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
avatarTmpPath = s.avatarTmpDir + u.String() + "." + fType.Extension
|
||||||
|
|
||||||
|
f, err := os.Create(avatarTmpPath)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
defer f.Close()
|
||||||
|
|
||||||
|
if _, err := f.Write(avatarBytes); err != nil {
|
||||||
|
cleanupTmpFiles([]string{avatarTmpPath})
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if err := f.Sync(); err != nil {
|
||||||
|
cleanupTmpFiles([]string{avatarTmpPath})
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
f.Close()
|
||||||
|
}
|
||||||
|
|
||||||
if s.signalCliMode == JsonRpc {
|
if s.signalCliMode == JsonRpc {
|
||||||
type Request struct {
|
type Request struct {
|
||||||
GroupId string `json:"groupId"`
|
GroupId string `json:"groupId"`
|
||||||
|
Avatar string `json:"avatar,omitempty"`
|
||||||
|
Description *string `json:"description,omitempty"`
|
||||||
}
|
}
|
||||||
request := Request{GroupId: groupId}
|
request := Request{GroupId: groupId}
|
||||||
|
|
||||||
|
if base64Avatar != nil {
|
||||||
|
request.Avatar = avatarTmpPath
|
||||||
|
}
|
||||||
|
|
||||||
|
request.Description = groupDescription
|
||||||
|
|
||||||
|
|
||||||
jsonRpc2Client, err := s.getJsonRpc2Client(number)
|
jsonRpc2Client, err := s.getJsonRpc2Client(number)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
_, err = jsonRpc2Client.getRaw("updateGroup", request)
|
_, err = jsonRpc2Client.getRaw("updateGroup", request)
|
||||||
} else {
|
} else {
|
||||||
_, err = s.cliClient.Execute(true, []string{"--config", s.signalCliConfig, "-a", number, "updateGroup", "-g", groupId}, "")
|
cmd := []string{"--config", s.signalCliConfig, "-a", number, "updateGroup", "-g", groupId}
|
||||||
|
if base64Avatar != nil {
|
||||||
|
cmd = append(cmd, []string{"-a", avatarTmpPath}...)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if groupDescription != nil {
|
||||||
|
cmd = append(cmd, []string{"-d", *groupDescription}...)
|
||||||
|
}
|
||||||
|
_, err = s.cliClient.Execute(true, cmd, "")
|
||||||
|
}
|
||||||
|
|
||||||
|
if avatarTmpPath != "" {
|
||||||
|
cleanupTmpFiles([]string{avatarTmpPath})
|
||||||
|
}
|
||||||
|
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -505,6 +505,58 @@ var doc = `{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"put": {
|
||||||
|
"description": "Update the state of a Signal Group.",
|
||||||
|
"consumes": [
|
||||||
|
"application/json"
|
||||||
|
],
|
||||||
|
"produces": [
|
||||||
|
"application/json"
|
||||||
|
],
|
||||||
|
"tags": [
|
||||||
|
"Groups"
|
||||||
|
],
|
||||||
|
"summary": "Update the state of a Signal Group.",
|
||||||
|
"parameters": [
|
||||||
|
{
|
||||||
|
"type": "string",
|
||||||
|
"description": "Registered Phone Number",
|
||||||
|
"name": "number",
|
||||||
|
"in": "path",
|
||||||
|
"required": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "string",
|
||||||
|
"description": "Group ID",
|
||||||
|
"name": "groupid",
|
||||||
|
"in": "path",
|
||||||
|
"required": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"description": "Input Data",
|
||||||
|
"name": "data",
|
||||||
|
"in": "body",
|
||||||
|
"required": true,
|
||||||
|
"schema": {
|
||||||
|
"$ref": "#/definitions/api.UpdateGroupRequest"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"responses": {
|
||||||
|
"204": {
|
||||||
|
"description": "No Content",
|
||||||
|
"schema": {
|
||||||
|
"type": "string"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"400": {
|
||||||
|
"description": "Bad Request",
|
||||||
|
"schema": {
|
||||||
|
"$ref": "#/definitions/api.Error"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
"delete": {
|
"delete": {
|
||||||
"description": "Delete the specified Signal Group.",
|
"description": "Delete the specified Signal Group.",
|
||||||
"consumes": [
|
"consumes": [
|
||||||
@@ -1854,6 +1906,17 @@ var doc = `{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"api.UpdateGroupRequest": {
|
||||||
|
"type": "object",
|
||||||
|
"properties": {
|
||||||
|
"base64_avatar": {
|
||||||
|
"type": "string"
|
||||||
|
},
|
||||||
|
"description": {
|
||||||
|
"type": "string"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
"api.UpdateProfileRequest": {
|
"api.UpdateProfileRequest": {
|
||||||
"type": "object",
|
"type": "object",
|
||||||
"properties": {
|
"properties": {
|
||||||
|
|||||||
@@ -489,6 +489,58 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"put": {
|
||||||
|
"description": "Update the state of a Signal Group.",
|
||||||
|
"consumes": [
|
||||||
|
"application/json"
|
||||||
|
],
|
||||||
|
"produces": [
|
||||||
|
"application/json"
|
||||||
|
],
|
||||||
|
"tags": [
|
||||||
|
"Groups"
|
||||||
|
],
|
||||||
|
"summary": "Update the state of a Signal Group.",
|
||||||
|
"parameters": [
|
||||||
|
{
|
||||||
|
"type": "string",
|
||||||
|
"description": "Registered Phone Number",
|
||||||
|
"name": "number",
|
||||||
|
"in": "path",
|
||||||
|
"required": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "string",
|
||||||
|
"description": "Group ID",
|
||||||
|
"name": "groupid",
|
||||||
|
"in": "path",
|
||||||
|
"required": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"description": "Input Data",
|
||||||
|
"name": "data",
|
||||||
|
"in": "body",
|
||||||
|
"required": true,
|
||||||
|
"schema": {
|
||||||
|
"$ref": "#/definitions/api.UpdateGroupRequest"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"responses": {
|
||||||
|
"204": {
|
||||||
|
"description": "No Content",
|
||||||
|
"schema": {
|
||||||
|
"type": "string"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"400": {
|
||||||
|
"description": "Bad Request",
|
||||||
|
"schema": {
|
||||||
|
"$ref": "#/definitions/api.Error"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
"delete": {
|
"delete": {
|
||||||
"description": "Delete the specified Signal Group.",
|
"description": "Delete the specified Signal Group.",
|
||||||
"consumes": [
|
"consumes": [
|
||||||
@@ -1838,6 +1890,17 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"api.UpdateGroupRequest": {
|
||||||
|
"type": "object",
|
||||||
|
"properties": {
|
||||||
|
"base64_avatar": {
|
||||||
|
"type": "string"
|
||||||
|
},
|
||||||
|
"description": {
|
||||||
|
"type": "string"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
"api.UpdateProfileRequest": {
|
"api.UpdateProfileRequest": {
|
||||||
"type": "object",
|
"type": "object",
|
||||||
"properties": {
|
"properties": {
|
||||||
|
|||||||
@@ -197,6 +197,13 @@ definitions:
|
|||||||
recipient:
|
recipient:
|
||||||
type: string
|
type: string
|
||||||
type: object
|
type: object
|
||||||
|
api.UpdateGroupRequest:
|
||||||
|
properties:
|
||||||
|
base64_avatar:
|
||||||
|
type: string
|
||||||
|
description:
|
||||||
|
type: string
|
||||||
|
type: object
|
||||||
api.UpdateProfileRequest:
|
api.UpdateProfileRequest:
|
||||||
properties:
|
properties:
|
||||||
base64_avatar:
|
base64_avatar:
|
||||||
@@ -634,6 +641,41 @@ paths:
|
|||||||
summary: List a Signal Group.
|
summary: List a Signal Group.
|
||||||
tags:
|
tags:
|
||||||
- Groups
|
- Groups
|
||||||
|
put:
|
||||||
|
consumes:
|
||||||
|
- application/json
|
||||||
|
description: Update the state of a Signal Group.
|
||||||
|
parameters:
|
||||||
|
- description: Registered Phone Number
|
||||||
|
in: path
|
||||||
|
name: number
|
||||||
|
required: true
|
||||||
|
type: string
|
||||||
|
- description: Group ID
|
||||||
|
in: path
|
||||||
|
name: groupid
|
||||||
|
required: true
|
||||||
|
type: string
|
||||||
|
- description: Input Data
|
||||||
|
in: body
|
||||||
|
name: data
|
||||||
|
required: true
|
||||||
|
schema:
|
||||||
|
$ref: '#/definitions/api.UpdateGroupRequest'
|
||||||
|
produces:
|
||||||
|
- application/json
|
||||||
|
responses:
|
||||||
|
"204":
|
||||||
|
description: No Content
|
||||||
|
schema:
|
||||||
|
type: string
|
||||||
|
"400":
|
||||||
|
description: Bad Request
|
||||||
|
schema:
|
||||||
|
$ref: '#/definitions/api.Error'
|
||||||
|
summary: Update the state of a Signal Group.
|
||||||
|
tags:
|
||||||
|
- Groups
|
||||||
/v1/groups/{number}/{groupid}/admins:
|
/v1/groups/{number}/{groupid}/admins:
|
||||||
delete:
|
delete:
|
||||||
consumes:
|
consumes:
|
||||||
|
|||||||
Reference in New Issue
Block a user