2021-12-24

How to delete contact flow in Amazon Connect

 As you may know, it is impossible to delete contact flows directly from Amazon Connect web interface.

In the past, the only option was to rename unused flows by adding something like zzzz_ at the beginning of the name of contact flow.

Finally, AWS gives you the option to delete contact flows from AWS CLI or by using Amazon Connect API.

Example:

1. Go to AWS Management Console

2. Open AWS CLI (also known as AWS CloudShell)


3. Type following command

aws connect delete-contact-flow --instance-id <instance-id> --contact-flow-id <contact-flow-id>

Example:

aws connect delete-contact-flow --instance-id 818ab265-dd50-476b-976c-0ce5fac38847 --contact-flow-id 83e19628-86b7-4b8a-b343-2cb8e4249631


4. You would need to know instance-id of Amazon Connect

You can learn how to do it here (in the web interface)

https://docs.aws.amazon.com/connect/latest/adminguide/find-instance-arn.html

Or you can type the following command in CloudShell:

aws connect list-instances 

and it would return all Amazon Connect instances


5. You would need to know contact flow id 

How to find out contact flow id:

https://docs.aws.amazon.com/connect/latest/adminguide/find-contact-flow-id.html

Or again you can do it directly in CloudShell:

aws connect list-contact-flows --instance-id <instance-id>


6. Last but not least.

You can also delete contact flow modules the same way:

aws connect delete-contact-flow-module --instance-id <instance-id> --contact-flow-module-id <contact-flow-module-id>

2021-12-12

Voicemail in Amazon Connect (part 2) - Sending voicemail to queue

In part 1 of this article, I gave an example of how to use Voicemail for Amazon Connect solution to be able to send voicemail from IVR to group email or to group cell phone as SMS.

Now I would like to show how to add the ability to send voicemail messages to Queue.

The idea is that we will piggyback on the Voicemail solution built by Amazon:

  • Whenever their solution does voicemail transcription it adds this information to DynamoDB table.
  • We will create Lambda function that is triggered when a new record is added to this table.
  • This lambda function in turn will gather all the available information about voicemail (voicemail timestamp, contact phone number,  queue name, voicemail transcript, URL to voicemail message)
  • It will then generate a Task that will have all this information and will send it to the queue.
  • An agent will receive a Task contact with all the available information about voicemail including transcript and link to a voicemail message that can be played back in the browser.

Here is how it is going to look like for agent:

1) Agent receives Task with title Voicemail
2) Agent accepts the task


3) Task contains all relevant info about the voicemail message
  • Contact Phone number         - caller id
  • Datetime - time when the client left a voicemail 
  • QueueName
  • QueueID  - this is a technical field that is required for the proper work of this solution
  • Voicemail Transcript
  • URL to the actual voicemail message





4) When Agent clicks on URL  - it will open player in the separate browser window, which gives agent option to listen to the actual voicemail message. 


5) Agent can also click on contactPhoneNumber and that will automatically initiate an outbound call.

Extra bonuses:
  • Since we already sent a voicemail to the queue it means that all the contact center stats and features (real-time reports, historical reports, contact search, Contact Lens) - will be automatically available
  • You can use all the available Amazon Connect KPIs  for voicemail
  • In the contact search you will see a voicemail transcript
  • If needed you can still be able to send voicemail by Email/SMS at the same time


If that is something that might be of interest to you - please follow this guide.


Step 1.

It is the same step that we had to do in part 1 of this article. So if you already did it in part 1 - no need to do it again.


We will start by implementing an official Voicemail for Amazon Connect solution.
It is fairly simple - just need to follow this implementation guide. It usually takes about 1 hour

https://docs.aws.amazon.com/solutions/latest/voicemail-for-amazon-connect/welcome.html

After it is implemented you need to test it and make sure it works, make sure that you can log in to Amazon Connect Voicemail Management Portal and can actually receive voicemail.


Step 2.

It is the same step that we had to do in part 1 of this article. So if you already did it in part 1 - no need to do it again.


Now we will create a "fake" agent account that will be used as a group voicemail box


  • First name = "VM"
  • Last name = must be equal to Name of Queue (for example "Tech_support")
  • Login name = must be equal to VM.<Name of the queue> (example VM.Tech_support)
  • Emal address - group email address that will be used to receive voicemails



Other parameters for this user can be anything you want because you would not need to log in to Amazon Connect with this user.



IMPORTANT:

For this solution to work correctly Login name must be in the following format
VM.<Name of the queue> (example VM.Tech_support)



Step 3.

It is the same step that we had to do in part 1 of this article. So if you already did it in part 1 - no need to do it again.

