diff --git a/api/messageservice.yaml b/api/messageservice.yaml index 1b01415..5595399 100644 --- a/api/messageservice.yaml +++ b/api/messageservice.yaml @@ -405,6 +405,43 @@ paths: description: INTERNAL SERVER ERROR - server encountered unexpected condition security: - Bearer: [ ] + /messages/aliasWithContent/new: + post: + tags: + - message-controller + summary: 'Saves a new system message containing the provided message type in the alias and + some content. + [Authorization: Role: user, consultant, technical]' + operationId: saveAliasMessageWithContent + parameters: + - name: rcGroupId + in: header + required: true + schema: + type: string + requestBody: + required: true + content: + 'application/json': + schema: + $ref: '#/components/schemas/AliasMessageDTO' + responses: + 201: + description: CREATED - message was successfully created + content: + 'application/json': + schema: + $ref: '#/components/schemas/MessageResponseDTO' + 400: + description: BAD REQUEST - invalid/incomplete request or body object + 401: + description: UNAUTHORIZED - no/invalid Keycloak token + 403: + description: FORBIDDEN - no/invalid role/authorization + 500: + description: INTERNAL SERVER ERROR - server encountered unexpected condition + security: + - Bearer: [ ] components: schemas: @@ -538,6 +575,8 @@ components: $ref: '#/components/schemas/VideoCallMessageDTO' messageType: $ref: '#/components/schemas/MessageType' + content: + type: string ForwardMessageDTO: type: object @@ -601,6 +640,9 @@ components: MessageType: type: string enum: + - "APPOINTMENT_SET" + - "APPOINTMENT_CANCELLED" + - "APPOINTMENT_RESCHEDULED" - "FINISHED_CONVERSATION" - "FORWARD" - "FURTHER_STEPS" diff --git a/src/main/java/de/caritas/cob/messageservice/Messenger.java b/src/main/java/de/caritas/cob/messageservice/Messenger.java index 61aac04..526d79c 100644 --- a/src/main/java/de/caritas/cob/messageservice/Messenger.java +++ b/src/main/java/de/caritas/cob/messageservice/Messenger.java @@ -212,4 +212,19 @@ public boolean patchEventMessage(String rcToken, String rcUserId, String message return isUpdated; } + + /** + * Posts a message which contains an alias with the provided {@link MessageType} in + * the specified Rocket.Chat group. + * + * @param rcGroupId Rocket.Chat group ID + * @param messageType {@link MessageType} + * @return {@link MessageResponseDTO} + */ + public MessageResponseDTO postAliasMessage(String rcGroupId, MessageType messageType, String content) { + AliasMessageDTO aliasMessageDTO = new AliasMessageDTO().messageType(messageType).content(content); + var response = this.rocketChatService.postAliasOnlyMessageAsSystemUser(rcGroupId, + aliasMessageDTO); + return mapper.messageResponseOf(response); + } } diff --git a/src/main/java/de/caritas/cob/messageservice/api/controller/MessageController.java b/src/main/java/de/caritas/cob/messageservice/api/controller/MessageController.java index 8c62a3c..53e5952 100644 --- a/src/main/java/de/caritas/cob/messageservice/api/controller/MessageController.java +++ b/src/main/java/de/caritas/cob/messageservice/api/controller/MessageController.java @@ -271,4 +271,25 @@ public ResponseEntity patchMessage(String rcToken, String rcUserId, String ? ResponseEntity.noContent().build() : ResponseEntity.notFound().build(); } + + /** + * Posts a message which contains an alias with the provided {@link MessageType} in the specified + * Rocket.Chat group. + * + * @param rcGroupId (required) Rocket.Chat group ID + * @param aliasOnlyMessageDTO {@link AliasOnlyMessageDTO} + * @return {@link ResponseEntity} with the {@link HttpStatus} + */ + @Override + public ResponseEntity saveAliasMessageWithContent( + @RequestHeader String rcGroupId, + @Valid AliasMessageDTO aliasOnlyMessageDTO) { + var type = aliasOnlyMessageDTO.getMessageType(); + var response = messenger + .postAliasMessage(rcGroupId, type, aliasOnlyMessageDTO.getContent()); + return new ResponseEntity<>(response, HttpStatus.CREATED); + } + } + + diff --git a/src/main/java/de/caritas/cob/messageservice/api/service/RocketChatService.java b/src/main/java/de/caritas/cob/messageservice/api/service/RocketChatService.java index bfdb0c0..88cc4f9 100644 --- a/src/main/java/de/caritas/cob/messageservice/api/service/RocketChatService.java +++ b/src/main/java/de/caritas/cob/messageservice/api/service/RocketChatService.java @@ -182,7 +182,7 @@ private void setMessageType(MessagesDTO msg) { if (nonNull(msg.getAlias().getForwardMessageDTO())) { msg.getAlias().setMessageType(MessageType.FORWARD); - } else { + } else if (nonNull(msg.getAlias().getVideoCallMessageDTO())) { msg.getAlias().setMessageType(MessageType.VIDEOCALL); } } diff --git a/src/main/java/de/caritas/cob/messageservice/config/SecurityConfig.java b/src/main/java/de/caritas/cob/messageservice/config/SecurityConfig.java index ab8fa1a..f10d270 100644 --- a/src/main/java/de/caritas/cob/messageservice/config/SecurityConfig.java +++ b/src/main/java/de/caritas/cob/messageservice/config/SecurityConfig.java @@ -81,6 +81,8 @@ protected void configure(HttpSecurity http) throws Exception { .hasAuthority(USE_FEEDBACK) .antMatchers("/messages/aliasonly/new") .hasAnyAuthority(USER_DEFAULT, CONSULTANT_DEFAULT, TECHNICAL_DEFAULT) + .antMatchers("/messages/aliasWithContent/new") + .hasAnyAuthority(USER_DEFAULT, CONSULTANT_DEFAULT, TECHNICAL_DEFAULT) .anyRequest() .denyAll(); }