Skip to content

Commit

Permalink
fix(msgr-reply): enhance typing indicators and user experience (#15) (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
vincejv authored Nov 2, 2022
1 parent 0693c6f commit a498ef5
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public class MetaMsgEvtPcsr {
public Uni<Void> 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());
Expand All @@ -93,7 +93,9 @@ public Uni<Void> 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();
}
Expand All @@ -106,7 +108,7 @@ private Uni<Void> processLoadQuery(LoginDto login, RespDto<SessionDto> 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());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,13 @@ public Uni<MsgrReqReply> sendMsg(String msg, String recipientId) {
).map(this::mapResponse);
}

public Uni<MsgrReqReply> sendTypingIndicator(String recipientId) {
public Uni<MsgrReqReply> 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);
Expand Down

0 comments on commit a498ef5

Please sign in to comment.