Amazon Connect is a cloud contact center that can be up and running in minutes, on both telephone and chat channels. It has a pay-as-you-go pricing model that many businesses are starting to find attractive.

With Amazon Connect being so easy to access, all of a sudden, the power of Conversational AI can be readily employed in contact centers of all shapes and sizes.

Table of Contents


The following graph shows the high-level architecture:


From left to right, the user calls a number (DID) accociated with the Amazon Connect instance, first. This called phone number uses a specifc Contact Flow to handle the response. It uses an AWS Lambda Function to fullfill the request. In order to process the message properly, Amazon Lex transforms the incoming speech to text (TTS). Afterward, the Lambda Function calls an Endpoint inside of Cognigy.AI where the virtual agent recognizes the intent and returns a fitting response based on the conversational Flow. This response gets sent back to Amazon Lex and transformed from text to speech (STT) where a configured Ouput Voice reads out loud the text to the calling user. This process gets repeated as long as the call wasn't hung up or forwarded to a human agent.

Natural Language Understanding (NLU)

In this setup, Amazon Lex is only used for handling Text-To-Speech (TTS) and Speech-To-Text (STT) so that the entire understanding and recognization of intents is handled within the Cognigy.AI Virtual Agent. With this configuration in place, the Conversation Designer doesn't have to maintain resources twice and can benefit from the centralized orchestration offered by Cognigy.AI.

Cognigy.AI: Set up the Virtual Agent

The first and easiest thing to do, is to set up the virtual agent for this connection. In this case, a REST Endpoint is used for sending and receiving messages. Please follow these steps:

  1. Login to Cognigy.AI and navigate to the virtual agent
  2. In the left side menu, navigate to Deploy -> Endpoints
  3. Click on + New Endpoint
  4. Call the Endpoint "Amazon Connect" or something similar
  5. Select a Flow that should handle the incoming message
  6. Select REST as Endpoint type
  7. Click SAVE

Now, one gets forwarded to the details page of the newly created Endpoint. The Endpoint URL will be used later in the AWS Lambda Function:




Nothing more is required inside of Cognigy.AI. 

AWS: Create the Lambda Function

The next step is to create the Lambda Function inside of Amazon Web Services (AWS) that fullfills the incoming and outgoing requests. In order to set up the general function, please follow the official documentation provided by Amazon: 

As soon as the Function is created, the following code can be inserted into the the intended field:

const COGNIGY_ENDPOINT_PATH = "/your-url-token";

exports.handler = async (event, context, callback) => {

try {

// Call was initialized by Amazon Lex
if (event.hasOwnProperty("Details")) {

let postObject = {
userId: event['Details']['ContactData']['CustomerEndpoint']['Address'],
sessionId: event['Details']['ContactData']['ContactId'],
text: event['Details']['Parameters']['text'],
data: {}

var resultMap = await sendMessageToCognigy(postObject);
resultMap['data']['connect_action'] = 'NONE'
var resultMapObj = { text: resultMap['text'], action: resultMap['data']['connect_action'] }

callback(null, resultMapObj);

} else {

//From Connect via Lex
let postObject = {
userId: event['sessionAttributes']['CustomerNumber'],
sessionId: event['sessionAttributes']['ContactId'],
text: event['inputTranscript'],
data: {}

var defaultSessionAtrributes = {
"action": "NONE",
"action_data": ""

var resultMap = await sendMessageToCognigy(postObject);

if (resultMap['data'] && resultMap['data']['connect_action']) {
defaultSessionAtrributes['action'] = resultMap['data']['connect_action']

if (resultMap['data'] && resultMap['data']['connect_action_data']) {
defaultSessionAtrributes['action_data'] = resultMap['data']['connect_action_data']

var resultMapObj = {
sessionAttributes: {
action: defaultSessionAtrributes.action,
action_data: defaultSessionAtrributes.action_data
dialogAction: {
type: "Close",
fulfillmentState: "Fulfilled",
message: {
contentType: "PlainText",
content: resultMap['text']

callback(null, resultMapObj);
} catch (e) {
return e;

const https = require('https');

async function sendMessageToCognigy(postObject) {

return new Promise((resolve, reject) => {
const postData = JSON.stringify(postObject);
const options = {
method: 'POST',
headers: {
'Content-Type': 'application/json'

const request = https.request(options, handleResponse);

request.on('error', (error) => {


function handleResponse(response) {
let data = '';

response.on('data', (d) => {
data += d.toString();

response.on('end', () => {
// Resolve with javascript object of JSON response:


The only required configuration to take is to insert the COGNIGY_ENDPOINT_HOSTNAME and COGNIGY_ENDPOINT_PATH. Both values can be extracted from the previously created Cognigy.AI Endpoint URL:
Path: /fdbaaacab8c0446e64d499d78d9985834f4fde15ce120356252fc5e10174c030
After pasting the code to the Lambda Function and inserting the Cognigy.AI related values, please Save and Deploy it. Later in this tutorial, the Lambda Function will be selected in the Contact Flows of Amazon Connect.


AWS: Create a Lex Instance

Next, the Amazon Lex instance must be created and configured to handle STT and TTS. Please read the official documentation for general information about Lex:


This Help Center article uses Amazon Lex Version 1.

Create a custom bot

Please follow these steps in order to create a function Lex instance for this connection:

  1. Inside of AWS, navigate to "Amazon Lex" and select the V1 Console
  2. In the left side menu, select Bots and click on Create

  3. Select Custom bot as type and fill in the required fields such as shown in the figure below:


  4. Click on Create

Create fallback and initiation intent

There are two intents needed to configure the Lex bot well. The first one is the built-in fallback intent that is triggered if Lex didn't understand the user's input. In this case, the previously created Lambda Function should be executed to let Cognigy.AI handle the undertanding (NLU). The second intent is a required dummy intent to be able to build and publish the Lex bot.

Please follow the below steps inside of Amazon Lex:

  1. Click on Create
  2. Click on Search existing intents
  3. Search for "AMAZON.FallbackIntent"
  4. Select it and call it "AmazonLexFallbackIntent" or something similar
  5. Inside of the Intent Details view, the Fullfillment must be defined. Please select the previously created AWS Lambda Function and its alias:

  6. Scoll down and click Save Intent
  7. Navigate back to the list of Intents and click on the + to create another one. It's required to create another intent containg sample utterances.
  8. Inside of the opened Pop-Up, cick on Create intent
  9. Call it "Initiation" or something similar
  10. In the Details view, add a sample utterance that a user probably won't say. Something like "GET_STARTED":


  11. Scroll down and click on Save Intent
  12. The last thing to do is to Build and Publish the Lex bot in order to make it visible in Amazon Connect later. Therefore, please click Build and then Publish on the top right of the screen:



Amazon Connect - Admin: Configure Contact Flows

Before the actual Contact Center can be configured using the Access URL, the Admin page of the Amazon Connect instance must be opened to configure which Lex Bot and Lambda Function should be available in the Contact Flow later. 

  1. In AWS, search for "Amazon Connect" and select it
  2. Click on the Instance alias to enter the admin view:


  3. Then, in the left side menu, click on Contact flows and select the previously created Lex bot and Lambda Function:


  4. Done

Amazon Connect: Create the Contact Flow

The last AWS recource that must be configured is Amazon Connect; the actual Contact Center that should be automated.

If there is no Amazon Connect instance given already, please follow the official documentation to create a new one: 

Otherwise, please follow the below steps in the existing Amazon Connect instance:

  1. In the left side menu, please navigate to Contact Flows:


  2. On the top right of the screen, please click on Create contact flow:


  3. Now, please take a look at the top right of the screen again and click on the "Arrow Down" button
  4. Select Import flow
  5. Please upload the file called "Cognigy" that is attached to this Help Center Article. Afterward, one should see something similar to:


  6. Click on Save

Since the uploaded Contact Flow is an example, there are two nodes in it that must be updated:

  1. Search for the Invoke AWS Lambda Function node


  2. Click on it to edit the configuration and select the previously created Lambda Function:


  3.  Click Save
  4. Now, search for the Get customer input node


  5. Click on it to edit the configuration and configure it such as shown on the screenshots below:


  6. Click Save

Amazon Connect: Assign the Contact Flow to a phone number

In order to use the new Contact Flow, it must be accociated with an existing phone number in the Conect instance. Accordingly, the next step is to navigate to the Phone Numbers overview:


Whether claim a new phone number or select an existing one. Afterward, please search for the Contact Flow/IVR configuration and select the new Contact Flow:




(Optional) Download the Amazon Connect Extension

In order to hang up or transfer the call from a user in Amazon Connect, an Extension can be used that sens specific metadata that is handled by the Contact Flow that will be used in this tutorial. In this case, a Flow could look as the following:




In order to add it to the virtual agent and the corresponding Flow Chart, please download this Extension in the Extension Marketplace oder click here to download the file. If the file was downloaded, one has to upload the Extension in the Manage -> Extensions view of the Cognigy.AI virtual agent.


Test the connection

The configuration is ready to be tested. In order to do so, please call the phone number that was configured in the step before. As soon as the call starts, the first message from the Cognigy.AI Flow will be read out loud.





Article is closed for comments.

Was this article helpful?
0 out of 0 found this helpful