Skip to content

Commit

Permalink
Received Digit fixup
Browse files Browse the repository at this point in the history
  • Loading branch information
docwho2 committed Dec 3, 2023
1 parent b4ab4b5 commit 58c3f12
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ protected synchronized final static Integer registerAction(Action action) {
} else {
return actions.entrySet().stream()
.filter((t) -> t.getValue().equals(action))
.map(t -> t.getKey() ).findAny().orElse(0);
.map(t -> t.getKey()).findAny().orElse(0);
}
}

Expand All @@ -149,7 +149,7 @@ private LinkedList<Action> getActions(Action initialAction, SMARequest event) th
log.info("Adding action " + action.getDebugSummary());

int counter = 1; // Can only send max of 10 actions at a time
while (action.isChainable() && action.getNextRoutingAction() != null && counter < 10) {
while (action.isChainable() && action.getNextRoutingAction() != null && counter < 10) {
// We have a next action
final var nextAction = action.getNextRoutingAction().clone(event);
list.add(nextAction);
Expand Down Expand Up @@ -233,7 +233,22 @@ public final SMAResponse handleRequest(SMARequest event, Context cntxt) {
break;
case DIGITS_RECEIVED:
action = getCurrentAction(event);
res = defaultResponse(action, event);
action.onActionSuccessful();
final var dr_attrs = event.getCallDetails().getTransactionAttributes();
final var dr_actionIdStr = (String) dr_attrs.get(CURRENT_ACTION_ID);
// We need to check if we were weren't the last action, because if we weren't then we need to get that action
// And set as current
final var dr_nra = action.getNextRoutingAction();
final var dr_List = getActions(dr_nra, event);
if ( !action.getId().toString().equals(dr_actionIdStr) ) {
// We weren't the current action ID, so reset to that
final var attrs_new = dr_List.getLast().getTransactionAttributes();
attrs_new.put(CURRENT_ACTION_ID, dr_actionIdStr);
res = SMAResponse.builder().withTransactionAttributes(attrs_new)
.withActions(dr_List.stream().map(a -> a.getResponse()).collect(Collectors.toList())).build();
} else {
res = defaultResponse(action, event);
}
break;
case ACTION_FAILED:
action = getCurrentAction(event);
Expand Down Expand Up @@ -269,15 +284,15 @@ public final SMAResponse handleRequest(SMARequest event, Context cntxt) {
final var disconnectedBy = event.getCallDetails().getTransactionAttributes().getOrDefault("Disconnect", "Application");
log.debug("Call Was disconnected by [" + disconnectedBy + "], sending empty response");
action = getCurrentAction(event);
if (action instanceof CallAndBridgeAction ) {
if (action instanceof CallAndBridgeAction) {
// Because Call Bridge has 2 call legs in play, delegate respone to the Action since there
// various way to handle things, but the default being once connected a hangup on one leg should drop the other
final var cab = (CallAndBridgeAction) action;
final var nextAction = cab.getHangupAction();
if ( nextAction != null ) {
if (nextAction != null) {
actionList = getActions(nextAction, event);
res = SMAResponse.builder().withTransactionAttributes(actionList.getLast().getTransactionAttributes())
.withActions(actionList.stream().map(a -> a.getResponse()).collect(Collectors.toList())).build();
.withActions(actionList.stream().map(a -> a.getResponse()).collect(Collectors.toList())).build();
} else {
// No next action after hangup
res = emptyResponse();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,14 @@ protected StringBuilder getDebugSummary() {
.append(" [").append(getInputDigitsRegex()).append(']');
}

@Override
protected void onActionSuccessful() {
setTransactionAttribute("LastReceivedDigits", getReceivedDigits());
}

/**
* Override this because this is special case where ID needs to be
* set at render time, not after success like LexBot for example.
* Override this because this is special case where ID needs to be set at render time, not after success like LexBot
* for example.
*
* @return
*/
Expand Down

0 comments on commit 58c3f12

Please sign in to comment.