Skip to content

Commit

Permalink
Updates to transfer
Browse files Browse the repository at this point in the history
  • Loading branch information
docwho2 committed Oct 12, 2023
1 parent b2976fe commit 44d1219
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 43 deletions.
29 changes: 14 additions & 15 deletions ChimeSMA/src/main/java/cloud/cleo/chimesma/squareup/ChimeSMA.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ public class ChimeSMA extends AbstractFlow {
private final static Action MAIN_MENU = getMainMenu();

/**
* Simple Object that caches Square data about hours to determine whether store is open or closed
* Simple Object that caches Square data about hours to determine whether
* store is open or closed
*/
private final static SquareHours squareHours = SquareHours.getInstance();

Expand All @@ -28,7 +29,8 @@ public class ChimeSMA extends AbstractFlow {
private final static String VC_ARN = System.getenv("VC_ARN");

/**
* Initial action is to play welcome message and whether store is open or closed
* Initial action is to play welcome message and whether store is open or
* closed
*
* @return
*/
Expand All @@ -53,8 +55,8 @@ protected Action getInitialAction() {
}

/**
* Main menu is just a LexBox, and the only outputs are Quit and Transfer. Quit - hang up the call Transfer. -
* transfer the call to another number.
* Main menu is just a LexBox, and the only outputs are Quit and Transfer.
* Quit - hang up the call Transfer. - transfer the call to another number.
*
* @return
*/
Expand Down Expand Up @@ -90,7 +92,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");
// final var botResponse = attrs.get("botResponse"); # Ignore what GPT says, sometimes it says we cannot transfer even though we are
final var phone = attrs.get("transferNumber");
final var transfer = CallAndBridgeAction.builder()
.withDescription("Send Call to Team Member")
Expand All @@ -102,15 +104,11 @@ public static Action getMainMenu() {
transfer.setArn(VC_ARN);
transfer.setDescription("Send Call to Main Number via SIP");
}
// If we have a GPT response for the transfer, play that before transferring
if (botResponse != null) {
yield SpeakAction.builder()
.withText(botResponse)
.withNextAction(transfer)
.build();
} else {
yield transfer;
}
yield PlayAudioAction.builder()
.withDescription("Indicate transfer in progress")
.withKey("transfer.wav")
.withNextAction(transfer)
.build();
}
case "Quit" ->
goodbye;
Expand All @@ -130,7 +128,8 @@ public static Action getMainMenu() {
}

/**
* When an error occurs on a Action and the Action did not specify an Error Action
* When an error occurs on a Action and the Action did not specify an Error
* Action
*
* @return the default error Action
*/
Expand Down
2 changes: 1 addition & 1 deletion samconfig.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ lint = true
region = "us-east-1"
parameter_overrides = "SMAID=\"d95bf7c0-6ae3-436f-9831-c5c362884b97\" VOICECONNECTORARN=\"arn:aws:chime:us-east-1:364253738352:vc/cze9epizslzqslzjpo58ff\""
capabilities = "CAPABILITY_IAM"
confirm_changeset = false
confirm_changeset = true
resolve_s3 = true
profile = "CLEO"

Expand Down
50 changes: 24 additions & 26 deletions template.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,15 @@ Resources:
PromptText: |
Our store is currently closed.
TransferEN:
Type: Custom::PromptCreator
Properties:
ServiceToken: !GetAtt PromptCreator.Arn
VoiceId: !Ref VOICEIDEN
PromptName: transfer.wav
PromptText: |
Your call will now be transferred. Please be patient until the remote party answers.
GoodbyePromptEN:
Type: Custom::PromptCreator
Properties:
Expand Down Expand Up @@ -433,35 +442,24 @@ Resources:
AttributeName: ttl
Enabled: true





ChimeCallLexGPT:
Type: 'AWS::Lex::ResourcePolicy'
Type: AWS::Lex::ResourcePolicy
Properties:
ResourceArn: !GetAtt BotAliasGPT.Arn
Policy:
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "AllowChimePstnAudioUseBotGPT",
"Effect": "Allow",
"Principal": {
"Service": "voiceconnector.chime.amazonaws.com"
},
"Action": "lex:StartConversation",
"Resource": !Sub "${BotAliasGPT.Arn}",
"Condition": {
"StringEquals": {
"AWS:SourceAccount": !Sub "${AWS::AccountId}"
},
"ArnEquals": {
"AWS:SourceArn": !Sub "arn:aws:voiceconnector:${AWS::Region}:${AWS::AccountId}:sma/${SMAID}"
}
}
}
]
}
Version: '2012-10-17'
Statement:
- Sid: AllowChimePstnAudioUseBotGPT
Effect: Allow
Principal:
Service: voiceconnector.chime.amazonaws.com
Action: lex:StartConversation
Resource: !Sub ${BotAliasGPT.Arn}
Condition:
StringEquals:
AWS:SourceAccount: !Sub ${AWS::AccountId}
ArnEquals:
AWS:SourceArn: !Sub arn:aws:voiceconnector:${AWS::Region}:${AWS::AccountId}:sma/${SMAID}


0 comments on commit 44d1219

Please sign in to comment.