From a498ef52f5dc8a0ac6b4c348fcc8156711409722 Mon Sep 17 00:00:00 2001 From: Vince Jerald Villamora Date: Wed, 2 Nov 2022 16:54:46 +0800 Subject: [PATCH] fix(msgr-reply): enhance typing indicators and user experience (#15) (#17) --- .../com/abavilla/fpi/bot/processor/MetaMsgEvtPcsr.java | 8 +++++--- .../java/com/abavilla/fpi/bot/service/MetaMsgrApiSvc.java | 4 ++-- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/fpi-bot-api-core/src/main/java/com/abavilla/fpi/bot/processor/MetaMsgEvtPcsr.java b/fpi-bot-api-core/src/main/java/com/abavilla/fpi/bot/processor/MetaMsgEvtPcsr.java index 07dabd1..c2e93a8 100644 --- a/fpi-bot-api-core/src/main/java/com/abavilla/fpi/bot/processor/MetaMsgEvtPcsr.java +++ b/fpi-bot-api-core/src/main/java/com/abavilla/fpi/bot/processor/MetaMsgEvtPcsr.java @@ -67,7 +67,7 @@ public class MetaMsgEvtPcsr { public Uni process(MetaMsgEvtDto evt) { Log.info("Received event: " + evt); if (StringUtils.isNotBlank(evt.getContent())) { - return metaMsgrSvc.sendTypingIndicator(evt.getSender()).chain(() -> { + return metaMsgrSvc.sendTypingIndicator(evt.getSender(), true).chain(() -> { Log.info("Processing event: " + evt.getMetaMsgId()); MetaMsgEvt metaMsgEvt = metaMsgEvtMapper.mapToEntity(evt); metaMsgEvt.setDateCreated(DateUtil.now()); @@ -93,7 +93,9 @@ public Uni process(MetaMsgEvtDto evt) { .invoke(throwable -> Log.warn("Received duplicate mid: " + evt.getMetaMsgId()) ); - }).onFailure().invoke(this::handleMsgEx); + }) + .chain(() -> metaMsgrSvc.sendTypingIndicator(evt.getSender(), false)).replaceWithVoid() + .onFailure().invoke(this::handleMsgEx); } return Uni.createFrom().voidItem(); } @@ -106,7 +108,7 @@ private Uni processLoadQuery(LoginDto login, RespDto session, query.setQuery(evt.getContent()); return loadApi.query(query, "Bearer " + session.getResp().getAccessToken()).chain(resp -> { Log.info("Query received, response is " + resp); - return sendMsgrMsg(evt, "Received your query, current status is " + resp.getStatus()); + return sendMsgrMsg(evt, "Working on your request, status is '%s'".formatted(resp.getStatus())); }); } return sendMsgrMsg(evt, session.getStatus()); diff --git a/fpi-bot-api-core/src/main/java/com/abavilla/fpi/bot/service/MetaMsgrApiSvc.java b/fpi-bot-api-core/src/main/java/com/abavilla/fpi/bot/service/MetaMsgrApiSvc.java index c3ea568..7d5508e 100644 --- a/fpi-bot-api-core/src/main/java/com/abavilla/fpi/bot/service/MetaMsgrApiSvc.java +++ b/fpi-bot-api-core/src/main/java/com/abavilla/fpi/bot/service/MetaMsgrApiSvc.java @@ -53,13 +53,13 @@ public Uni sendMsg(String msg, String recipientId) { ).map(this::mapResponse); } - public Uni sendTypingIndicator(String recipientId) { + public Uni sendTypingIndicator(String recipientId, boolean isTyping) { var recipient = new ProfileDto(); recipient.setId(recipientId); return client.sendTypingIndicator( metaApiKeyConfig.getPageId(), recipient.toJsonStr(), - SenderAction.TYPING_ON.toString(), + isTyping ? SenderAction.TYPING_ON.getValue() : SenderAction.TYPING_OFF.getValue(), "RESPONSE", metaApiKeyConfig.getPageAccessToken() ).map(this::mapResponse);