From 68c6595ab9a536cac696c26b94a96efd20a0b179 Mon Sep 17 00:00:00 2001 From: Bernhard B Date: Wed, 26 May 2021 18:02:55 +0200 Subject: [PATCH] return timestamp of sent message see #137 --- src/api/api.go | 12 +++++++++--- src/docs/docs.go | 12 ++++++++++-- src/docs/swagger.json | 12 ++++++++++-- src/docs/swagger.yaml | 9 +++++++-- 4 files changed, 36 insertions(+), 9 deletions(-) diff --git a/src/api/api.go b/src/api/api.go index 3a0f774..62e277c 100644 --- a/src/api/api.go +++ b/src/api/api.go @@ -118,6 +118,10 @@ type TrustIdentityRequest struct { VerifiedSafetyNumber string `json:"verified_safety_number"` } +type SendMessageResponse struct { + Timestamp string `json:"timestamp"` +} + func convertInternalGroupIdToGroupId(internalId string) string { return groupPrefix + base64.StdEncoding.EncodeToString([]byte(internalId)) } @@ -235,7 +239,7 @@ func send(c *gin.Context, attachmentTmpDir string, signalCliConfig string, numbe cmd = append(cmd, attachmentTmpPaths...) } - _, err := runSignalCli(true, cmd, message) + resp, err := runSignalCli(true, cmd, message) if err != nil { cleanupTmpFiles(attachmentTmpPaths) if strings.Contains(err.Error(), signalCliV2GroupError) { @@ -246,8 +250,10 @@ func send(c *gin.Context, attachmentTmpDir string, signalCliConfig string, numbe return } + sendMessageResponse := SendMessageResponse{Timestamp: strings.TrimSuffix(resp, "\n")} + cleanupTmpFiles(attachmentTmpPaths) - c.Writer.WriteHeader(201) + c.JSON(201, sendMessageResponse) } func parseWhitespaceDelimitedKeyValueStringList(in string, keys []string) []map[string]string { @@ -543,7 +549,7 @@ func (a *Api) Send(c *gin.Context) { // @Description Send a signal message // @Accept json // @Produce json -// @Success 201 {string} string "OK" +// @Success 201 {object} SendMessageResponse // @Failure 400 {object} Error // @Param data body SendMessageV2 true "Input Data" // @Router /v2/send [post] diff --git a/src/docs/docs.go b/src/docs/docs.go index cc8692a..079834f 100644 --- a/src/docs/docs.go +++ b/src/docs/docs.go @@ -902,9 +902,9 @@ var doc = `{ ], "responses": { "201": { - "description": "OK", + "description": "Created", "schema": { - "type": "string" + "$ref": "#/definitions/api.SendMessageResponse" } }, "400": { @@ -1048,6 +1048,14 @@ var doc = `{ } } }, + "api.SendMessageResponse": { + "type": "object", + "properties": { + "timestamp": { + "type": "string" + } + } + }, "api.SendMessageV1": { "type": "object", "properties": { diff --git a/src/docs/swagger.json b/src/docs/swagger.json index d02bd85..9401f6c 100644 --- a/src/docs/swagger.json +++ b/src/docs/swagger.json @@ -887,9 +887,9 @@ ], "responses": { "201": { - "description": "OK", + "description": "Created", "schema": { - "type": "string" + "$ref": "#/definitions/api.SendMessageResponse" } }, "400": { @@ -1033,6 +1033,14 @@ } } }, + "api.SendMessageResponse": { + "type": "object", + "properties": { + "timestamp": { + "type": "string" + } + } + }, "api.SendMessageV1": { "type": "object", "properties": { diff --git a/src/docs/swagger.yaml b/src/docs/swagger.yaml index fb381eb..e4b5610 100644 --- a/src/docs/swagger.yaml +++ b/src/docs/swagger.yaml @@ -84,6 +84,11 @@ definitions: use_voice: type: boolean type: object + api.SendMessageResponse: + properties: + timestamp: + type: string + type: object api.SendMessageV1: properties: base64_attachment: @@ -718,9 +723,9 @@ paths: - application/json responses: "201": - description: OK + description: Created schema: - type: string + $ref: '#/definitions/api.SendMessageResponse' "400": description: Bad Request schema: