diff --git a/src/api/api.go b/src/api/api.go index df9c7cf..2d8194f 100644 --- a/src/api/api.go +++ b/src/api/api.go @@ -109,7 +109,7 @@ type SendMessageV2 struct { QuoteAuthor *string `json:"quote_author"` QuoteMessage *string `json:"quote_message"` QuoteMentions []client.MessageMention `json:"quote_mentions"` - TextMode *string `json:"text_mode"` + TextMode *string `json:"text_mode" enums:"normal,styled"` } type TypingIndicatorRequest struct { @@ -341,7 +341,7 @@ func (a *Api) Send(c *gin.Context) { // @Summary Send a signal message. // @Tags Messages -// @Description Send a signal message +// @Description Send a signal message. Set the text_mode to 'styled' in case you want to add formatting to your text message. Styling Options: *italic text*, **bold text**, ~strikethrough text~. // @Accept json // @Produce json // @Success 201 {object} SendMessageResponse @@ -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) +} diff --git a/src/client/client.go b/src/client/client.go index 6ecb7dc..72e629a 100644 --- a/src/client/client.go +++ b/src/client/client.go @@ -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 { diff --git a/src/docs/docs.go b/src/docs/docs.go index 890e42c..0bc3b04 100644 --- a/src/docs/docs.go +++ b/src/docs/docs.go @@ -333,6 +333,39 @@ var doc = `{ } } }, + "/v1/contacts{number}/sync": { + "post": { + "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.", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "Contacts" + ], + "summary": "Send a synchronization message with the local contacts list to all linked devices.", + "parameters": [ + { + "type": "string", + "description": "Registered Phone Number", + "name": "number", + "in": "path", + "required": true + } + ], + "responses": { + "204": {}, + "400": { + "description": "Bad Request", + "schema": { + "$ref": "#/definitions/api.Error" + } + } + } + } + }, "/v1/devices/{number}": { "post": { "description": "Links another device to this device. Only works, if this is the master device.", @@ -1566,7 +1599,7 @@ var doc = `{ }, "/v2/send": { "post": { - "description": "Send a signal message", + "description": "Send a signal message. Set the text_mode to 'styled' in case you want to add formatting to your text message. Styling Options: *italic text*, **bold text**, ~strikethrough text~.", "consumes": [ "application/json" ], @@ -1839,7 +1872,11 @@ var doc = `{ "type": "string" }, "text_mode": { - "type": "string" + "type": "string", + "enum": [ + "normal", + "styled" + ] } } }, diff --git a/src/docs/swagger.json b/src/docs/swagger.json index c6d3e34..ef70d4c 100644 --- a/src/docs/swagger.json +++ b/src/docs/swagger.json @@ -317,6 +317,39 @@ } } }, + "/v1/contacts{number}/sync": { + "post": { + "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.", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "Contacts" + ], + "summary": "Send a synchronization message with the local contacts list to all linked devices.", + "parameters": [ + { + "type": "string", + "description": "Registered Phone Number", + "name": "number", + "in": "path", + "required": true + } + ], + "responses": { + "204": {}, + "400": { + "description": "Bad Request", + "schema": { + "$ref": "#/definitions/api.Error" + } + } + } + } + }, "/v1/devices/{number}": { "post": { "description": "Links another device to this device. Only works, if this is the master device.", @@ -1550,7 +1583,7 @@ }, "/v2/send": { "post": { - "description": "Send a signal message", + "description": "Send a signal message. Set the text_mode to 'styled' in case you want to add formatting to your text message. Styling Options: *italic text*, **bold text**, ~strikethrough text~.", "consumes": [ "application/json" ], @@ -1823,7 +1856,11 @@ "type": "string" }, "text_mode": { - "type": "string" + "type": "string", + "enum": [ + "normal", + "styled" + ] } } }, diff --git a/src/docs/swagger.yaml b/src/docs/swagger.yaml index a17bb8f..d91dd86 100644 --- a/src/docs/swagger.yaml +++ b/src/docs/swagger.yaml @@ -154,6 +154,9 @@ definitions: sticker: type: string text_mode: + enum: + - normal + - styled type: string type: object api.TrustIdentityRequest: @@ -497,6 +500,28 @@ paths: 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 + /v1/contacts{number}/sync: + post: + consumes: + - application/json + 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. + parameters: + - description: Registered Phone Number + in: path + name: number + required: true + type: string + produces: + - application/json + responses: + "204": {} + "400": + description: Bad Request + schema: + $ref: '#/definitions/api.Error' + summary: Send a synchronization message with the local contacts list to all linked devices. + tags: + - Contacts /v1/devices/{number}: post: consumes: @@ -1317,7 +1342,7 @@ paths: post: consumes: - application/json - description: Send a signal message + description: 'Send a signal message. Set the text_mode to ''styled'' in case you want to add formatting to your text message. Styling Options: *italic text*, **bold text**, ~strikethrough text~.' parameters: - description: Input Data in: body diff --git a/src/main.go b/src/main.go index 7cd512b..0d1e6a0 100644 --- a/src/main.go +++ b/src/main.go @@ -242,6 +242,7 @@ func main() { contacts := v1.Group("/contacts") { contacts.PUT(":number", api.UpdateContact) + contacts.POST(":number/sync", api.SendContacts) } }