diff --git a/bot-core/bot-core-quarkus/src/main/java/dev/struchkov/godfather/quarkus/core/GeneralAutoResponder.java b/bot-core/bot-core-quarkus/src/main/java/dev/struchkov/godfather/quarkus/core/GeneralAutoResponder.java index d571c6c..1b4dca2 100644 --- a/bot-core/bot-core-quarkus/src/main/java/dev/struchkov/godfather/quarkus/core/GeneralAutoResponder.java +++ b/bot-core/bot-core-quarkus/src/main/java/dev/struchkov/godfather/quarkus/core/GeneralAutoResponder.java @@ -62,6 +62,10 @@ public class GeneralAutoResponder { this.modifiable = modifiable; } + public void initTextAnswerActionUnit(AnswerTextAction action) { + actionUnitMap.put(TypeUnit.TEXT, action); + } + public void initActionUnit(String typeUnit, ActionUnit, M> actionUnit) { if (!actionUnitMap.containsKey(typeUnit)) { actionUnitMap.put(typeUnit, actionUnit); diff --git a/bot-core/bot-core-quarkus/src/main/java/dev/struchkov/godfather/quarkus/core/action/AnswerTextAction.java b/bot-core/bot-core-quarkus/src/main/java/dev/struchkov/godfather/quarkus/core/action/AnswerTextAction.java index 2d1b16e..ce9d98c 100644 --- a/bot-core/bot-core-quarkus/src/main/java/dev/struchkov/godfather/quarkus/core/action/AnswerTextAction.java +++ b/bot-core/bot-core-quarkus/src/main/java/dev/struchkov/godfather/quarkus/core/action/AnswerTextAction.java @@ -20,10 +20,16 @@ public class AnswerTextAction implements ActionUnit, Message private final Sending sending; + private ActionBeforeSending actionBeforeSending; + public AnswerTextAction(Sending sending) { this.sending = sending; } + public void setActionBeforeSending(ActionBeforeSending actionBeforeSending) { + this.actionBeforeSending = actionBeforeSending; + } + @Override public Uni> action(UnitRequest, Message> unitRequest) { final Message message = unitRequest.getMessage(); @@ -31,9 +37,15 @@ public class AnswerTextAction implements ActionUnit, Message return unit.getAnswer().processing(message) .onItem().ifNotNull().call(v -> { - final ActionBeforeSending actionBeforeSending = unit.getActionBeforeSending(); if (checkNotNull(actionBeforeSending)) { - return actionBeforeSending.execute(); + return actionBeforeSending.execute(message.getPersonId()); + } + return Uni.createFrom().nullItem(); + }) + .onItem().ifNotNull().call(v -> { + final ActionBeforeSending unitActionBeforeSending = unit.getActionBeforeSending(); + if (checkNotNull(unitActionBeforeSending)) { + return unitActionBeforeSending.execute(message.getPersonId()); } return Uni.createFrom().nullItem(); }) diff --git a/bot-core/bot-core-quarkus/src/main/java/dev/struchkov/godfather/quarkus/core/unit/func/ActionBeforeSending.java b/bot-core/bot-core-quarkus/src/main/java/dev/struchkov/godfather/quarkus/core/unit/func/ActionBeforeSending.java index 492e6d3..2236fb0 100644 --- a/bot-core/bot-core-quarkus/src/main/java/dev/struchkov/godfather/quarkus/core/unit/func/ActionBeforeSending.java +++ b/bot-core/bot-core-quarkus/src/main/java/dev/struchkov/godfather/quarkus/core/unit/func/ActionBeforeSending.java @@ -5,6 +5,6 @@ import io.smallrye.mutiny.Uni; @FunctionalInterface public interface ActionBeforeSending { - Uni execute(); + Uni execute(String personId); } diff --git a/bot-core/bot-core-simple/src/main/java/dev/struchkov/godfather/simple/core/GeneralAutoResponder.java b/bot-core/bot-core-simple/src/main/java/dev/struchkov/godfather/simple/core/GeneralAutoResponder.java index 51a0357..8237a4f 100644 --- a/bot-core/bot-core-simple/src/main/java/dev/struchkov/godfather/simple/core/GeneralAutoResponder.java +++ b/bot-core/bot-core-simple/src/main/java/dev/struchkov/godfather/simple/core/GeneralAutoResponder.java @@ -61,6 +61,10 @@ public class GeneralAutoResponder { this.modifiable = modifiable; } + public void initTextAnswerActionUnit(AnswerTextAction action) { + actionUnitMap.put(TypeUnit.TEXT, action); + } + public void initActionUnit(String typeUnit, ActionUnit, M> actionUnit) { if (!actionUnitMap.containsKey(typeUnit)) { actionUnitMap.put(typeUnit, actionUnit); diff --git a/bot-core/bot-core-simple/src/main/java/dev/struchkov/godfather/simple/core/action/AnswerTextAction.java b/bot-core/bot-core-simple/src/main/java/dev/struchkov/godfather/simple/core/action/AnswerTextAction.java index 15dd9bc..1d3ada2 100644 --- a/bot-core/bot-core-simple/src/main/java/dev/struchkov/godfather/simple/core/action/AnswerTextAction.java +++ b/bot-core/bot-core-simple/src/main/java/dev/struchkov/godfather/simple/core/action/AnswerTextAction.java @@ -24,10 +24,16 @@ public class AnswerTextAction implements ActionUnit, Message private final Sending sending; + private ActionBeforeSending actionBeforeSending; + public AnswerTextAction(Sending sending) { this.sending = sending; } + public void setActionBeforeSending(ActionBeforeSending actionBeforeSending) { + this.actionBeforeSending = actionBeforeSending; + } + @Override public UnitRequest action(UnitRequest, Message> unitRequest) { final Message message = unitRequest.getMessage(); @@ -41,11 +47,15 @@ public class AnswerTextAction implements ActionUnit, Message answer.setRecipientIfNull(message.getPersonId()); - final ActionBeforeSending actionBeforeSending = unit.getActionBeforeSending(); if (checkNotNull(actionBeforeSending)) { actionBeforeSending.execute(message.getPersonId()); } + final ActionBeforeSending unitActionBeforeSending = unit.getActionBeforeSending(); + if (checkNotNull(unitActionBeforeSending)) { + unitActionBeforeSending.execute(message.getPersonId()); + } + final Optional optSentBox = sending.send(answer); final CallBackConsumer callBack = unit.getCallBack(); if (checkNotNull(callBack) && optAnswer.isPresent()) {