- Newest
- Most votes
- Most comments
To add time-specific greetings (good morning, good afternoon, good evening) to your Amazon Connect chat bot, you can use Amazon Connect Contact Flows along with AWS Lambda functions to dynamically determine the correct greeting based on the current time. Here's how you can implement this:
Step-by-Step Guide
1. Create a Lambda Function
Create a Lambda function that determines the current time of day and returns the appropriate greeting.
const AWS = require('aws-sdk');
exports.handler = async (event) => {
let currentTime = new Date();
let currentHour = currentTime.getUTCHours(); // Use UTC time for consistency across time zones
let greeting;
if (currentHour >= 5 && currentHour < 12) {
greeting = "Good morning";
} else if (currentHour >= 12 && currentHour < 18) {
greeting = "Good afternoon";
} else {
greeting = "Good evening";
}
return {
statusCode: 200,
greeting: greeting
};
};
2. Set Up IAM Role
Ensure that your Lambda function has the necessary permissions to be invoked by Amazon Connect. Create an IAM role with the following policy:
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": "lambda:InvokeFunction",
"Resource": "arn:aws:lambda:<region>:<account-id>:function:<lambda-function-name>"
}
]
}
3. Create Amazon Connect Contact Flow
In Amazon Connect, create a new contact flow or modify an existing one. Add the following steps:
1. Invoke Lambda Function:
- Add a Invoke AWS Lambda Function block to call your Lambda function.
- Configure the block to use the Lambda function you created.
2. Set Contact Attributes:
- Use a Set Contact Attributes block to store the greeting returned by the Lambda function. Set the attribute name (e.g., greeting) to the Lambda function's response.
3. Play Prompt:
- Add a Play Prompt block to play the greeting message.
- Use the greeting contact attribute in the prompt. For example, if you are using text-to-speech, you can set the prompt text to ${greeting}, welcome to our service!.
4. Deploy and Test Deploy the Lambda function and test your contact flow to ensure it correctly plays the time-specific greeting based on the time of day.
Example Contact Flow Configuration Here is an example of how the contact flow might look:
1. Invoke AWS Lambda Function Block:
- Name: Get Greeting
- Function ARN: arn:aws:lambda:<region>:<account-id>:function:<lambda-function-name>
- Save the response as a contact attribute greeting.
2. Set Contact Attributes Block:
- Attribute: greeting
- Value: $.External.GetGreeting.greeting
3. Play Prompt Block:
- Text-to-speech message: ${greeting}, welcome to our service!
By following these steps, your Amazon Connect contact flow will dynamically generate the appropriate greeting based on the time of day. This approach leverages Lambda functions to add flexibility and scalability to your contact center operations.
This can be achieved using hours of operation and a "Check hours of operation" flow block.
1. Define 3 hours of operation under Routing -> Hours of operation
- GoodMorning 9:00am - 12:00pm
- GoodAfternoon 12:01pm - 5:00pm
- GoodEvening 5:01pm - 9:00pm
2. Create flow
Create a flow that checks the hours of operation and plays a prompt if that check is "In Hours", if it is "Out of Hours" move on to the next check until the appropriate greeting is played.
When the Check hours of operation block is added change setting to set specific hours to check.
Relevant content
- asked 7 years ago
- AWS OFFICIALUpdated 3 months ago
- AWS OFFICIALUpdated 3 months ago
- AWS OFFICIALUpdated 2 years ago
- AWS OFFICIALUpdated 8 months ago
Where would you need to then reference this flow to apply it to all numbers/flows that have been created?