Now you need to login into your Amazon Connect Voicemail Management Portal.

1) Click on SYNC AGENTS button and your new user should appear in the list
2) Click on your VM user and configure it as required.
3) First thing you need to assign any extension that will be used to reference this agent in IVR.
In my case I assigned extension 7000.
4) Now you need to make sure to enable the following options:
  • Transcribe
  • Encrypt
  • Delivery Options - Email

This is required for the correct work of the solution. If you do not want to receive email notifications - you can assign to user a non-existent email address, but the delivery option must be enabled.





Step 4.

The next step is to create a new contact flow SendTask that is required to send tasks to the queue.



At first, we need to assign a working queue using Set working queue block.
  • Select Use attribute option.  
  • Type - User Defined
  • Attribute - QueueID

 

and after that our flow uses Transfer to queue block to actually transfer task to the queue.


You can download this flow from my GitHub:
https://github.com/contactcenterdude/amazon-connect/blob/main/Voicemail/SendTask-flow.json


Before we can move to the next step - you need to get Contact Flow ID that will be required in future steps.

  • Click on Show additional flow information.
  • In the ARN string Flow ID is the last 36 characters after contact-flow/





Step 5.

1. Go to AWS Management Console
2. Select DynamoDB
3. In the list of tables find 2 tables that have ContactVoicemailTable and UsersTable in the name.
These tables are automatically created when you install Voicemail solution.

In my case they have the following names: 
  • Amazon-Connect-Voicemail-VoicemailStack-1O9JZHZJ8ZD7Y-UsersTable-4DLIYWATXZ7T
  • Amazon-Connect-Voicemail-VoicemailStack-1O9JZHZJ8ZD7Y-ContactVoicemailTable-10UMQELMDZKAJ

Record their names, they will be required in future steps.


Step 6.

Now we will need to add lambda function create_Voicemail_Task that actually creates Task with voicemail info. This function is written in Python 3.9.


How it works:

  • gets info from ContactVoicemailTable. this table is used by Voicemail to keep results of voicemail transcription
  • if the transcription is completed it starts gathering data that will be added to Amazon Connect Task
      • contact phone number 
      • timestamp
      • queue name
      • queue id
      • URL to voicemail wav file
      • voicemail transcript
  • creates Amazon Connect Task

Source code available on my GitHub:
https://github.com/contactcenterdude/amazon-connect/blob/main/Voicemail/create_Voicemail_Task.py

************
You need to modify it before adding it to your instance:

In the lambda_handler function  provide info that is right for you: 

   # Region name of Amazon S3 and Amazon Transcribe
    region_name="us-east-1"
    
    # Amazon Connect InstanceId
    InstanceId="818ab265-dd50-476b-976c-0ce5fac38807"
    
    # FlowId of SendTask flow 
    ContactFlowId='5b67729d-21e7-4d3c-8a28-c96f881aa1a1'
    
    #name of DynamoDB table that is used by Voicemail to store voicemail users
    VoicemailTable="Amazon-Connect-Voicemail-VoicemailStack-1O9JZHZJ8ZD7Y-UsersTable-4DLIYWATXZ7T"

*************

After you add this lambda function I recommend increasing default timeout  (by default it is 3 seconds) to 10 seconds to give our function enough time to complete execution.
  • In AWS Management console open Lambda
  • Go to your function
  • Go to Configuration - General configuration
  • Click edit and change timeout to 10 seconds

Step 7. 

Before we can continue you have to add enough rights to the Role under which you will be running your lambda function.

Here is an example of a policy that I added to the role under which lambda function create_Voicemail_Task is running.


Before applying it you need to modify it for your case:
  • On line 8 - you need to specify ARN of your S3 bucket that is used for storing voicemails:
           "Resource": "arn:aws:s3:::amazon-connect-voicemail-vo-audiorecordingsbucket-z3v6jf3t44e7/*"
  • You can connect to S3 from the management console and find a bucket that has voicemail-vo-audiorecordingsbucket in the name.


Example 1 -- Role that is used for my lambda function


Example 2 -- Permissions for this role:




Step 8.

Now we need to add a trigger to our lambda function create_Voicemail_Task.
It will be triggered every time there is a new record added to ContactVoicemailTable table.
How to do it:
1) Go to Lambda and open our function create_Voicemail_Task
2) Click Add Trigger and create a new DynamoDB trigger

  • Trigger configuration - DynamoDB
  • DynamoDB table - find your ContactVoicemailTable
  • Batch size = 10
  • Starting position = TRIM_HORIZON
  • other configuration - by default
3) Save it
This is how it looks in my case.




Step 9. 

It is the same step that we had to do in part 1 of this article. So if you already did it in part 1 - no need to do it again.

Now we will create a module that will be doing all the magic of recording voicemail message and sending it to Email/SMS.




You can download this module from my GitHub:

https://github.com/contactcenterdude/amazon-connect/blob/main/Voicemail/Transfer_to_VM_module.json

Import it to your Amazon Connect instance.

Step 10.

It is the same step that we had to do in part 1 of this article. So if you already did it in part 1 - no need to do it again.

Now we can use our module in any IVR flow.

I created a simple VoicemailDemo flow. It emulates a situation when you want to offer client to leave a voicemail during non-working hours.


How it works.

1) At first I play the message "Our contact center is currently closed, please call us tomorrow. If you want to leave us a voicemail press 1".

2) If a client enters 1 

* First we need to add Set contact attributes block and assign voicemail user extension 7000 to user-defined attribute extensionNumber


* second - I invoke module Transfer_to_VM

And it is done. Transfer_to_VM module will do the rest.

Here is a full screenshot of VoicemailDemo flow


You can download it from my GitHub:

https://github.com/contactcenterdude/amazon-connect/blob/main/Voicemail/VoicemailDemo_flow.json

Step 11 (optional) .

It is the same step that we had to do in part 1 of this article. So if you already did it in part 1 - no need to do it again.

In steps 9 and 10 I gave you examples of how to offer the voicemail option in IVR before the call was transferred to queue.

What if you want to offer voicemail for the call that is already waiting in the queue?

I created another demo flow WaitInQueue_with_VM that demonstrates how to do it.

Important:

1) This is Customer queue flow so in order to use it you have to use Set customer queue flow in your main IVR before call is transferred to queue.

2) Amazon Connect does not allow to use of modules in Customer queue flows (hopefully this functionality would be added in the future). So I had to copy all the blocks from my module directly to customer queue flow.

3) Again, you have to assign an extension to extensionNumber attribute using Set contact attributes block like we did it before.


You can download this flow from my Github

https://github.com/contactcenterdude/amazon-connect/blob/main/Voicemail/WaitInQueue_with_VM_flow.json


**********

This solution is a little bit more complicated than my previous articles. So if you have any questions do not hesitate to contact me either in the comments or using the contact form on my site.



2021-12-11

Voicemail in Amazon Connect (part 1) - Group voicemail

 When Amazon Connect was first released back in 2017 many users were surprised that voicemail (and many other basic telephony features) were missing.

We are at the end of 2021 and still, voicemail is not a part of official functionality. Luckily things have changed. In 2020 Amazon introduced Voicemail as a separate solution that can be quite easily added to your instance of Amazon Connect. Plus there are some modifications of it developed either by AWS or by AWS partners.

You can easily add Voicemail by following this instruction:

https://aws.amazon.com/solutions/implementations/voicemail-for-amazon-connect/

Essentially it is a Voicemail/Auto-Attendant application that allows you to reach each individual agent (or user) of Amazon Connect by extension and leave a voicemail message if the person is not available. So basically it is a solution for personal voicemail boxes. Voicemail can be sent by Email and/or by SMS of the user, there is built-in Encryption and Transcription option (Speech to text). 

I find that this solution is missing some quite common features of voicemail that are sometimes used by contact centers:

1) Group voicemail.  

Very often contact centers offer to leave voicemail messages during non-working hours or when all agents are busy. In this case, voicemail is not associated with one user but generally associated with a group of agents.

2) Send voicemail to queue

In this case, voicemail message is sent to the queue and will be processed by the first available agent like any other type of contact. This is very similar to the callback option, except that voicemail allows clients to record a message with their voice, but generally, clients have expectations that someone from the contact center will listen to their message and contact them.

-------

The good news is that both of these features can be added to already existing Voicemail for Amazon Connect solution without major development.

In part 1 of this article, I would like to demonstrate how to add Group voicemail. Part 2 will be about sending voicemail to the queue. 

****************************

OK. So how can we add Group voicemail to Amazon Connect? Here is the process:

Step 1.

We will start by implementing an official Voicemail for Amazon Connect solution.

It is fairly simple - just need to follow this implementation guide. It usually takes about 1 hour.

https://docs.aws.amazon.com/solutions/latest/voicemail-for-amazon-connect/welcome.html

After it is implemented you need to test it and make sure it works, make sure that you can log in to Amazon Connect Voicemail Management Portal and can actually receive voicemail.

Step 2.

Now we will create a "fake" agent account that will be used as a group voicemail box


  • First name = "VM"
  • Last name = Name of Queue  (for example "Tech_support")
  • Login name = VM.<Name of the queue>   (example VM.Tech_support)
  • Emal address - group email address that will be used to receive voicemails

