skip to Main Content

I am currently trying out Amazon Connect and want to setup a Lambda function to send email notification when a call is disconnected because it was unattended by an agent.

Also in the contact flow where do I invoke the Lambda function?

I currently have this python Lambda function:

import json
import boto3

def lambda_handler(event, context):
    # Extract the necessary information from the event payload
    contact_id = event['Details']['ContactData']['ContactId']
    disconnect_reason = event['Details']['ContactData']['DisconnectReasons'][0]

    # Check if the call was disconnected due to being unattended
    if disconnect_reason == 'CONTACT_FLOW_DISCONNECTED':
        disconnect_cause = event['Details']['ContactData']['Attributes']['DisconnectCause']
        if disconnect_cause == 'unattended':
            # Construct the email message
            subject = f"Missed call from contact ID {contact_id}"
            body = f"The call from contact ID {contact_id} was disconnected and unattended."
            sender = '[email protected]'
            recipient = '[email protected]'

            # Send the email using Amazon SES
            client = boto3.client('ses')
            response = client.send_email(
                Destination={
                    'ToAddresses': [
                        recipient,
                    ],
                },
                Message={
                    'Body': {
                        'Text': {
                            'Charset': 'UTF-8',
                            'Data': body,
                        },
                    },
                    'Subject': {
                        'Charset': 'UTF-8',
                        'Data': subject,
                    },
                },
                Source=sender
            )

            # Log the response from Amazon SES
            print(response)

Not sure if it’s correct.

Thank you.

2

Answers


  1. There is a disconnect-flow, where you can invoke this function:
    https://docs.aws.amazon.com/connect/latest/adminguide/set-disconnect-flow.html

    However, in my opinion best way to invoke that Lambda function would be EventBridge:
    https://docs.aws.amazon.com/connect/latest/adminguide/contact-events.html

    You can create a rule in EventBridge and then set it as a trigger in your Lambda function.

    Login or Signup to reply.
  2. You’ll need to define a rule on EventBridge and capture disconnected calls with AgentConnectionAttempts > 0. I’m not sure if the code snippet will work; specifically this bit – ‘disconnect_cause == ‘unattended’’

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search