Created
October 18, 2019 20:42
-
-
Save chrisckchang/200bd3b55c41d5d013f32960b43faac0 to your computer and use it in GitHub Desktop.
Amazon Connect example: Direct inbound DID dial to agent
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import boto3 | |
def lambda_handler(event, context): | |
dynamodb = boto3.resource('dynamodb') | |
table = dynamodb.Table('agentNumbersDb') | |
print(event) | |
## Find which number was dialed by customer. | |
## You may need to do some string manipulation to remove the "+" in the phone number. | |
dialedNumber = event['Details']['SystemEndpoint']['Address'] | |
print(dialedNumber) | |
response = table.get_item( | |
Key={ | |
'phoneNumber': int(dialedNumber) | |
} | |
) | |
print("Response is:") | |
print(response) | |
## Below code assumes DynamoDB item has phoneNumber + agentName fields | |
## If the phone number matches an agent, return the agent's name | |
## If the phone number doesn't match an agent, route to generic 'Support' queue | |
if 'Item' in response: | |
agentName = response['Item']['agentName'] | |
return { | |
'QueueName': agentName | |
} | |
else: | |
return { | |
'QueueName': "Support" | |
} | |
''' | |
example Connect -> Lambda event object | |
{ | |
'Details': { | |
'ContactData': { | |
'Channel': 'VOICE', | |
'ContactId': '6b47c081-1841-460d-86a1-5d810246b93e', | |
'CustomerEndpoint': { | |
'Address': '+14152339559', | |
'Type': 'TELEPHONE_NUMBER' | |
}, | |
'InitialContactId': '6b47c081-1841-460d-86a1-5d810246b93e', | |
'InitiationMethod': 'INBOUND', | |
'InstanceARN': 'CONNECT_ARN', | |
'MediaStreams': { | |
'Customer': { | |
'Audio': None | |
} | |
}, | |
'PreviousContactId': '6b47c081-1841-460d-86a1-5d810246b93e', | |
'Queue': None, | |
'SystemEndpoint': { | |
'Address': '+12066863680', | |
'Type': 'TELEPHONE_NUMBER' | |
} | |
}, | |
'Parameters': {}}, | |
'Name': 'ContactFlowEvent' | |
} | |
''' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment