private void createLexBot()

in chatops-lex-bot/src/main/java/software/aws/chatops_lex_bot/App.java [73:131]


    private void createLexBot() {
    	
        try {
            //SlotType AccountTypeValues
            lexBuilderClient.putSlotType(builder-> builder.name("AccountTypeValues")
                                                            .enumerationValues(EnumerationValue.builder().value("Production").build(), 
                                                                                EnumerationValue.builder().value("Sandbox").build())
                                                            .build());
        }catch(PreconditionFailedException e) {
            logger.log("It seems the AccountTypeValues already exist.");
        }
        
        logger.log("Adding Slot Type:: AccountOUValues");
        try {
            //SlotType AccountOUValues
            lexBuilderClient.putSlotType(builder-> builder.name("AccountOUValues")
                    .enumerationValues(EnumerationValue.builder().value("Experiment").build(), 
                                        EnumerationValue.builder().value("Demos").build())
                    .build());
        }catch(PreconditionFailedException e) {
            logger.log("It seems the AccountOUValues already exist.");
        }
        
        
        logger.log("Adding Intent:: "+App.CHATOPS_INTENT_ACCT_VENDING_NAME);
        //Intent
        PutIntentResponse intentResp = lexBuilderClient.putIntent(builder-> builder
                                                .description("Intent responsible for the account vending conversation")
                                                .name(App.CHATOPS_INTENT_ACCT_VENDING_NAME)
                                                .fulfillmentActivity(act->act.type(FulfillmentActivityType.RETURN_INTENT).build()) //check here if builds but fails at the end
                                                .sampleUtterances("Hi I want a new account please", "Hi I would like to get an account", "I need a new account on AWS", "I want to create a new account", "I would like to create a new account", "I would like to get a new AWS account") // "I would like to create a ·{AccountType}· account"
                                                .confirmationPrompt(Prompt.builder().maxAttempts(4).messages(Arrays.asList(new Message[] {Message.builder().content("[UserName], are you sure you want to create a {AccountType} account associated to the OU {AccountOU} using root accout email {RootEmail}?").contentType(ContentType.PLAIN_TEXT).build()})).build())
                                                .rejectionStatement(b-> b.messages(Message.builder().contentType(ContentType.PLAIN_TEXT).content("Okay [UserName]. Your order won't be placed.").build()).build())
                                                .slots(Slot.builder().priority(1).slotConstraint(SlotConstraint.REQUIRED).slotType("AccountTypeValues").slotTypeVersion("$LATEST").name("AccountType").valueElicitationPrompt(Prompt.builder().maxAttempts(4).messages(Message.builder().contentType(ContentType.PLAIN_TEXT).content("Hi [UserName], what account type do you want? Production or Sandbox?").build()).build()).build(),
                                                        Slot.builder().priority(2).slotConstraint(SlotConstraint.REQUIRED).slotType("AMAZON.EmailAddress").name("RootEmail").valueElicitationPrompt(Prompt.builder().maxAttempts(4).messages(Message.builder().contentType(ContentType.PLAIN_TEXT).content("[UserName], what e-mail should I use for the root account? Hint: use a restricted access mailbox").build()).build()).build(),
                                                        Slot.builder().priority(3).slotConstraint(SlotConstraint.REQUIRED).slotType("AccountOUValues").slotTypeVersion("$LATEST").name("AccountOU").valueElicitationPrompt(Prompt.builder().maxAttempts(4).messages(Message.builder().contentType(ContentType.PLAIN_TEXT).content("[UserName], what is the OU this account should belong to? Hint: choose Experiment or Demos").build()).build()).build()
                                                        )
                                                .build());
        
        logger.log("Adding LexBot:: "+CHATOPS_BOT_NAME);
        //Bot name 
        PutBotResponse resp =   lexBuilderClient.putBot(builder-> builder.name(App.CHATOPS_BOT_NAME)    
                                            .childDirected(Boolean.FALSE)
                                            .clarificationPrompt(Prompt.builder().maxAttempts(4).messages(Message.builder().content("I don't understand. What would you like to do?").contentType(ContentType.PLAIN_TEXT).build()).build())
                                            .description("Control Tower Account Vending Intent")
                                            .detectSentiment(Boolean.FALSE)
                                            .enableModelImprovements(Boolean.TRUE)
                                            .idleSessionTTLInSeconds(600)
                                            .abortStatement(b-> b.messages(Message.builder().contentType(ContentType.PLAIN_TEXT).content("[UserName] I've given up.").build()).build())
                                            .locale(Locale.EN_US)
                                            .processBehavior(ProcessBehavior.BUILD)
                                            .intents(Intent.builder().intentName(App.CHATOPS_INTENT_ACCT_VENDING_NAME).intentVersion(intentResp.version()).build())
                                            .build());      

        logger.log("Adding LexBot Alias:: "+App.CHATOPS_INTENT_ACCT_VENDING_NAME);
        //create bot alias
        lexBuilderClient.putBotAlias(builder-> builder.botName(CHATOPS_BOT_NAME).botVersion(resp.version()).description("Production alias of the chatops bot").name("Prod").build());
        
    }