Create an Inbound Contact Flow
The inbound contact flow is used to define the steps involved in setting up and executing conversation flows for the incoming calls. Though Amazon provides default flows, you can create a new flow or use contact flows that are already defined for U-Self Serve.
Note
Ensure the necessary Lambda functions are created before creating a bot. For more information, refer Create Lambda Function.
To Create Inbound Contact Flow
Log in to Amazon Connect using your credentials, all available instances are displayed.
Select the instance you wish to work on, the Account overview page of the instance is displayed.
Select Flows from the left menu.
Go to Amazon Lex section, click Return to the V1 Console and Create bot.
Click Custom Bot to create a mock bot. Example: RoadTrip.
To create a mock Intent, go to Editor tab and click + button to add Intents. Example: Book a car.
Select the Intent and enter a Sample Utterance. Example: I would like to travel with my pet.
Note
As it is a mock bot, a single Intent and a Sample utterance is sufficient.
In Lambda initiation and Validation section:
Check Initiation and validation code hook box.
From the Lambda function dropdown, select the lambda function that is used to initiate the U-Self Serve session. Example: invokeak.
To learn about lambda function, refer Create Lambda Function section.
To create a Fallback Intent, repeat step 6 and select Search Existing Intents.
From the Search Existing Intents dialog, select Amazon Fallbackintent which is listed under Built-in intents.
In the Fulfillment section, select AWS Lambda function and add Lambda function from the drop down. Example: invokeak.
Note
Use the same lambda function for the mock Intent and Amazon Fallbackintent.
Click Error Handling from the left menu and uncheck Clarification Prompts box. This ensures that the Clarification Prompts becomes inactive and the Amazon Fallbackintent is triggered.
Once the mock Intent and Amazon Fallbackintent are created, click Build and Publish the Bot.
Note
When the Lambda function (invokeak) is invoked in mock Intent and Amazon Fallbackintent, the flow will be routed to U-Self Serve.
Go to Amazon Connect console, Click Flows from the menu. In the Amazon Lex bot section, the bot you created is displayed.
Enable Contact flow logs to store your logs.
Click Save.
Go to Account overview, click the Access URL. Refer step 2.
Enter the Username and Password. The Amazon Connect Dashboard is displayed.
In Amazon Connect Dashboard, click Routing icon from the left pane and select Contact flows.
In Contact flows, you can view the pre-defined contact flows.
To create a new contact flow for U-Self Serve, click Create contact flow.
Enter a Name and Description for the flow.
Drag and drop contract blocks into the canvas and add connections between elements.
Double-click the title of the block to open the Configuration pane.
Configure settings for block and click Save.
In the canvas, go to the first block and select circle for the action to perform.
Using arrows, connect to the subsequent actions to be performed in case of success and failure.
Click Save to save a draft of the flow.
Click Publish to activate the flow.
Create Lambda Function
In Lambda console, click Add Lambda Function to add the Lambda function(s) that are required in the contact flow.
The Lambda Function code to initiate, converse and terminate a session in U-Self Serve is given below:
const request = require('request'); const https = require('http') exports.handler = async function(event,context) { console.log('event',event["Details"]["ContactData"]["Attributes"]); console.log(event); console.log('context',context); var vcmid = event["Details"]["ContactData"]["Attributes"]["vcmid"]; var pwd = event["Details"]["ContactData"]["Attributes"]["password"]; var lang = event["Details"]["ContactData"]["Attributes"]["language"]; var customerno = event["Details"]["ContactData"]["Attributes"]["customerno"]; var welcome = event["Details"]["ContactData"]["Attributes"]["welcomemessage"]; var host = event["Details"]["ContactData"]["Attributes"]["host"]; var metadata = {'mobile':customerno} console.log('host',host); console.log('welcome',welcome); var data = {}; const promise = new Promise(function(resolve, reject) { var options = { 'method': 'POST', 'url': host+'/V1/AC/initsession?sessionId='+event.Details.ContactData.ContactId+'&password='+pwd+'&vcmId='+vcmid+'&lang='+lang+'&welcomeIntent='+welcome, 'headers': { } }; console.log(host+'/V1/AC/initsession?sessionId='+event.Details.ContactData.ContactId+'&password='+pwd+'&vcmId='+vcmid+'&lang='+lang+'&welcomeIntent='+welcome); // ,'body':{'metaData':{'mobile':metadata}} request(options, function (error, response) { if (error) { console.log(error.errno) var res = {"source":event["Details"]["ContactData"]["Attributes"]["Servicedown"]} console.log(res); reject(res); } var ds = JSON.parse(response.body); console.log(ds.status); if(ds.status== 500){ var res = {"source":event["Details"]["ContactData"]["Attributes"]["Servicedown"],"service":"Down"}; resolve(res); } else{ console.log('data',response.body); var data = JSON.parse(response.body); data.service = "Up"; resolve(data); } // return response.body }); }) // console.log(promise); return promise; }
const request = require('request'); const https = require('http') exports.handler = async function(event,context) { console.log('event',event["Details"]["ContactData"]["Attributes"]); console.log(event); console.log('context',context); var vcmid = event["Details"]["ContactData"]["Attributes"]["vcmid"]; var pwd = event["Details"]["ContactData"]["Attributes"]["password"]; var lang = event["Details"]["ContactData"]["Attributes"]["language"]; var customerno = event["Details"]["ContactData"]["Attributes"]["customerno"]; var welcome = event["Details"]["ContactData"]["Attributes"]["welcomemessage"]; var host = event["Details"]["ContactData"]["Attributes"]["host"]; var metadata = {'mobile':customerno} console.log('host',host); console.log('welcome',welcome); var data = {}; const promise = new Promise(function(resolve, reject) { var options = { 'method': 'POST', 'url': host+'/V1/AC/initsession?sessionId='+event.Details.ContactData.ContactId+'&password='+pwd+'&vcmId='+vcmid+'&lang='+lang+'&welcomeIntent='+welcome, 'headers': { } }; console.log(host+'/V1/AC/initsession?sessionId='+event.Details.ContactData.ContactId+'&password='+pwd+'&vcmId='+vcmid+'&lang='+lang+'&welcomeIntent='+welcome); // ,'body':{'metaData':{'mobile':metadata}} request(options, function (error, response) { if (error) { console.log(error.errno) var res = {"source":event["Details"]["ContactData"]["Attributes"]["Servicedown"]} console.log(res); reject(res); } var ds = JSON.parse(response.body); console.log(ds.status); if(ds.status== 500){ var res = {"source":event["Details"]["ContactData"]["Attributes"]["Servicedown"],"service":"Down"}; resolve(res); }else{ console.log('data',response.body); var data = JSON.parse(response.body); data.service = "Up"; resolve(data); } // return response.body }); }) // console.log(promise); return promise; }
'use strict'; const request = require('request'); const https = require('http') exports.handler = async function(event,context) { var host = event["Details"]["ContactData"]["Attributes"]["host"]; console.log('event',event["Details"]["ContactData"]["Attributes"]["customerno"]); console.log(event); console.log('context',context); var data = {}; const promise = new Promise(function(resolve, reject) { v var options = { 'method': 'POST', 'url': host+'/V1/endsession?sessionId='+event.Details.ContactData.ContactId, 'headers': { } }; request(options, function (error, response) { if (error) throw new Error(error); console.log('data',response.body); data = response.body; resolve(JSON.parse(response.body)); // return response.body }); }) // console.log(promise); return promise; }
After adding Lambda functions, in Lambda console you can view the list of Lambda functions which can be added to the bot.
In Lambda console, go to Functions and select your lambda function.
In Function overview, select Template tab and verify whether the Timeout configured in the Instance is as per the organization's requirement.
If you wish to change the Timeout, select Diagram tab and click Configuration and select Edit.
In Timeout, set a value from 1 second to 15 seconds and click Save.