Other parameters for these users can be anything you want because you would not need to log in to Amazon Connect with this user.

Step 3.

Now you need to login into your Amazon Connect Voicemail Management Portal.

1) Click on SYNC AGENTS button and your new user should appear in the list

2) Click on your VM user and configure it as required.

3) First thing you need is to assign any extension that will be used to reference this agent in IVR.

In my case, I assigned extension 7000.

4) Now you might want to enable some of these features depending on your requirements.

In my example  I enabled everything:

  • Transcribe
  • Encrypt
  • Delivery Options - Email
  • Delivery Options - SMS
  • Added cell phone number for SMS delivery



Step 4.

Now we will create a module that will be doing all the magic of recording voicemail message and sending it to Email/SMS.

I almost did not have to develop anything myself. I just took 2 standard flows that come with this Voicemail solution - VM-Greeting.json and VM-Agent.json, combined them into 1 module that is called Transfer_to_VM that will work this way:

1) Instead of asking a client to enter an agent extension we will pass the extension to our module using contact attribute

2) I removed all the verifications of user availability - we do not need them because we want to force transfer to voicemail

3) After that it pretty much follows the algorithm of standard VM-Greeting & VM-Agent - uses Lambda function to find a configuration of the user and starts media streaming & recording, that later will be transcribed by Amazon Transcribe and sent to email and/or SMS depending on how you configure it.



You can download this module from my GitHub:

https://github.com/contactcenterdude/amazon-connect/blob/main/Voicemail/Transfer_to_VM_module.json

NOTE:  On line 235  you need to change the name of lambda function to match your configuration.

Import it to your Amazon Connect instance.

Step 5.

Now we can use our module in any IVR flow.

I created a simple VoicemailDemo flow. It emulates a situation when you want to offer the client to leave a voicemail during non-working hours.

How it works.

1) At first I play the message "Our contact center is currently closed, please call us tomorrow. If you want to leave us a voicemail press 1".

2) If the client enters 1 

* First we need to add Set contact attributes block and assign voicemail user extension 7000 to user-defined attribute extensionNumber


* second - I invoke module Transfer_to_VM

And it is done. Transfer_to_VM module will do the rest.

Here is a screenshot of VoicemailDemo flow


You can download it from my GitHub:

https://github.com/contactcenterdude/amazon-connect/blob/main/Voicemail/VoicemailDemo_flow.json

Step 6 (optional) .

In steps 4 and 5 I gave you examples of how to offer a voicemail option in IVR before the call was transferred to the queue.

What if you want to offer voicemail for the call that is already waiting in the queue?

I created another demo flow WaitInQueue_with_VM that demonstrates how to do it.

Important:

1) This is Customer queue flow so to use it you have to use Set customer queue flow in your main IVR before the call is transferred to the queue.

2) Amazon Connect does not allow the use of modules in Customer queue flows (hopefully this functionality would be added in the future). So I had to copy all the blocks from my module directly to customer queue flow.

3) Again, you have to assign an extension to extensionNumber attribute using Set contact attributes block like we did it before.


You can download this flow from my Github

https://github.com/contactcenterdude/amazon-connect/blob/main/Voicemail/WaitInQueue_with_VM_flow.json

NOTE:  On line 448  you need to change the name of lambda function to match your configuration.

****************

So there you have it - we can now add Voicemail option to your IVR:

  • before the call was transferred to the queue 
  • while the call is waiting in the queue

In both cases, a voicemail message will be sent to an email address  (or phone number for SMS) that is associated with a "fake" user account. 

Positive side of this configuration:

  • easy to setup
  • does not require custom development

Negative side:

  • It is not ideal from a management perspective - since it does not generate any stats
  • Someone needs to constantly monitor your group email address (or cell phone number) to be able to reach clients that left voicemail messages

With some customizations and by using Tasks it is possible to send voicemails to Queue and that will automatically take care of stats and management.

Stay tuned for part 2 of this article where I would explain how to do it.

2021-12-09

SLA Notifications in Amazon Connect

One of the most important KPIs of any contact center is SLA (service level agreement). It shows the percentage of the calls that were answered before the threshold. For example, 80% of the calls must be answered before 20 seconds of waiting in line.

Since it is such an important metric quite often contact center management would like to be informed about it, so they could act quickly to improve SLA for example by adding more agents on the line.

Of course, you can see SLA in historical and real-time reports, but in this article, I would like to demonstrate how to create automated SLA notifications that will be sending SLA metrics every hour by SMS or by EMail.

In my example, I will be sending SLA notifications every hour for the previous hour. This can be modified based on requirements.

Step 1. 

I will start by creating DynamoDB table that will be used to keep configuration for each Queue.

DynamoDB table - SLA_Notifier with following attributes

  • QueueId     - QueueId in Amazon Connect (see below where to find QueueId)
  • QueueName   - Queue name
  • Channel     - a type of channel (VOICE, CHAT, TASK).  You need this field because normally you would have different SLAs for each type of contact (calls, chats, tasks).
  • Threshold  - SLA threshold (for example 20 seconds)
  • SendEmail   - yes/no. Do you want to send SLA notifications by Email?
  • SendSMS     - yes/no. Do you want to send SLA notifications by SMS?
  • email       - send Email to this address
  • phoneNumber - send SMS to this phone number 



* Where to find QueueID:

1. Connect to Amazon Connect interface
2. Go to Routing - Queues
3. Select desired Queue
4. Click "Show additional queue information"
5. Take the last 36 characters in ARN field after queue/ - this is QueueID



Step 2.

I created Lambda function SLA_Notifier using Python 3.9 that does the following:

1) grabs all data from DynamoDB table SLA_Notifier
2) for each queue in the table it gets SLA for the last X minutes. Where X is configurable.
3)  for each line in the table it identifies if we need to send SMS and/or send Email
4)  sends SMS and/or EMail as required

Source code of this function on my GitHub:

Before you can use it you have to configure the following parameters 

************
    # Amazon Connect InstanceId
    InstanceId="838ab265-dd60-476b-976c-0ce5fac44809"
    
    #Statistical interval in minutes (SLA for last X minutes)
    statInterval="60"
    
    # Region name of Amazon SES and Amazon SNS
    region_name="us-east-1"
    
    # MailFrom for EMail notification
    MailFrom = "sla_notifier@ecorp.com"
    
    # Subject for EMail notifications
    Subject='SLA Notifier'

**************

Read this article to find your Amazon Connect InstanceId



IMPORTANT:
 In my example, I assume that you already configured Amazon SES so that you would be able to send emails using MailFrom address. 

*******

After you add this lambda function I recommend increasing default timeout  (by default it is 3 seconds) to 10 seconds to give our function enough time to complete execution.
  • In AWS Management console open Lambda
  • Go to your function
  • Go to Configuration - General configuration
  • Click edit and change timeout to 10 seconds


Step 3.

The last step is to create a schedule to run our Lambda function every hour.
To do that do the following:

1. In AWS console select Amazon EventBridge
2. Go to Rules
3. Click "Create rule"
4. Specify rule name (for example "SLA_Notifier")
5. Define pattern - select "Schedule"
6. Select "Cron expression"
7. Enter following cron expression 0 * * * ? *
It means that our rule will be triggered at 0 minutes of every hour.
8. Scroll down to "Select targets"
9. In the Target list select "Lambda function"
10. And select our function "SLA_Notifier"


11. Save this rule

*****************************

Some possible modifications:

1) The same way I send SLA it is easy to add additional metrics to notifications.
Anything that can be returned by GetMetricData function of Amazon Connect API can be easily added to the notification.
2) You can add extra logic and only send notifications if SLA (or any other metric) is within a certain range (for example if SLA drops below 70%)
3) You can adjust statistical interval and cron expression to send notifications more or less often.







2021-12-07

Emergency Messages in Amazon Connect (part 3)

In part 2 of this article, I demonstrated how to create Admin IVR to be able to enable/disable emergency messages using the phone menu.

Right now our Admin IVR has no protection so anyone can dial it and fiddle with emergency messages.

There are multiple options on how to add security to our IVR menu such as:

1) Option 1 - easiest option would be to add a numeric password that will be hardcoded directly in Admin IVR. You ask users to enter the password first and if it is correct proceed with normal Admin IVR behavior.

This option is OK if you have a small number of users (ideally 1 user only).

2) Option 2 - create a user table that contains an individual numeric password for each user. 

Optionally you can add phone numbers to user table and limit access for each user only if they dialed from a specific phone number (for example corporate cell phone number).

3) Option 3 - use VoiceID to add authentication by voice.

In this article, I would like to show how to use DynamoDB table to add authentication to Admin IVR - option 2.


Step 1.

I created DynamoDB table EmergencyMessagesAdmin with the following attributes:
  • PIN   - unique PIN code assigned to each user
  • FirstName  
  • LastName



Step 2.

Next step we will need a new Lambda function checkEmergencyMessagesAdmin to verify if the PIN code matches.

What it does:

  • takes PIN codes as input and verifies if there such PIN code in EmergencyMessagesAdmin
  • if yes returns Valid = 1
You can download source code from my GitHub:

https://github.com/contactcenterdude/amazon-connect/blob/main/EmergencyMessages/checkEmergencyMessagesAdmin.py

Step 3.

Now let's update the existing flow EmergencyMessagesAdmin.


Right at the beginning of the flow, we will ask user to enter PIN-code and then use our lambda function checkEmergencyMessagesAdmin to verify if it is a valid user.


If it is a valid user -> we will offer a standard IVR Admin menu.



You can download source code from my GitHub:

Emergency Messages in Amazon Connect (part 2)

 In this article, I would like to continue talking about Emergency Messages in Amazon Connect.

In part1 I explained how to add Emergency Messages in your existing IVR. Now I would like to talk about how to disable/enable them using Admin IVR.

As described in part1 we already have DynamoDB table EmergencyMessages that contains information about our Emergency Messages. 

So what options do we have to update this table?

1) Option1  - connect to DynamoDB and change values directly in the table. This option is situable for system administrators, regular users would not have access to the table.

2) Option 2 - create a web interface that would allow us to manage Emergency Messages. This is probably the most user-friendly option but it requires web development.

3) Option 3 - create Admin IVR that allows to Enable/Disable emergency messages. 

I would like to give you an example of how to implement Option 3.


Step 1.

I created Lambda function using Python 3.9 which is called UpdateEmergencyMessage.

It takes 2 input parameters:

  • MessageID  -  ID of Emergency Message
  • Status  - current status of the message
After that, it changes the status of the emergency message from the current one to the opposite (Enabled to Disabled, Disabled to Enabled) and updates DynamoDB EmergencyMessages table

You can download source code from my GitHub:

https://github.com/contactcenterdude/amazon-connect/blob/main/EmergencyMessages/UpdateEmergencyMessage.py


Step 2.

Now we will create a new IVR flow EmergencyMessagesAdmin.

How it works:

1) At first we will ask a user to enter ID of the Emergency Message.

2) After that we will use the existing lambda function CheckEmergencyMessage to check the current status of this message

3) We will play back the user current status of the message

4) After that I offer the user 2 options

  • Press 1 - to change the status of the message
  • Press 2 - to play text of the message (might be helpful to verify if you are actually changing the right thing)
5) If the user pressed 1 - I will call Lambda function UpdateEmergencyMessage to change the status of the message.

6) After that I will call again lambda function CheckEmergencyMessage to verify the new status of the message and playback to user new status



You can download the flow from my GitHub:

https://github.com/contactcenterdude/amazon-connect/blob/main/EmergencyMessages/EmergencyMessagesAdmin_flow.json

Step 3.

Now you just need to assign a phone number to Admin IVR flow.

****************


Ok. Admin IVR is now ready but something seems to be still missing.

Well, right now anyone can dial this Admin IVR and disable/enable emergency messages. There is almost no protection. Stay tuned for part 3 of this article where I would discuss options of adding a security layer to Admin IVR.

 

2021-12-06

Emergency Messages in Amazon Connect (part 1)

In this article, I would like to demonstrate how to add Emergency Messages in Amazon Connect.

Let's say you have an IVR and would like to be able to enable/disable certain messages or certain treatment without changing the whole IVR.

Usually, this is required in case of emergency situations or under some special circumstances.
Emergency Messages can also be called Special Messages.   

I will split this article into 3 parts:
  • Part 1 - how to add emergency messages to IVR menu
  • Part 2 - how to enable/disable emergency messages using Admin IVR
  • Part 3 - adding security to Admin IVR

Also very recently Amazon added new functionality to Amazon Connect - now you can create reusable call flows that are called Modules. In my example below I will use modules because it allows me to reuse the same module multiple times, makes my call flow much cleaner, and is easier to read.

You can learn more about modules in the official Amazon Connect documentation

Another thing that I would like to point out - in my example I use text to speech for emergency messages.
This seems to be straightforward, but If your emergency message is pre-recorded prompt you can still easily do it, just by adding prompt name as one of the attributes in DynamoDB table (step 1) and some extra logic in the module (step 3).

Step 1.

First, we need to create DynamoDB table EmergencyMessages that will be used to store Emergency Messages configuration and would allow to control what should happen after we played Emergency Message.

Here is a list of attributes:

  • id       - unique id of emergency messages. In my case, I use 4-digit long numbers
  • Enabled -  true / false   - status of Emergency Message
  • Description - description field for each emergency message
  • Text -  Actual text of an emergency message that will be played to the client
  • Action - what to do with the call after we played Emergency Message (see table below)
  • ActionTarget - additional property of action (see table below)

