Commit d361e3da authored by henrik.prangel's avatar henrik.prangel
Browse files

JUT-52 & JUT-53 Inform client that support is closed when trying to request...

JUT-52 & JUT-53 Inform client that support is closed when trying to request help at a time when support isn't working
parent 2c2ab1c8
......@@ -4,6 +4,10 @@ import com.netgroup.riigibot.service.dto.ChatDTO;
import com.netgroup.riigibot.service.dto.MessageDTO;
import com.netgroup.riigibot.service.enums.UnremarkableIntent;
import com.netgroup.riigibot.web.websocket.ActivityService;
import java.time.Instant;
import java.time.OffsetTime;
import java.time.ZoneId;
import java.time.ZoneOffset;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
......@@ -110,4 +114,13 @@ public class ConversationService {
private boolean isRemarkableIntent(String intent) {
return !EnumUtils.isValidEnum(UnremarkableIntent.class, intent);
}
public boolean isCustomerServiceCurrentlyActive() {
ZoneOffset estonianZoneOffset = ZoneOffset.of(ZoneId.of("Europe/Tallinn").getRules().getOffset(Instant.now()).getId());
OffsetTime openingTime = OffsetTime.of(10, 0, 0, 0, estonianZoneOffset);
OffsetTime closingTime = OffsetTime.of(15, 0, 0, 0, estonianZoneOffset);
return Instant.now().atOffset(estonianZoneOffset).toOffsetTime().isAfter(openingTime) &&
Instant.now().atOffset(estonianZoneOffset).toOffsetTime().isBefore(closingTime);
}
}
......@@ -2,6 +2,7 @@ package com.netgroup.riigibot.service;
import com.netgroup.riigibot.domain.Message;
import com.netgroup.riigibot.repository.MessageRepository;
import com.netgroup.riigibot.service.dto.ChatDTO;
import com.netgroup.riigibot.service.dto.MessageDTO;
import com.netgroup.riigibot.service.enums.VoteValues;
import com.netgroup.riigibot.service.mapper.MessageMapper;
......@@ -26,6 +27,13 @@ import org.springframework.transaction.annotation.Transactional;
@Service
@Transactional
public class MessageService {
private static final String CLIENT_SUPPORT_CLOSED =
"Tööaeg on 10.00-15.00, töövälisel ajal vastab ainult juturobot. Teenindajale " +
"suunamise testimiseks, palun edasta oma e-posti aadress, et saaksime olla kindlad, " +
"et sinu küsimus suunati klienditeenindajale. Kuna küsimus tuli töövälisel ajal, " +
"siis sellele klienditeenindaja enam ei vasta, suunamisest ja sinu e-posti aadressist piisab, " +
"et tehnilise lahenduse toimimist tõestada.";
private final Logger log = LoggerFactory.getLogger(MessageService.class);
private final MessageRepository messageRepository;
......@@ -117,6 +125,15 @@ public class MessageService {
}
}
public void sendMessageThatCustomerServiceIsClosedToChat(ChatDTO chatDTO) {
MessageDTO messageToSend = new MessageDTO();
messageToSend.setText(CLIENT_SUPPORT_CLOSED);
messageToSend.setChatId(chatDTO.getId());
messageToSend.setSender(chatDTO.getCommittedBot());
messageToSend.setSessionId(chatDTO.getSessionId());
saveAndSendMessage(messageToSend);
}
public void saveAndSendMessage(MessageDTO messageDTO) {
MessageDTO savedMessage = save(messageDTO);
sendMessageToUser(savedMessage, savedMessage.getSessionId());
......
......@@ -3,6 +3,7 @@ package com.netgroup.riigibot.web.rest;
import com.netgroup.riigibot.domain.BotNameConstants;
import com.netgroup.riigibot.security.AuthoritiesConstants;
import com.netgroup.riigibot.service.ChatService;
import com.netgroup.riigibot.service.ConversationService;
import com.netgroup.riigibot.service.MessageService;
import com.netgroup.riigibot.service.dto.ChatDTO;
import com.netgroup.riigibot.service.dto.MessageDTO;
......@@ -46,9 +47,12 @@ public class ChatResource {
private final MessageService messageService;
public ChatResource(ChatService chatService, MessageService messageService) {
private final ConversationService conversationService;
public ChatResource(ChatService chatService, MessageService messageService, ConversationService conversationService) {
this.chatService = chatService;
this.messageService = messageService;
this.conversationService = conversationService;
}
/**
......@@ -168,6 +172,9 @@ public class ChatResource {
messageDTO.setChatId(chat.getId());
messageDTO.setText(CHAT_REQUIRES_CUSTOMER_SERVICE);
messageService.broadcastMessageToUserGroup(chat.getCommittedBot(), messageDTO);
if (!conversationService.isCustomerServiceCurrentlyActive()) {
messageService.sendMessageThatCustomerServiceIsClosedToChat(chat);
}
HttpHeaders entityUpdateAlert = HeaderUtil.createEntityUpdateAlert(applicationName, true, ENTITY_NAME, id.toString());
return ResponseEntity.noContent().headers(entityUpdateAlert).build();
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment