☎️ An automated answering machine build on top of Amazon Connect
This small demo tries to simulate an automated answering machine built on top of Amazon Connect and AWS Lex. The stack basically pushes what you can do with Amazon Connect to the limit because Connect was never designed to be used in a scenario like this. But we do like to test the limits of what the cloud has to offer here at 0x4447, so we did it anyway, just to see where the stack would break. So enjoy the read.
Lex is the AWS service that powers Amazon Alexa, a Machine Learning model designed to understand the human voice by extracting the intent in the detected voice.
The service also allows interfacing with AWS Lambda to control how Lex processes the intents.
Amazon Connect is a virtual call center service we can use to create phone call flows based on user input, time of day, active agents, and more. This means that when someone calls a phone number we’ve bought, we can screen the caller with a basic number wall of options the caller can choose from. Or, if Connect is combined with Lex, the caller can talk back based on questions asked.
In addition to these two services, we can add a number of Lambda functions to gain complete control over Lex and Connect. We can do the following:
This enables us to ask for the caller’s name if it doesn’t appear in the database or use the caller’s name in greeting if the calling number has a matching name.
We’re pushing Connect to the limit, so there will be issues that can’t be solved and issues that require more code to solve, which would lead to overkill for this type of project. Regardless, those issues are listed below:
This stack is available to anyone at no cost, but on an as-is basis. 0x4447, LLC is not responsible for damages or costs of any kind that may occur when you use the stack. You take full responsibility when you use it.
This project is described using a CloudFormation file. Sadly, Lex and Connect are not yet supported by CloudFormation, and before deploying the stack, we need to perform some manual tasks to gather all necessary details for the CF stack itself.
Create
.Custom bot
.Office
as the name of your bot.Output voice
. Joanna seems to be the most natural-sounding of them all.Session timeout
field.No
in the COPPA
section.Create
.Create Intent
.Create intent
.GetName
Slots
section, we first need to create a new entry called first_name
with a Slot type
of AMAZON.US_FIRST_NAME
and a Prompt
set as Can I have your name
.+
button next to the slot to save it.Yes sure my name is {first_name}
I'm {first_name}
My name is {first_name}
{first_name}
Save intent
.GetMessage
.Slots
, type message
.Slot type
, select AMAZON.Festival
. We want the most general type possible, because we want to get the entire voice transcript rather than letting Lex try to understand the meaning of what’s said.Prompt
, type anything. Lex won’t be asking the question, our lambda will.+
button next to the slot to save it.Save intent
.Error Hanling
from the left menu.Clarification prompts
, type something like:Sorry, I didn't hear you.
What's that?
Maximum number of retries
to three.Hang-up phrase
, write: Sorry, the connection is bad. Please go to our contact page to send us an email.
+
button next to the message.x
button for the default disconnect message.Aliases
and create an alias named production
. Then select the latest Bot version
. This alias is important for building our setup.Build
. Once the process is done, you can test your bot by tying any string that infers your name. In return, only your name should be extracted from the message.Publish
at the top right corner next to Build
.Add an instance
button or Get Started
.Store users within Amazon Connect
, write the name for the Access URL
, and click Next step
.Create an Administrator
page, fill out the form for a new admin user. This has nothing to do with a IAM user. Once ready, click Next step
.Telephony Options
, check all options if you like, then click Next step
.Data storage
page as is by clicking Next step
.Create instance
when ready.Contact flows
at the bottom of the left menu.Amazon Lex
section, select the region where you created the bot.Bot
drop-down menu, select the Lex bot we created in the previous setup.+ add Lex Bot
.When this is done, we have Lex linked with Connect and the Connect Instance ARN for CloudFormation.
To deploy this stack, all you need to do is click the button to the left and follow the instructions that CloudFormation provides in your AWS Dashboard. Alternatively, you can download the CF file from here.
The stack takes advantage of AWS SES, AWS Lambda, and DyamoDB. You’ll get:
All project resources can be found here.
The stack is set up in a such a way that when new code is pushed to a selected branch, the CodePipeline picks up the change and updates the Lambdas for you. These are the available branches:
Now that we’ve deployed the stack, we have to go back to Lex for a moment to set one of the deployed Lambda to process the intent.
Offcie
bot we previously created.GetMessage
.Lambda initialization and validation
section:Initialization and validation code hook
.Ok
when the modal drops down.Fulfillment
section below:AWS Lambda function
.Save intent
.This part of the setup requires that you edit a JSON file to update it to your setup. But before we do that, let’s start with the basics.
Contact flows
.Contact flows
page, click Create contact flow
.Office
).At this stage, you can download our contact flow that we create. This is the file that you’ll have to edit, replacing some ARNs of the Lambda functions with your own. Sadly, there’s no automatic way to do this. You can find the Lambda ARNs in the output section of the deployed stack in CloudFormation.
Once you change the file, you can import the flow. At the top right corner is the Save
button, which has a downward-pointing arrow. Click on it and select Import flow (beta)
. Select the file and upload it. Once the flow shows up on the page, don’t forget to click Publish
. At this point, we have to attach the flow we made with a phone number. To do so, follow these steps:
Phone numbers
.Claim a number
on the right side of the page.Description
.Contact flow/IVR
drop-down.Save
.All resources deployed via this stack will potentially cost you money, but you’d have to do the following for this to happen:
The only payment you’ll encounter from Day One is with Connect, since they bill per minutes of use. Check their pricing page to get an idea of the cost.
When you want to deploy the stack, the only file you should be interested in is the CloudFormation.json
file. If you’d like to modify the stack, we recommend that you use the Grapes framework, which was designed to make it easier to work with the CloudFormation file. If you’d like to keep your sanity, never edit the main CF file 🤪.
If you enjoyed this project, please consider giving it a 🌟. And check out our 0x4447 GitHub account, where you’ll find additional resources you might find useful or interesting.
This project is brought to you by 0x4447 LLC, a software company specializing in building custom solutions on top of AWS. Follow this link to learn more: https://0x4447.com. Alternatively, send an email to hello@0x4447.email.