Possible values for Action and corresponding ActionTarget:
Action ActionTarget Comment
<EMPTY> <EMPTY> Do nothing. Just play Emergency Message and continue IVR flow as usual
DISCONNECT <EMPTY> Disconnect the call after the message
CALLBACK <QUEUE name> After the message create callback request for <QUEUE name>
TRANSFER_NUMBER <phone number> After the message transfer call to <phone number>
TRANSFER_QUEUE <QUEUE name> After the message transfer call to <Queue name>


Step 2.

Next step - I created Lambda function CheckEmergencyMessage using Python 3.9 that checks the status of Emergency Message and returns all attributes.

Input:
  • MessageID - id of the message
Output:
  • Enabled
  • Text
  • Action
  • ActionTarget


Source code of my lambda function you can see on my GitHub:


Step 3.

Now we will create a module CheckEmergencyMessage. As I previously mentioned modules are the new way to create reusable call flows.

What it does
  1. Invokes Lambda function CheckEmergencyMessage
  2. Checks if an emergency message is Enabled. 
    1. If it is not enabled - exits module
    2. If it is Enabled - plays text using text-to-speech
      • After that uses values of Action and ActionTarget to decide what to do with the call


You can download the source code of this module from my Github.

Step 4.

The last step is to create a demo flow that actually uses Emergency Messages.

What it does:

1. First I play a welcome message, something like "Welcome to customer support"

2. I assign the value of emergency message to attribute MessageID using Set Contact Attributes block

In this example MessageID = 2001

3. After that I invoke module CheckEmergencyMessage that actually checks if this emergency message is Enabled and plays it back to the customer and performs the required Action.


You can download the source code of this module from my GitHub:

https://github.com/contactcenterdude/amazon-connect/blob/main/EmergencyMessages/EmergencyMessagesDemo_flow.json


******

I would like to add that by adding the ability to create modules  Amazon Connect made it much easier to develop solutions like this one. Before that, I would have to add a whole bunch of blocks right directly in the main IVR flow. Now I can just 2 blocks at any place of my IVR to add additional Emergency Messages.

2021-11-20

Post Call Surveys in Amazon Connect

 One of the features of Contact centers is the ability to offer a client Post Call Survey.

In your Post Call Survey, you can ask the client to rate the quality of service or any other related questions.

It can be done in multiple ways - by sending client email form right after the call, by sending an SMS, or by asking the client to stay on the line after the agent disconnects and answer questions in the IVR. In this article, I would like to demonstrate how to build IVR Post Call Survey that is automatically triggered by the system once the agent disconnects from the call.

Step 1.

Create DynamoDB table that we will use to save results of Post Call Survey

Table name - PostCallSurveys

Columns:

  • ContactId  - unique ID of the call
  • answer  -  client's answer to post call survey
  • datetime - timestamp
  • phoneNumber - caller number (CLID) of the client


Step 2.

Now we will create Lambda function using Python 3.9 that is called savePostCallSurvey.

What it does:

1) Takes following attributes from the call

  • ContactId
  • Caller Number (CLID)
  • Client's answer to Survey
2) Saves this information to DynamoDB table PostCallSurveys

Here is the full text of my Lambda function:

import boto3
from botocore.exceptions import ClientError
from datetime import datetime

def lambda_handler(event, context):


    print(event)
    dynamodb = boto3.resource('dynamodb')
    table = dynamodb.Table('PostCallSurveys')
    
    ContactId=event['Details']['ContactData']['ContactId']
    CLID=event['Details']['ContactData']['CustomerEndpoint']['Address']
    
    current_date =datetime.now()
    curren_date_string=current_date.strftime("%Y-%m-%d %H:%M:%S")
    
    answer=event['Details']['ContactData']['Attributes']['answer']
    
    try:
        response = table.put_item(
           Item={
                'ContactId':ContactId,
                'phoneNumber': CLID,
                'datetime': curren_date_string,
                'answer': answer
            }
        )
        
        return response

    
            
    except ClientError as e:
        print(e.response['Error']['Message'])
    

You can also download it from my GitHub:


Step 3.

Next,  we will create a call flow that will be used to offer the client Post call survey.

You can download it from my GitHub:



How it works:

1) First we will use Store Customer input block to play "Please rate the quality of our service from 1 to 5" and capture user input.


2) After that we will save result to user defined attributed called "answer".

3) Now we will invoke our lambda function savePostCallSurvey to save results to the database.

Step 4.

The last step will be -  activate our Post Call Survey flow so that it will be automatically offered to the client when the agent disconnects.

In order to do that in our main IVR flow, we need to add Set disconnect flow action that will be called before we transfer call to the queue. 

Set disconnect flow allows to specify a flow that will be executed when the agent disconnect from the call.

In the Set disconnect flow we will select our Post Call Survey flow that we previously created in Step 3.


