Create the Amazon Lex Bot

Create an Amazon Lex V2 bot that sends a voice contact to the Agentforce agent. Keep the bot and the Q in Connect assistant in the same region.

Create the Lex V2 bot with AMAZON.QInConnectIntent pointed at the Q in Connect assistant ARN. Turn on speech-to-speech with Amazon Nova 2 Sonic. Then build the locale, create a version and alias, and associate the alias with the instance. Lex creates the system AMAZON.FallbackIntent.

  1. Create the bot. Leave error logging off unless the Lex service-linked role can create the log group. If error logging is on and the role doesn’t have that permission, the bot moves to Failed. If that happens, delete that bot and create it again.
    aws lexv2-models create-bot \
      --bot-name <LEX_BOT_NAME> \
      --role-arn <LEX_V2_SERVICE_LINKED_ROLE_ARN> \
      --data-privacy childDirected=false \
      --idle-session-ttl-in-seconds 300 \
      --bot-type Bot \
      --error-log-settings enabled=false \
      --region <REGION>
    Tip
    Tip For the Lex V2 service-linked role ARN, don’t use AmazonLexTestWorkbenchServiceRole. To get the role, run this command.
    aws iam list-roles \
      --query 'Roles[?starts_with(RoleName, `AWSServiceRoleForLexV2Bots_AmazonConnect_`)].Arn | [0]' \
      --output text \
      --profile <AWS_PROFILE>
  2. To confirm that the bot is created and available, run this command.
    aws lexv2-models describe-bot \
      --bot-id <botId> \
      --query '{botName:botName,botStatus:botStatus,failureReasons:failureReasons}' \
      --output table \
      --profile <AWS_PROFILE> \
      --region <REGION>
  3. Create the en_US locale and turn on speech-to-speech. Use a voice that Nova 2 Sonic supports. The example voice is tiffany. Use the amazon.nova-2-sonic-v1:0 model. Lex rejects the amazon.nova-sonic-v1:0 model.
    aws lexv2-models create-bot-locale \
      --bot-id <LEX_BOT_ID> \
      --bot-version DRAFT \
      --locale-id en_US \
      --nlu-intent-confidence-threshold 0.40 \
      --unified-speech-settings '{"speechFoundationModel":{"modelArn":"arn:aws:bedrock:<REGION>::foundation-model/amazon.nova-2-sonic-v1:0","voiceId":"tiffany"}}' \
      --region <REGION>
  4. Add the Q in Connect intent. Don’t add other intents or sample utterances.
    aws lexv2-models create-intent \
      --intent-name QInConnectIntent \
      --parent-intent-signature AMAZON.QInConnectIntent \
      --bot-id <LEX_BOT_ID> \
      --bot-version DRAFT \
      --locale-id en_US \
      --q-in-connect-intent-configuration '{"qInConnectAssistantConfiguration":{"assistantArn":"<ASSISTANT_ARN>"}}' \
      --region <REGION>
  5. To confirm the status of the bot locale, run this command.
    aws lexv2-models describe-bot-locale \
      --bot-id <LEX_BOT_ID> \
      --bot-version DRAFT \
      --locale-id en_US \
      --query '{status:botLocaleStatus,failureReasons:failureReasons}' \
      --output table \
      --profile <AWS_PROFILE> \
      --region <REGION>
  6. After the locale is NotBuilt, build it. Then wait until the locale is Built.
    aws lexv2-models build-bot-locale \
      --bot-id <LEX_BOT_ID> \
      --bot-version DRAFT \
      --locale-id en_US \
      --region <REGION>
  7. Create a bot version.
    aws lexv2-models list-bot-versions \
      --bot-id <LEX_BOT_ID> \
      --query "botVersionSummaries[?botVersion=='1'] | [0].{botVersion:botVersion,botStatus:botStatus}" \
      --output table \
      --profile <AWS_PROFILE> \
      --region <REGION>
  8. Create an enabled alias.
    aws lexv2-models create-bot-alias \
      --bot-alias-name <LEX_ALIAS_NAME> \
      --bot-version <LEX_BOT_VERSION> \
      --bot-alias-locale-settings '{"en_US":{"enabled":true}}' \
      --bot-id <LEX_BOT_ID> \
      --region <REGION>
  9. To get the alias ARN, run this command.
    LEX_ALIAS_ID=$(aws lexv2-models list-bot-aliases \
      --bot-id <BOT_ID> \
      --query "botAliasSummaries[?botAliasName=='scv-third-party-a2a-alias'].botAliasId | [0]" \
      --output text \
      --profile <SECURITY_PROFILE> \
      --region <REGION>)
    echo "arn:aws:lex:us-west-2:764189949692:bot-alias/E07YTAR2BZ/${LEX_ALIAS_ID}"
    The alias ARN is arn:aws:lex:<REGION>:<ACCOUNT_ID>:bot-alias/<LEX_BOT_ID>/<LEX_ALIAS_ID>.
  10. Confirm the alias is available.
    aws lexv2-models describe-bot-alias \
      --bot-id BOTID \
      --bot-alias-id ALIASID \
      --query '{name:botAliasName,status:botAliasStatus,version:botVersion}' \
      --output table \
      --region REGION
  11. Associate the alias with the Amazon Connect instance.
    aws connect associate-bot \
      --instance-id <CONNECT_INSTANCE_ID> \
      --lex-v2-bot AliasArn=<LEX_ALIAS_ARN> \
      --region <REGION>
    The alias ARN is arn:aws:lex:<REGION>:<ACCOUNT_ID>:bot-alias/<LEX_BOT_ID>/<LEX_ALIAS_ID>.