Skip to content

Commit

Permalink
Tweak Lex responses
Browse files Browse the repository at this point in the history
  • Loading branch information
docwho2 committed Nov 29, 2023
1 parent 09d821c commit 78de25f
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 22 deletions.
22 changes: 4 additions & 18 deletions ChatGPT/src/main/java/cloud/cleo/squareup/ChatGPTLambda.java
Original file line number Diff line number Diff line change
Expand Up @@ -282,28 +282,14 @@ private LexV2Response processGPT(LexV2Event lexRequest) {
*/
private LexV2Response buildQuitResponse(LexV2Event lexRequest) {

String state, action;
switch (LexInputMode.fromString(lexRequest.getInputMode())) {
case TEXT -> {
// For text, we say Quit is filled and close session
state = "Fulfilled";
action = "Close";
}
default -> {
// For voice we tell lex to return the intent and let it be fullfilled by Voice controller
state = "ReadyForFulfillment";
action = "Delegate";
}
}

// State to return
final var ss = SessionState.builder()
// Retain the current session attributes
.withSessionAttributes(lexRequest.getSessionState().getSessionAttributes())
// Send back Quit Intent
.withIntent(Intent.builder().withName("Quit").withState(state).build())
.withIntent(Intent.builder().withName("Quit").withState("Fulfilled").build())
// Indicate the Action
.withDialogAction(DialogAction.builder().withType(action).build())
.withDialogAction(DialogAction.builder().withType("Close").build())
.build();

final var lexV2Res = LexV2Response.builder()
Expand Down Expand Up @@ -352,9 +338,9 @@ private LexV2Response buildTransferResponse(LexV2Event lexRequest, String transf
// Retain the current session attributes
.withSessionAttributes(attrs)
// Send back Transfer Intent and let lex know that caller will fullfil it (namely Chime SMA Controller)
.withIntent(Intent.builder().withName("Transfer").withState("ReadyForFulfillment").build())
.withIntent(Intent.builder().withName("Transfer").withState("Fulfilled").build())
// Indicate the action as delegate, meaning lex won't fullfill, the caller will (Chime SMA Controller)
.withDialogAction(DialogAction.builder().withType("Delegate").build())
.withDialogAction(DialogAction.builder().withType("Close").build())
.build();

final var lexV2Res = LexV2Response.builder()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ public static Action getMainMenu() {
return switch (a.getIntentName()) {
case "Transfer" -> {
final var attrs = a.getActionData().getIntentResult().getSessionState().getSessionAttributes();
// final var botResponse = attrs.get("botResponse"); # Ignore what GPT says, sometimes it says we cannot transfer even though we are
final var botResponse = attrs.get("botResponse");
final var phone = attrs.get("transferNumber");
final var transfer = CallAndBridgeAction.builder()
.withDescription("Send Call to Team Member")
Expand All @@ -110,9 +110,9 @@ public static Action getMainMenu() {
transfer.setArn(VC_ARN);
transfer.setDescription("Send Call to Main Number via SIP");
}
yield PlayAudioAction.builder()
.withDescription("Indicate transfer in progress")
.withKey("transfer.wav")
yield SpeakAction.builder()
.withDescription("Indicate transfer in progress with Bot response")
.withTextF(tf -> botResponse)
.withNextAction(transfer)
.build();
}
Expand Down

0 comments on commit 78de25f

Please sign in to comment.