You can download it from my GitHub:
https://github.com/contactcenterdude/amazon-connect/blob/main/PostCallSurveys/MainFlow_flow.json

BONUS:

As I mentioned at the very beginning of this article Post Call survey can be also offered by sending an email.
It can be achieved by creating another flow that sends an email to a client. The same way we triggered IVR Post Call Survey by using Set disconnect flow we can also trigger flow that sends email.

2021-09-24

How to initiate task from IVR in Amazon Connect

UPDATE from 2021/11/20:

Amazon Connect now allows creating tasks from Contact Flow using a new contact block.

It means that you do not need to use Lambda functions to do that.

The New Create task block is quite intuitive. Now you can also specify if you want to create a task right away or schedule task creation in the future. 

More documentation is available here:

https://docs.aws.amazon.com/connect/latest/adminguide/create-task-block.html

Lambda function that is mentioned below could be still useful if you want to trigger task creation, not from IVR. But for example from another Amazon AWS service.


*********************

Not long time ago Amazon introduced a new type of contacts available in Amazon Connect -  tasks.

In my article, I will show you an example of how to initiate a task from IVR.

How it could be useful?

For example, a client calls your IVR and requests a certain type of service that cannot be fully automated. In that case, you might profit from the ability to automatically create a task that will be then sent to an agent for processing.

Here is a sample scenario:

1) Client calls an IVR of  home internet provider company

2) IVR asks the client to enter the account number for identification

3) After that you ask the client what he wants to do with his current contract

  • option 1- upgrade
  • option 2 - renewal
  • option 3 - cancellation
4) For example client selects renewal 

5) Now we will initiate a task that will be sent to a queue that is responsible for contract renewals.

6) When an agent receives the task he would be able to see: account number, request type, and phone number of the person. 

Here is how it can be done in Amazon Connect:



Step 1.

The first step is to create a simple contact flow that will be used to send tasks to the required queue.


 What it does:
* Set working queue - to define Queue that will be used to receive tasks
* Transfer to queue - to send a task to the queue

Once you created the contact flow click on "Show additional flow information". You will see a long string of Contact Flow ARN. You need to copy the last 36 characters of it starting after contact-flow/. This is your ContactFlowId. You will need it in the next step.


Step 2.

I created Lambda function using Python 3.9 which is called initiateTask.

What it does:

1) Collects the following attributes from the call
* account number
* request type
* caller number
* InstanceARN - it is required to be able to get InstanceID, it is required to initiate task using Amazon Connect API

2) Using Amazon Connect API I initiate a task.

Important: you need to specify Contact Flow Id that will be used to send tasks to the queue.
This is Contact Flow that was created in the previous step.

3) You can also specify the URL that will be displayed in your task description.
It could be link to your CRM system or any other website.

Here is the full text of my Lambda function:

import json
import boto3


def lambda_handler(event, context):
    
    accountNumber=event['Details']['ContactData']['Attributes']['accountNumber']
    requestType=event['Details']['ContactData']['Attributes']['requestType']
    CLID=event['Details']['ContactData']['CustomerEndpoint']['Address']
    InstanceARN=event['Details']['ContactData']['InstanceARN']
    InstanceId = InstanceARN[-36:]

    client = boto3.client('connect')
    
    Name=requestType.upper()
    URL="https://www.your-internet-on-demand.com/?accountNumber="+accountNumber
    Description="Request type ="+requestType+". AccountNumber="+ accountNumber+". Caller number="+CLID
    
    
    response = client.start_task_contact(
        InstanceId=InstanceId,
        ContactFlowId='5b67729d-21e7-4d3c-8a28-c96f881aa1a1',
        Name=Name,
        References={
            'URL': {
                'Value': URL,
                'Type': 'URL'
            }
        },
        Description=Description
    )
    
    # TODO implement
    return {
        'statusCode': 200,
        'body': json.dumps('OK')
    }


Step 3.

Now I will create another Contact flow that initiates the task.





This is how it works

1) Client calls the contact center

2) In the IVR I play the following message 
"Hello. Welcome to Internet on Demand. 
Please enter your 5-digit account number."

3) Client enters an account number

4) I save this information as User Defined attribute accountNumber


5) Now I play another message to the client

"How can we help you?
To request an upgrade press 1. 
To request a renewal without upgrade press 2. 
To cancel account press 3"

6) Depending on what the client selects I save the choice in User-defined attribute requestType

Example: when the client selects option 1 - upgrade


7) After that I invoke my Lambda function

8) At the end I play the following message
"Thank you. Your request was sent for processing. You can expect results in 24 hours."



Step 4.

Here is what the agent will see when the task arrives